From cfdf30e1135f5c890f8ff1b621432c7909bf2a9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 23 Oct 2024 21:15:33 +0200 Subject: [PATCH] Extend searcher for assignation required from supplier consignment Closes #8893 (grafted from 5fb7d90bc1e7725ba7788f7dfb789b1e4192c5ac) --HG-- branch : 7.0 --- modules/stock_consignment/stock.py | 38 ++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/modules/stock_consignment/stock.py b/modules/stock_consignment/stock.py index cbb3a13162..87841665d7 100644 --- a/modules/stock_consignment/stock.py +++ b/modules/stock_consignment/stock.py @@ -5,7 +5,7 @@ from functools import wraps from trytond.model import ModelView, Workflow, fields from trytond.pool import Pool, PoolMeta from trytond.pyson import Eval -from trytond.transaction import Transaction +from trytond.transaction import Transaction, inactive_records class Location(metaclass=PoolMeta): @@ -138,11 +138,45 @@ class Move(metaclass=PoolMeta): required = super(Move, self).on_change_with_assignation_required( name=name) if self.from_location: - if (self.from_location.type == 'supplier' + if (self.quantity + and self.from_location.type == 'supplier' and self.from_location.warehouse): required = True return required + @classmethod + def search_assignation_required(cls, name, clause): + pool = Pool() + Location = pool.get('stock.location') + _, operator, operand = clause + domain = super().search_assignation_required(name, clause) + reverse = { + '=': '!=', + '!=': '=', + } + if operator in reverse: + with inactive_records(): + warehouses = Location.search([ + ('type', '=', 'warehouse'), + ]) + warehouse_ids = list(map(int, warehouses)) + if operator == '!=': + bool_op = 'AND' + warehouse_op = 'not child_of' + else: + bool_op = 'OR' + warehouse_op = 'child_of' + if not operand: + operator = reverse[operator] + domain = [bool_op, + domain, + [('quantity', '!=', 0), + ('from_location.type', operator, 'supplier'), + ('from_location', warehouse_op, warehouse_ids, 'parent'), + ], + ] + return domain + @property def is_supplier_consignment(self): return (self.from_location.type == 'supplier'