From 3562c769cad70915393dab4f8dc91626d328eda2 Mon Sep 17 00:00:00 2001 From: ?ngel ?lvarez Date: Tue, 12 Jun 2018 16:24:10 +0200 Subject: [PATCH] make warehouse searchable --- search_warehouse.diff | 40 ++++++++++++++++++++++++++++++++++++++++ series | 1 + 2 files changed, 41 insertions(+) create mode 100644 search_warehouse.diff diff --git a/search_warehouse.diff b/search_warehouse.diff new file mode 100644 index 0000000..9765a54 --- /dev/null +++ b/search_warehouse.diff @@ -0,0 +1,40 @@ +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'] diff --git a/series b/series index 9559fb6..8caf4dd 100644 --- a/series +++ b/series @@ -10,5 +10,6 @@ issue4506.diff # [account_invoice] Add credit invoices keyword from account.invo issue4030.diff # [analytic_account] Not selected root accounts in analytic account lines issue4482.diff # [stock] stock inventory misses company access rule +search_warehouse.diff #[stock] search function for warehouse. stock_consignment_create_invoice_lines_on_move_done.diff # [stock_consignment] Task #034628: stock_consignment only create invoice lines on move done domain_validation_warning.diff # [trytond] Increase the verbosity of domain_validation_error message