Do not allow to add product or unit with amendment if there was no unit

Invoice lines may already exist with incompatible unit which will fail to
compute invoiced quantity.
This commit is contained in:
Cédric Krier
2024-10-27 19:43:15 +01:00
parent 0e0f5f0ec6
commit d7c8fae637
2 changed files with 10 additions and 14 deletions
+5 -7
View File
@@ -246,12 +246,12 @@ class AmendmentLine(ModelSQL, ModelView):
& ~(Eval('quantity', 0) < 0),
('purchasable', '=', True),
()),
If(Eval('product_uom_category'),
('default_uom_category', '=', Eval('product_uom_category')),
()),
('default_uom_category', '=', Eval('product_uom_category', -1)),
],
states={
'readonly': Eval('state') != 'draft',
'readonly': (
(Eval('state') != 'draft')
| ~Eval('product_uom_category', None)),
'invisible': Eval('action') != 'line',
})
product_supplier = fields.Many2One(
@@ -310,9 +310,7 @@ class AmendmentLine(ModelSQL, ModelView):
cls.__access__.add('amendment')
unit_categories = cls._unit_categories()
cls.unit.domain = [
If(Bool(Eval('product_uom_category')),
('category', 'in', [Eval(c) for c in unit_categories]),
('category', '!=', -1)),
('category', 'in', [Eval(c, -1) for c in unit_categories]),
]
@classmethod
+5 -7
View File
@@ -284,12 +284,12 @@ class AmendmentLine(ModelSQL, ModelView):
& ~(Eval('quantity', 0) < 0),
('salable', '=', True),
()),
If(Eval('product_uom_category'),
('default_uom_category', '=', Eval('product_uom_category')),
()),
('default_uom_category', '=', Eval('product_uom_category', -1)),
],
states={
'readonly': Eval('state') != 'draft',
'readonly': (
(Eval('state') != 'draft')
| ~Eval('product_uom_category', None)),
'invisible': Eval('action') != 'line',
})
quantity = fields.Float(
@@ -330,9 +330,7 @@ class AmendmentLine(ModelSQL, ModelView):
cls.__access__.add('amendment')
unit_categories = cls._unit_categories()
cls.unit.domain = [
If(Bool(Eval('product_uom_category')),
('category', 'in', [Eval(c) for c in unit_categories]),
('category', '!=', -1)),
('category', 'in', [Eval(c, -1) for c in unit_categories]),
]
@classmethod