diff --git a/pos_to_weight_by_product_uom/models/__init__.py b/pos_to_weight_by_product_uom/models/__init__.py index a64cf628af..ca457dc39f 100644 --- a/pos_to_weight_by_product_uom/models/__init__.py +++ b/pos_to_weight_by_product_uom/models/__init__.py @@ -1,6 +1,6 @@ -# -*- coding: utf-8 -*- -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +# coding: utf-8 +from . import product_product from . import product_template from . import product_uom from . import product_uom_categ diff --git a/pos_to_weight_by_product_uom/models/product_product.py b/pos_to_weight_by_product_uom/models/product_product.py new file mode 100644 index 0000000000..f92f3e687c --- /dev/null +++ b/pos_to_weight_by_product_uom/models/product_product.py @@ -0,0 +1,19 @@ +# coding: utf-8 +# Copyright (C) 2018 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import api, models + + +class ProductProduct(models.Model): + _inherit = 'product.product' + + @api.multi + def onchange_uom(self, uom_id, uom_po_id): + res = super(ProductProduct, self).onchange_uom(uom_id, uom_po_id) + if uom_id: + res = res or {} + val = res.setdefault('value', {}) + val['to_weight'] = self.env['product.uom'].browse(uom_id).to_weigh + return res diff --git a/pos_to_weight_by_product_uom/models/product_template.py b/pos_to_weight_by_product_uom/models/product_template.py index 25cb4d4ede..cf992eb44b 100644 --- a/pos_to_weight_by_product_uom/models/product_template.py +++ b/pos_to_weight_by_product_uom/models/product_template.py @@ -1,7 +1,7 @@ -# -*- coding: utf-8 -*- -# Copyright 2017, Grap -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - +# coding: utf-8 +# Copyright (C) 2017 - Today: GRAP (http://www.grap.coop) +# @author: Quentin DUPONT +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import api, models @@ -12,7 +12,9 @@ class ProductTemplate(models.Model): def onchange_uom(self, uom_id, uom_po_id): res = super(ProductTemplate, self).onchange_uom(uom_id, uom_po_id) if uom_id: - if res.get('value', False): - res['value']['to_weight'] =\ - self.env['product.uom'].browse(uom_id).to_weigh + res = res and res or {} + if not res.get('value', False): + res['value'] = {} + res['value']['to_weight'] =\ + self.env['product.uom'].browse(uom_id).to_weigh return res