trytond-patches/search_warehouse.diff

41 lines
1.7 KiB
Diff

diff -r 78ac887c5b7f location.py
--- a/trytond/trytond/modules/stock/location.py Tue Jun 12 16:16:43 2018 +0200
+++ b/trytond/trytond/modules/stock/location.py Tue Jun 12 16:19:53 2018 +0200
@@ -59,7 +59,7 @@
"Flat Children",
help="Check to restrict to one level of children.")
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',
@@ -195,6 +195,27 @@
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):
""" Check locations with moves have types compatible with moves. """
invalid_move_types = ['warehouse', 'view']