From 06c1657c97244d349d2b988f5e6954a7ae6949e9 Mon Sep 17 00:00:00 2001 From: yk2kus Date: Fri, 24 Aug 2018 16:33:55 +0000 Subject: [PATCH 1/2] improve wizard --- tko_product_update_qty/models/inventory.py | 2 +- .../views/inventory_view.xml | 23 +++++++++++++++++- .../wizard/stock_change_product_qty.py | 24 ++++++++++++------- .../wizard/stock_change_product_qty_view.xml | 2 ++ 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/tko_product_update_qty/models/inventory.py b/tko_product_update_qty/models/inventory.py index 0a4e878..d43d885 100644 --- a/tko_product_update_qty/models/inventory.py +++ b/tko_product_update_qty/models/inventory.py @@ -15,7 +15,7 @@ class StockInventoryLine(models.Model): reason = fields.Char(string='Reason', related='inventory_id.reason', store=True) user_id = fields.Many2one('res.users', 'User', readonly=True, related='inventory_id.user_id', default=lambda self: self.env.uid) - mode = fields.Selection([('p', ' + '), ('n', ' - ')], compute='get_mode', default='p', required=True, string='Mode') + mode = fields.Selection([('p', 'Input'), ('n', 'Output')], compute='get_mode', default='p', required=True, string='Mode') @api.one @api.depends('product_qty', 'theoretical_qty') diff --git a/tko_product_update_qty/views/inventory_view.xml b/tko_product_update_qty/views/inventory_view.xml index b9faec9..d1713c1 100644 --- a/tko_product_update_qty/views/inventory_view.xml +++ b/tko_product_update_qty/views/inventory_view.xml @@ -15,7 +15,7 @@ - + stock.inventory.form.inherit stock.inventory @@ -26,4 +26,25 @@ + + stock.inventory.tree.inherit + stock.move.line + + + + + + + + + stock.inventory.form.inherit + stock.move.line + + + + + + + + \ No newline at end of file diff --git a/tko_product_update_qty/wizard/stock_change_product_qty.py b/tko_product_update_qty/wizard/stock_change_product_qty.py index 3d88b45..dd72048 100644 --- a/tko_product_update_qty/wizard/stock_change_product_qty.py +++ b/tko_product_update_qty/wizard/stock_change_product_qty.py @@ -1,5 +1,6 @@ from odoo import api, models, fields, _ from odoo import tools +from odoo.exceptions import Warning as UserError class StockChangeProductQty(models.TransientModel): @@ -7,8 +8,9 @@ class StockChangeProductQty(models.TransientModel): old_quantity = fields.Float('Old Qty', readonly=True) update_quantity = fields.Float('Update Qty') - mode = fields.Selection([('p', ' + '), ('n', ' - ')], default='p', required=True, string='Mode') + mode = fields.Selection([('p', 'Input'), ('n', 'Output')], default='p', required=True, string='Mode') reason = fields.Text('Reason') + show_new_quantity = fields.Float('New Quantity on Hand', help='Duplicate field only to be able to make it readonly on view, onchange doesnt pass value of readonly field') # When a user updates stock qty on the product form, propose the # right location to update stock. @@ -27,22 +29,26 @@ def onchange_mode(self): if 'new_quantity' not in self._context.keys(): if self.mode == 'p': self.new_quantity = self.old_quantity + self.update_quantity + self.show_new_quantity = self.old_quantity + self.update_quantity else: self.new_quantity = self.old_quantity - self.update_quantity + self.show_new_quantity = self.old_quantity - self.update_quantity - @api.onchange('new_quantity') - def onchange_new_quantity(self): - if self.new_quantity >= self.old_quantity: - self.mode = 'p' - self.update_quantity = self.new_quantity - self.old_quantity - else: - self.mode = 'n' - self.update_quantity = self.new_quantity + self.old_quantity + # @api.onchange('new_quantity') + # def onchange_new_quantity(self): + # if self.new_quantity >= self.old_quantity: + # self.mode = 'p' + # self.update_quantity = self.new_quantity - self.old_quantity + # else: + # self.mode = 'n' + # self.update_quantity = self.new_quantity + self.old_quantity def change_product_qty(self): """ Changes the Product Quantity by making a Physical Inventory. """ Inventory = self.env['stock.inventory'] for wizard in self: + if wizard.new_quantity < 0: + raise UserError('Quantity can not be less than zero.') product = wizard.product_id.with_context(location=wizard.location_id.id, lot_id=wizard.lot_id.id) line_data = wizard._action_start_line() diff --git a/tko_product_update_qty/wizard/stock_change_product_qty_view.xml b/tko_product_update_qty/wizard/stock_change_product_qty_view.xml index e4b550a..873afad 100644 --- a/tko_product_update_qty/wizard/stock_change_product_qty_view.xml +++ b/tko_product_update_qty/wizard/stock_change_product_qty_view.xml @@ -11,8 +11,10 @@ stock.group_stock_manager + 1 + From 2f34dd052b563c15efbca035ba26e04bf6f22833 Mon Sep 17 00:00:00 2001 From: yk2kus Date: Thu, 30 Aug 2018 16:53:47 +0000 Subject: [PATCH 2/2] update translationos --- tko_product_update_qty/i18n/pt_BR.po | 37 +++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/tko_product_update_qty/i18n/pt_BR.po b/tko_product_update_qty/i18n/pt_BR.po index 44f4734..241e8e5 100644 --- a/tko_product_update_qty/i18n/pt_BR.po +++ b/tko_product_update_qty/i18n/pt_BR.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 11.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-07-31 18:30+0000\n" -"PO-Revision-Date: 2018-07-31 18:30+0000\n" +"POT-Creation-Date: 2018-08-30 16:10+0000\n" +"PO-Revision-Date: 2018-08-30 16:10+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -21,11 +21,22 @@ msgid "Change Product Quantity" msgstr "Alterar Quantidade do Produto" #. module: tko_product_update_qty -#: code:addons/tko_product_update_qty/wizard/stock_change_product_qty.py:58 +#: model:ir.model.fields,help:tko_product_update_qty.field_stock_change_product_qty_show_new_quantity +msgid "Duplicate field only to be able to make it readonly on view, onchange doesnt pass value of readonly field" +msgstr "Duplicate field only to be able to make it readonly on view, onchange doesnt pass value of readonly field" + +#. module: tko_product_update_qty +#: code:addons/tko_product_update_qty/wizard/stock_change_product_qty.py:62 #, python-format msgid "INV: %s" msgstr "INV: %s" +#. module: tko_product_update_qty +#: selection:stock.change.product.qty,mode:0 +#: selection:stock.inventory.line,mode:0 +msgid "Input" +msgstr "Input" + #. module: tko_product_update_qty #: model:ir.model,name:tko_product_update_qty.model_stock_inventory msgid "Inventory" @@ -40,27 +51,41 @@ msgstr "Linha do Inventário" #: model:ir.model.fields,field_description:tko_product_update_qty.field_stock_change_product_qty_mode #: model:ir.model.fields,field_description:tko_product_update_qty.field_stock_inventory_line_mode msgid "Mode" -msgstr "Mode" +msgstr "Modo" + +#. module: tko_product_update_qty +#: model:ir.model.fields,field_description:tko_product_update_qty.field_stock_change_product_qty_show_new_quantity +msgid "New Quantity on Hand" +msgstr "Nova Quantidade na Mão" #. module: tko_product_update_qty #: model:ir.model.fields,field_description:tko_product_update_qty.field_stock_change_product_qty_old_quantity msgid "Old Qty" -msgstr "Old Qty" +msgstr "Quantidade Antiga" + +#. module: tko_product_update_qty +#: selection:stock.change.product.qty,mode:0 +#: selection:stock.inventory.line,mode:0 +msgid "Output" +msgstr "Output" #. module: tko_product_update_qty #: model:ir.model.fields,field_description:tko_product_update_qty.field_stock_change_product_qty_reason #: model:ir.model.fields,field_description:tko_product_update_qty.field_stock_inventory_line_reason #: model:ir.model.fields,field_description:tko_product_update_qty.field_stock_inventory_reason +#: model:ir.ui.view,arch_db:tko_product_update_qty.view_inventory_form_inherit msgid "Reason" msgstr "Motivo da atualização" #. module: tko_product_update_qty #: model:ir.model.fields,field_description:tko_product_update_qty.field_stock_change_product_qty_update_quantity msgid "Update Qty" -msgstr "Update Qty" +msgstr "Atualizar Quantidade" #. module: tko_product_update_qty #: model:ir.model.fields,field_description:tko_product_update_qty.field_stock_inventory_line_user_id #: model:ir.model.fields,field_description:tko_product_update_qty.field_stock_inventory_user_id +#: model:ir.ui.view,arch_db:tko_product_update_qty.view_move_line_form_inherit +#: model:ir.ui.view,arch_db:tko_product_update_qty.view_move_line_tree_inherit msgid "User" msgstr "Usuário"