Replace uom domain by parent to product uom category (#5)

#163292
This commit is contained in:
Raimon Esteve 2023-11-10 07:13:48 +01:00
parent d08a80d270
commit 1257df9879
3 changed files with 20 additions and 28 deletions

View File

@ -170,9 +170,9 @@ msgctxt "field:product.cost.plan.product_line,uom:"
msgid "UoM" msgid "UoM"
msgstr "UdM" msgstr "UdM"
msgctxt "field:product.cost.plan.product_line,uom_category:" msgctxt "field:product.cost.plan.product_line,product_uom_category:"
msgid "UoM Category" msgid "Product UoM Category"
msgstr "Categoria d'UdM" msgstr "Categoria UdM del producte"
msgctxt "field:product.cost.plan.product_line,uom_digits:" msgctxt "field:product.cost.plan.product_line,uom_digits:"
msgid "UoM Digits" msgid "UoM Digits"

View File

@ -170,9 +170,9 @@ msgctxt "field:product.cost.plan.product_line,uom:"
msgid "UoM" msgid "UoM"
msgstr "UdM" msgstr "UdM"
msgctxt "field:product.cost.plan.product_line,uom_category:" msgctxt "field:product.cost.plan.product_line,product_uom_category:"
msgid "UoM Category" msgid "Product UoM Category"
msgstr "Categoría de UdM" msgstr "Categoría UdM del producto"
msgctxt "field:product.cost.plan.product_line,uom_digits:" msgctxt "field:product.cost.plan.product_line,uom_digits:"
msgid "UoM Digits" msgid "UoM Digits"

36
plan.py
View File

@ -490,19 +490,18 @@ class PlanProductLine(ModelSQL, ModelView, tree(separator='/')):
plan = fields.Many2One('product.cost.plan', 'Plan', ondelete='CASCADE') plan = fields.Many2One('product.cost.plan', 'Plan', ondelete='CASCADE')
product = fields.Many2One('product.product', 'Product', domain=[ product = fields.Many2One('product.product', 'Product', domain=[
('type', '!=', 'service'), ('type', '!=', 'service'),
If(Bool(Eval('children')), ])
('default_uom.category', '=', Eval('uom_category')),
()),
], depends=['children', 'uom_category'])
quantity = fields.Float('Quantity', required=True, quantity = fields.Float('Quantity', required=True,
digits=(16, Eval('uom_digits', 2)), depends=['uom_digits']) digits=(16, Eval('uom_digits', 2)), depends=['uom_digits'])
uom_category = fields.Function(fields.Many2One('product.uom.category', product_uom_category = fields.Function(
'UoM Category'), 'on_change_with_uom_category') fields.Many2One('product.uom.category', 'Product Uom Category'),
uom = fields.Many2One('product.uom', 'UoM', required=True, domain=[ 'on_change_with_product_uom_category')
If(Bool(Eval('children')) | Bool(Eval('product')), uom = fields.Many2One('product.uom', 'UoM', required=True,
('category', '=', Eval('uom_category')), domain=[
()), If(Bool(Eval('product_uom_category')),
], depends=['children', 'product', 'uom_category']) ('category', '=', Eval('product_uom_category')),
('category', '!=', -1)),
], depends=['product_uom_category'])
uom_digits = fields.Function(fields.Integer('UoM Digits'), uom_digits = fields.Function(fields.Integer('UoM Digits'),
'on_change_with_uom_digits') 'on_change_with_uom_digits')
party_stock = fields.Boolean('Party Stock', party_stock = fields.Boolean('Party Stock',
@ -553,17 +552,10 @@ class PlanProductLine(ModelSQL, ModelView, tree(separator='/')):
self.uom = None self.uom = None
self.product_cost_price = None self.product_cost_price = None
@fields.depends('children', 'product', 'plan', '_parent_plan.uom') @fields.depends('product')
def on_change_with_uom_category(self, name=None): def on_change_with_product_uom_category(self, name=None):
if self.children: if self.product:
uoms = set([child.uom.category for child in self.children return self.product.default_uom_category.id
if child.uom])
if len(uoms) == 1:
return list(uoms)[0].id
elif self.product:
return self.product.default_uom.category.id
elif self.plan and self.plan.uom:
return self.plan.uom.category.id
@fields.depends('uom') @fields.depends('uom')
def on_change_with_uom_digits(self, name=None): def on_change_with_uom_digits(self, name=None):