changeset 64f771e3f4c0 in modules/product_kit:default
details:
https://hg.tryton.org/modules/product_kit?cmd=changeset&node=64f771e3f4c0
description:
Convert quantity into parent uom
The component line is computed based on the parent quantity.
issue10325
review334231002
diffstat:
product.py | 13 ++++++++++++-
tests/scenario_product_kit.rst | 3 ++-
tests/scenario_product_kit_purchase.rst | 3 ++-
tests/scenario_product_kit_sale.rst | 3 ++-
4 files changed, 18 insertions(+), 4 deletions(-)
diffs (97 lines):
diff -r dec46e92224b -r 64f771e3f4c0 product.py
--- a/product.py Mon Apr 19 09:57:04 2021 +0200
+++ b/product.py Sun Apr 25 17:52:36 2021 +0200
@@ -116,6 +116,10 @@
def on_change_with_parent_type(self, name):
raise NotImplementedError
+ @property
+ def parent_uom(self):
+ raise NotImplementedError
+
@fields.depends('product', 'unit', 'quantity',
methods=['on_change_with_product_unit_category'])
def on_change_product(self):
@@ -145,7 +149,7 @@
line.quantity = self.quantity
else:
quantity = Uom.compute_qty(
- unit, quantity, self.product.default_uom, round=False)
+ unit, quantity, self.parent_uom, round=False)
line.quantity = self.unit.round(quantity * self.quantity)
return line
@@ -207,6 +211,13 @@
elif self.parent_template:
return self.parent_template.type
+ @property
+ def parent_uom(self):
+ if self.parent_product:
+ return self.parent_product.default_uom
+ elif self.parent_template:
+ return self.parent_template.default_uom
+
def get_rec_name(self, name):
return super().get_rec_name(name) + (
' @ %s' % (
diff -r dec46e92224b -r 64f771e3f4c0 tests/scenario_product_kit.rst
--- a/tests/scenario_product_kit.rst Mon Apr 19 09:57:04 2021 +0200
+++ b/tests/scenario_product_kit.rst Sun Apr 25 17:52:36 2021 +0200
@@ -21,6 +21,7 @@
>>> Uom = Model.get('product.uom')
>>> unit, = Uom.find([('name', '=', 'Unit')])
+ >>> meter, = Uom.find([('name', '=', "Meter")])
>>> ProductTemplate = Model.get('product.template')
>>> Product = Model.get('product.product')
@@ -35,7 +36,7 @@
>>> template = ProductTemplate()
>>> template.name = "Product 2"
- >>> template.default_uom = unit
+ >>> template.default_uom = meter
>>> template.type = 'goods'
>>> template.save()
>>> product2, = template.products
diff -r dec46e92224b -r 64f771e3f4c0 tests/scenario_product_kit_purchase.rst
--- a/tests/scenario_product_kit_purchase.rst Mon Apr 19 09:57:04 2021 +0200
+++ b/tests/scenario_product_kit_purchase.rst Sun Apr 25 17:52:36 2021 +0200
@@ -57,6 +57,7 @@
>>> ProductUom = Model.get('product.uom')
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
+ >>> meter, = ProductUom.find([('name', '=', "Meter")])
>>> ProductTemplate = Model.get('product.template')
>>> template = ProductTemplate()
@@ -73,7 +74,7 @@
>>> template = ProductTemplate()
>>> template.name = "Product 2"
- >>> template.default_uom = unit
+ >>> template.default_uom = meter
>>> template.type = 'goods'
>>> template.list_price = Decimal('20')
>>> template.account_category = account_category
diff -r dec46e92224b -r 64f771e3f4c0 tests/scenario_product_kit_sale.rst
--- a/tests/scenario_product_kit_sale.rst Mon Apr 19 09:57:04 2021 +0200
+++ b/tests/scenario_product_kit_sale.rst Sun Apr 25 17:52:36 2021 +0200
@@ -55,6 +55,7 @@
>>> ProductUom = Model.get('product.uom')
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
+ >>> meter, = ProductUom.find([('name', '=', "Meter")])
>>> ProductTemplate = Model.get('product.template')
>>> template = ProductTemplate()
@@ -69,7 +70,7 @@
>>> template = ProductTemplate()
>>> template.name = "Product 2"
- >>> template.default_uom = unit
+ >>> template.default_uom = meter
>>> template.type = 'goods'
>>> template.list_price = Decimal('20')
>>> template.account_category = account_category