trytond-patches/search_warehouse.diff
2023-01-04 16:05:47 +01:00

41 lines
1.8 KiB
Diff

diff --git a/location.py b/location.py
index 87104cf..3d89bdb 100644
--- a/tryton/modules/stock/location.py
+++ b/tryton/modules/stock/location.py
@@ -72,7 +72,7 @@ class Location(DeactivableMixin, tree(), ModelSQL, ModelView):
help="Check to enforce a single level of children with no "
"grandchildren.")
warehouse = fields.Function(fields.Many2One('stock.location', 'Warehouse'),
- 'get_warehouse')
+ 'get_warehouse', searcher='search_warehouse')
input_location = fields.Many2One(
"stock.location", "Input", states={
'invisible': Eval('type') != 'warehouse',
@@ -234,6 +234,27 @@ class Location(DeactivableMixin, tree(), ModelSQL, ModelView):
inactives.append(location)
cls.check_inactive(inactives)
+ @classmethod
+ def search_warehouse(cls, name, clause):
+ warehouse_child_locations = cls.search([
+ ('parent.type', '=', 'warehouse'),
+ ('type', '=', 'storage'),
+ ('parent', clause[1], clause[2]),
+ ])
+ found_warehouse_ids = []
+ storage_location_ids = []
+ for location in warehouse_child_locations:
+ storage_location_ids.append(location.id)
+ found_warehouse_ids.append(location.parent.id)
+ warehouse_location_ids = []
+ for location in cls.search([
+ ('parent', 'child_of', storage_location_ids),
+ ]):
+ if (location.warehouse and location.warehouse.id in
+ found_warehouse_ids):
+ warehouse_location_ids.append(location.id)
+ return [('id', 'in', warehouse_location_ids)]
+
def check_type_for_moves(self, field_names=None):
""" Check locations with moves have types compatible with moves. """
pool = Pool()