Browse Source

[FIX] pos_weight: make the module working for product variants (#255)

pull/368/head
Sylvain LE GAL 7 years ago
parent
commit
dcf3f4f25b
  1. 4
      pos_to_weight_by_product_uom/models/__init__.py
  2. 19
      pos_to_weight_by_product_uom/models/product_product.py
  3. 16
      pos_to_weight_by_product_uom/models/product_template.py

4
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_template
from . import product_uom from . import product_uom
from . import product_uom_categ from . import product_uom_categ

19
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

16
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 <quentin.dupont@grap.coop>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import api, models from openerp import api, models
@ -12,7 +12,9 @@ class ProductTemplate(models.Model):
def onchange_uom(self, uom_id, uom_po_id): def onchange_uom(self, uom_id, uom_po_id):
res = super(ProductTemplate, self).onchange_uom(uom_id, uom_po_id) res = super(ProductTemplate, self).onchange_uom(uom_id, uom_po_id)
if uom_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 return res
Loading…
Cancel
Save