Browse Source

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

pull/248/head
Sylvain LE GAL 7 years ago
committed by Pedro M. Baeza
parent
commit
d6bd7e7dd0
  1. 4
      pos_to_weight_by_product_uom/models/__init__.py
  2. 19
      pos_to_weight_by_product_uom/models/product_product.py
  3. 12
      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

12
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 = res and res or {}
if not res.get('value', False):
res['value'] = {}
res['value']['to_weight'] =\ res['value']['to_weight'] =\
self.env['product.uom'].browse(uom_id).to_weigh self.env['product.uom'].browse(uom_id).to_weigh
return res return res
Loading…
Cancel
Save