changeset 2449cd9590d1 in modules/stock:default
details: https://hg.tryton.org/modules/stock?cmd=changeset;node=2449cd9590d1
description:
Add unit and digits to location quantities
issue9876
review333251002
diffstat:
location.py | 40 ++++++++++++++++++++++++++++++++++++----
view/location_quantity_form.xml | 4 ++--
view/location_quantity_tree.xml | 6 +++---
3 files changed, 41 insertions(+), 9 deletions(-)
diffs (91 lines):
diff -r 584ab4cbb6b0 -r 2449cd9590d1 location.py
--- a/location.py Fri Jan 08 22:57:47 2021 +0100
+++ b/location.py Sun Jan 17 00:41:23 2021 +0100
@@ -160,14 +160,25 @@
],
depends=['type'],
help="The warehouses that use the location for waste products.")
+
quantity = fields.Function(
- fields.Float('Quantity',
- help="The amount of stock in the location."),
+ fields.Float(
+ "Quantity", digits=(16, Eval('quantity_uom_digits', 2)),
+ depends=['quantity_uom_digits'],
+ help="The amount of stock in the location."),
'get_quantity', searcher='search_quantity')
forecast_quantity = fields.Function(
- fields.Float('Forecast Quantity',
- help="The amount of stock expected to be in the location."),
+ fields.Float(
+ "Forecast Quantity", digits=(16, Eval('quantity_uom_digits', 2)),
+ depends=['quantity_uom_digits'],
+ help="The amount of stock expected to be in the location."),
'get_quantity', searcher='search_quantity')
+ quantity_uom = fields.Function(fields.Many2One(
+ 'product.uom', "Quantity UOM"),
+ 'get_quantity_uom')
+ quantity_uom_digits = fields.Function(fields.Integer(
+ "Quantity UOM Digits"),
+ 'get_quantity_uom')
cost_value = fields.Function(fields.Numeric(
"Cost Value", digits=price_digits,
help="The value of the stock in the location."),
@@ -442,6 +453,27 @@
return [('id', 'in', ids)]
@classmethod
+ def get_quantity_uom(cls, locations, name):
+ pool = Pool()
+ Product = pool.get('product.product')
+ Template = pool.get('product.template')
+ context = Transaction().context
+ value = None
+ uom = None
+ if context.get('product') is not None:
+ product = Product(context['product'])
+ uom = product.default_uom
+ elif context.get('product_template') is not None:
+ template = Template(context['product_template'])
+ uom = template.default_uom
+ if uom:
+ if name == 'quantity_uom':
+ value = uom.id
+ elif name == 'quantity_uom_digits':
+ value = uom.digits
+ return {l.id: value for l in locations}
+
+ @classmethod
def get_cost_value(cls, locations, name):
pool = Pool()
Product = pool.get('product.product')
diff -r 584ab4cbb6b0 -r 2449cd9590d1 view/location_quantity_form.xml
--- a/view/location_quantity_form.xml Fri Jan 08 22:57:47 2021 +0100
+++ b/view/location_quantity_form.xml Sun Jan 17 00:41:23 2021 +0100
@@ -5,9 +5,9 @@
<label name="name"/>
<field name="name" colspan="5"/>
<label name="quantity"/>
- <field name="quantity"/>
+ <field name="quantity" symbol="quantity_uom"/>
<label name="forecast_quantity"/>
- <field name="forecast_quantity"/>
+ <field name="forecast_quantity" symbol="quantity_uom"/>
<label name="cost_value"/>
<field name="cost_value"/>
<field name="childs" colspan="6"
view_ids="stock.location_quantity_view_list,stock.location_quantity_view_form"/>
diff -r 584ab4cbb6b0 -r 2449cd9590d1 view/location_quantity_tree.xml
--- a/view/location_quantity_tree.xml Fri Jan 08 22:57:47 2021 +0100
+++ b/view/location_quantity_tree.xml Sun Jan 17 00:41:23 2021 +0100
@@ -2,8 +2,8 @@
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tree>
- <field name="name"/>
- <field name="quantity"/>
- <field name="forecast_quantity"/>
+ <field name="name" expand="1"/>
+ <field name="quantity" symbol="quantity_uom"/>
+ <field name="forecast_quantity" symbol="quantity_uom"/>
<field name="cost_value"/>
</tree>