From 983a6282fd07e98d48d2bbab19a28c8ed31c09f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 17 Mar 2020 23:26:58 +0100 Subject: [PATCH] Enforce the same category of UoM between invoice lines and origin The origin lines compute the remaining quantity by converting the move quantity to the origin unit. So they must have the same category of UoM. issue9142 review285011002 --- invoice.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/invoice.py b/invoice.py index e5661a8d2d..f5bafac65d 100644 --- a/invoice.py +++ b/invoice.py @@ -105,6 +105,19 @@ class Invoice(metaclass=PoolMeta): class InvoiceLine(metaclass=PoolMeta): __name__ = 'account.invoice.line' + @fields.depends('origin') + def on_change_with_product_uom_category(self, name=None): + pool = Pool() + PurchaseLine = pool.get('purchase.line') + category = super().on_change_with_product_uom_category(name=name) + # Enforce the same unit category as they are used to compute the + # remaining quantity to invoice and the quantity to receive. + # Use getattr as reference field can have negative id + if (isinstance(self.origin, PurchaseLine) + and getattr(self.origin, 'unit', None)): + category = self.origin.unit.category.id + return category + @property def origin_name(self): pool = Pool()