Skip to content

Commit

Permalink
[FIX] pos_weight: make the module working for product variants (OCA#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Jan 12, 2024
1 parent b3dcb90 commit afb8128
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pos_to_weight_by_product_uom/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions pos_to_weight_by_product_uom/models/product_product.py
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 7 deletions pos_to_weight_by_product_uom/models/product_template.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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

0 comments on commit afb8128

Please sign in to comment.