From cf9ae54fe3dee4bb3885784a37d0832a02c2d335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 17 Mar 2020 23:35:47 +0100 Subject: [PATCH] Define lost and found location for inventory on parent location We remove the lost and found location on the inventory to only used one define on the warehouse or parent of the inventoried location. issue9071 review276901002 --- CHANGELOG | 2 ++ stock.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 66f0520f4e..6f3ab2dc66 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Add lost and found per supplier and customer location + Version 5.4.0 - 2019-11-04 * Bug fixes (see mercurial logs for details) diff --git a/stock.py b/stock.py index 4e2d7864d4..adf9223666 100644 --- a/stock.py +++ b/stock.py @@ -20,6 +20,12 @@ class Location(metaclass=PoolMeta): depends=['type'], help="The party invoiced when consignment stock is used.") + @classmethod + def __setup__(cls): + super().__setup__() + cls.lost_found_location.states['invisible'] &= ( + ~Eval('type').in_(['supplier', 'customer'])) + @classmethod def _parent_domain(cls): domain = super(Location, cls)._parent_domain() @@ -27,6 +33,18 @@ class Location(metaclass=PoolMeta): domain['storage'].append('customer') return domain + @property + def lost_found_used(self): + lost_found = super().lost_found_used + if not lost_found and not self.warehouse and self.type == 'storage': + location = self.parent + while location: + if location.type in {'supplier', 'storage'}: + lost_found = location.lost_found_location + break + location = location.parent + return lost_found + class LocationLeadTime(metaclass=PoolMeta): __name__ = 'stock.location.lead_time'