Provide digits from unit of measure

issue10677
review365801002
This commit is contained in:
Cédric Krier
2021-08-30 00:27:13 +02:00
parent 8a118d1fd1
commit a8a04caaea
8 changed files with 18 additions and 57 deletions
+2 -2
View File
@@ -475,7 +475,7 @@
<text:p text:style-name="P13"><text:placeholder text:placeholder-type="text">&lt;move.product.rec_name&gt;</text:placeholder></text:p>
</table:table-cell>
<table:table-cell table:style-name="Table1.B3" office:value-type="string">
<text:p text:style-name="P12"><text:placeholder text:placeholder-type="text">&lt;format_number(move.quantity, shipment.delivery_address.party.lang, digits=move.unit_digits)&gt;</text:placeholder><text:s/><text:placeholder text:placeholder-type="text">&lt;move.uom.symbol&gt;</text:placeholder></text:p>
<text:p text:style-name="P12"><text:placeholder text:placeholder-type="text">&lt;format_number(move.quantity, shipment.delivery_address.party.lang, digits=move.uom.digits)&gt;</text:placeholder><text:s/><text:placeholder text:placeholder-type="text">&lt;move.uom.symbol&gt;</text:placeholder></text:p>
</table:table-cell>
</table:table-row>
<table:table-row>
@@ -488,4 +488,4 @@
<text:p text:style-name="P9"><text:placeholder text:placeholder-type="text">&lt;/for&gt;</text:placeholder></text:p>
</office:text>
</office:body>
</office:document>
</office:document>
+2 -2
View File
@@ -506,7 +506,7 @@
<text:p text:style-name="Table_20_Contents"><text:placeholder text:placeholder-type="text">&lt;move.product.rec_name&gt;</text:placeholder></text:p>
</table:table-cell>
<table:table-cell table:style-name="Table1.D4" office:value-type="string">
<text:p text:style-name="P11"><text:placeholder text:placeholder-type="text">&lt;format_number(move.quantity, user.language, digits=move.unit_digits)&gt;</text:placeholder><text:s/><text:placeholder text:placeholder-type="text">&lt;move.uom.symbol&gt;</text:placeholder></text:p>
<text:p text:style-name="P11"><text:placeholder text:placeholder-type="text">&lt;format_number(move.quantity, user.language, digits=move.uom.digits)&gt;</text:placeholder><text:s/><text:placeholder text:placeholder-type="text">&lt;move.uom.symbol&gt;</text:placeholder></text:p>
</table:table-cell>
</table:table-row>
<table:table-row>
@@ -525,4 +525,4 @@
<text:p text:style-name="Text_20_body"><text:placeholder text:placeholder-type="text">&lt;/for&gt;</text:placeholder></text:p>
</office:text>
</office:body>
</office:document>
</office:document>
+6 -24
View File
@@ -328,18 +328,14 @@ class InventoryLine(ModelSQL, ModelView):
], states=_states, depends=_depends)
uom = fields.Function(fields.Many2One('product.uom', 'UOM',
help="The unit in which the quantity is specified."), 'get_uom')
unit_digits = fields.Function(fields.Integer('Unit Digits'),
'get_unit_digits')
expected_quantity = fields.Float('Expected Quantity', required=True,
digits=(16, Eval('unit_digits', 2)), readonly=True,
expected_quantity = fields.Float(
"Expected Quantity", digits='uom', required=True, readonly=True,
states={
'invisible': Eval('id', -1) < 0,
},
depends=['unit_digits'],
help="The quantity the system calculated should be in the location.")
quantity = fields.Float('Quantity',
digits=(16, Eval('unit_digits', 2)),
states=_states, depends=['unit_digits'] + _depends,
quantity = fields.Float(
"Quantity", digits='uom', states=_states, depends=_depends,
help="The actual quantity found in the location.")
moves = fields.One2Many('stock.move', 'origin', 'Moves', readonly=True)
inventory = fields.Many2One('stock.inventory', 'Inventory', required=True,
@@ -401,20 +397,14 @@ class InventoryLine(ModelSQL, ModelView):
# Migration from 4.6: drop required on quantity
table.not_null_action('quantity', action='remove')
@staticmethod
def default_unit_digits():
return 2
@staticmethod
def default_expected_quantity():
return 0.
@fields.depends('product')
def on_change_product(self):
self.unit_digits = 2
if self.product:
self.uom = self.product.default_uom
self.unit_digits = self.product.default_uom.digits
@fields.depends('inventory', '_parent_inventory.location')
def on_change_with_inventory_location(self, name=None):
@@ -457,9 +447,6 @@ class InventoryLine(ModelSQL, ModelView):
def get_uom(self, name):
return self.product.default_uom.id
def get_unit_digits(self, name):
return self.product.default_uom.digits
@property
def unique_key(self):
key = []
@@ -594,7 +581,6 @@ class Count(Wizard):
values['line'] = line.id
values['product'] = line.product.id
values['uom'] = line.uom.id
values['unit_digits'] = line.unit_digits
if line.uom.rounding == 1:
values['quantity'] = 1
return values
@@ -674,17 +660,13 @@ class CountQuantity(ModelView):
uom = fields.Many2One('product.uom', "UOM", readonly=True,
help="The unit in which the quantities are specified.")
total_quantity = fields.Float(
"Total Quantity", digits=(16, Eval('unit_digits', 2)),
readonly=True, depends=['unit_digits'],
"Total Quantity", digits='uom', readonly=True,
help="The total amount of the line counted so far.")
quantity = fields.Float(
"Quantity", digits=(16, Eval('unit_digits', 2)), required=True,
depends=['unit_digits'],
"Quantity", digits='uom', required=True,
help="The quantity to add to the existing count.")
unit_digits = fields.Integer("Unit Digits", readonly=True)
@fields.depends('quantity', 'line')
def on_change_quantity(self):
if self.line:
+3 -16
View File
@@ -192,11 +192,9 @@ class Move(Workflow, ModelSQL, ModelView):
],
depends=['state', 'unit_price', 'product_uom_category'],
help="The unit in which the quantity is specified.")
unit_digits = fields.Function(fields.Integer('Unit Digits'),
'on_change_with_unit_digits')
quantity = fields.Float("Quantity", required=True,
digits=(16, Eval('unit_digits', 2)), states=STATES,
depends=['state', 'unit_digits'],
quantity = fields.Float(
"Quantity", digits='uom', required=True,
states=STATES, depends=DEPENDS,
help="The amount of stock moved.")
internal_quantity = fields.Float('Internal Quantity', readonly=True,
required=True)
@@ -408,23 +406,12 @@ class Move(Workflow, ModelSQL, ModelView):
company = Company(company)
return company.currency.id
@staticmethod
def default_unit_digits():
return 2
@fields.depends('uom')
def on_change_with_unit_digits(self, name=None):
if self.uom:
return self.uom.digits
return 2
@fields.depends('product', 'uom')
def on_change_product(self):
if self.product:
if (not self.uom
or self.uom.category != self.product.default_uom.category):
self.uom = self.product.default_uom
self.unit_digits = self.product.default_uom.digits
@fields.depends('product')
def on_change_with_product_uom_category(self, name=None):
+2 -2
View File
@@ -468,7 +468,7 @@
<text:p text:style-name="Table_20_Contents"><text:placeholder text:placeholder-type="text">&lt;move.product.rec_name&gt;</text:placeholder></text:p>
</table:table-cell>
<table:table-cell table:style-name="Table1.D4" office:value-type="string">
<text:p text:style-name="P12"><text:placeholder text:placeholder-type="text">&lt;format_number(move.quantity, user.language, digits=move.unit_digits)&gt;</text:placeholder> <text:placeholder text:placeholder-type="text">&lt;move.uom.symbol&gt;</text:placeholder></text:p>
<text:p text:style-name="P12"><text:placeholder text:placeholder-type="text">&lt;format_number(move.quantity, user.language, digits=move.uom.digits)&gt;</text:placeholder> <text:placeholder text:placeholder-type="text">&lt;move.uom.symbol&gt;</text:placeholder></text:p>
</table:table-cell>
</table:table-row>
<table:table-row>
@@ -487,4 +487,4 @@
<text:p text:style-name="Text_20_body"><text:placeholder text:placeholder-type="text">&lt;/for&gt;</text:placeholder></text:p>
</office:text>
</office:body>
</office:document>
</office:document>
+1 -7
View File
@@ -344,11 +344,8 @@ class ProductMixin:
depends=['company'])
internal_quantity = fields.Float("Internal Quantity")
quantity = fields.Function(fields.Float(
"Quantity", digits=(16, Eval('unit_digits', 2)),
depends=['unit_digits']), 'get_quantity')
"Quantity", digits='unit'), 'get_quantity')
unit = fields.Function(fields.Many2One('product.uom', "Unit"), 'get_unit')
unit_digits = fields.Function(
fields.Integer("Unit Digits"), 'get_unit_digits')
@classmethod
def _columns(cls, tables, withs):
@@ -379,9 +376,6 @@ class ProductMixin:
def get_unit(self, name):
return self.product.default_uom.id
def get_unit_digits(self, name):
return self.product.default_uom.digits
class Product(ProductMixin, Abstract, ModelView):
"Stock Reporting Margin per Product"
+2 -2
View File
@@ -460,7 +460,7 @@
<text:p text:style-name="Table_20_Contents"><text:placeholder text:placeholder-type="text">&lt;move.product.rec_name&gt;</text:placeholder></text:p>
</table:table-cell>
<table:table-cell table:style-name="Table1.D4" office:value-type="string">
<text:p text:style-name="P11"><text:placeholder text:placeholder-type="text">&lt;format_number(move.quantity, user.language, digits=move.unit_digits)&gt;</text:placeholder> <text:placeholder text:placeholder-type="text">&lt;move.uom.symbol&gt;</text:placeholder></text:p>
<text:p text:style-name="P11"><text:placeholder text:placeholder-type="text">&lt;format_number(move.quantity, user.language, digits=move.uom.digits)&gt;</text:placeholder> <text:placeholder text:placeholder-type="text">&lt;move.uom.symbol&gt;</text:placeholder></text:p>
</table:table-cell>
</table:table-row>
<table:table-row>
@@ -479,4 +479,4 @@
<text:p text:style-name="Text_20_body"><text:placeholder text:placeholder-type="text">&lt;/for&gt;</text:placeholder></text:p>
</office:text>
</office:body>
</office:document>
</office:document>
-2
View File
@@ -33,6 +33,4 @@ this repository contains the full copyright notices and license terms. -->
<button name="draft" icon="tryton-clear"/>
<button name="do" icon="tryton-forward"/>
</group>
<field name="unit_price_required" invisible="1" colspan="4"/>
<field name="unit_digits" invisible="1" colspan="4"/>
</form>