From 78abed9f25951b72fc69246c0f2adef69ad64cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 8 Jan 2024 14:28:38 +0100 Subject: [PATCH] Allow selecting blanket agreement line without supplier/customer product When the order line as a supplier/customer product, we should allow to select blanket agreement line with the same product or without any product. Because the supplier/customer product may be added after the blanket agreement is running. Closes #12909 --- modules/purchase_blanket_agreement/purchase.py | 18 +++++++++++++----- modules/sale_product_customer/sale.py | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/modules/purchase_blanket_agreement/purchase.py b/modules/purchase_blanket_agreement/purchase.py index 6a91d392f8..f61013e8fc 100644 --- a/modules/purchase_blanket_agreement/purchase.py +++ b/modules/purchase_blanket_agreement/purchase.py @@ -767,8 +767,11 @@ class Line(metaclass=PoolMeta): return [ ('product', '=', Eval('product', -1)), If(Eval('product_supplier'), - ('product_supplier', '=', Eval('product_supplier')), - ()), + ['OR', + ('product_supplier', '=', Eval('product_supplier')), + ('product_supplier', '=', None), + ], + []), ] @fields.depends( @@ -820,11 +823,16 @@ class Line(metaclass=PoolMeta): self.blanket_agreement_line = None @fields.depends( - 'blanket_agreement_line', 'product', - '_parent_blanket_agreement_line.product') + 'blanket_agreement_line', 'product', 'product_supplier', + '_parent_blanket_agreement_line.product', + '_parent_blanket_agreement_line.product_supplier') def is_valid_product_for_blanket_agreement(self): if self.blanket_agreement_line: - return self.product == self.blanket_agreement_line.product + return (self.product == self.blanket_agreement_line.product + and ( + (self.product_supplier + == self.blanket_agreement_line.product_supplier) + or not self.product_supplier)) def quantity_for_blanket_agreement(self, line, round=True): pool = Pool() diff --git a/modules/sale_product_customer/sale.py b/modules/sale_product_customer/sale.py index 7ee1f7168f..7f37683c71 100644 --- a/modules/sale_product_customer/sale.py +++ b/modules/sale_product_customer/sale.py @@ -128,8 +128,11 @@ class LineBlanketAgreement(metaclass=PoolMeta): return [ super()._domain_blanket_agreemnt_line_product(), If(Eval('product_customer'), - ('product_customer', '=', Eval('product_customer')), - ()), + ['OR', + ('product_customer', '=', Eval('product_customer')), + ('product_customer', '=', None), + ], + []), ] @fields.depends( @@ -142,6 +145,15 @@ class LineBlanketAgreement(metaclass=PoolMeta): self.product_customer = line.product_customer super().on_change_blanket_agreement_line() + @fields.depends( + 'product_customer', '_parent_blanket_agreement_line.product_customer') + def is_valid_product_for_blanket_agreement(self): + return (super().is_valid_product_for_blanket_agreement() + and ( + (self.product_customer + == self.blanket_agreement_line.product_customer) + or not self.product_customer)) + class BlanketAgreementLine(metaclass=PoolMeta): __name__ = 'sale.blanket_agreement.line'