From 981fd0c7603e97a5bcaa8aec15fa3eaceb308fa8 Mon Sep 17 00:00:00 2001 From: Patrick Wilson <36892066+patrickrwilson@users.noreply.github.com> Date: Mon, 23 Mar 2020 11:01:45 -0500 Subject: [PATCH 1/5] [IMP] Warehouse On Change Since the location and routes depend on the warehouse that is selected on the stock request order, if the warehouse changes then so will the route options. This adds an on change event so if the warehouse changes, then the direction gets cleared and so do the routes on the product lines. This forces the user to properly reset the items using the correct routes for the newly selected warehouse. --- stock_request_direction/models/stock_request_order.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stock_request_direction/models/stock_request_order.py b/stock_request_direction/models/stock_request_order.py index 29e719c76..f1b970180 100644 --- a/stock_request_direction/models/stock_request_order.py +++ b/stock_request_direction/models/stock_request_order.py @@ -23,6 +23,14 @@ class StockRequestOrder(models.Model): # Otherwise the Stock Location of the Warehouse self.location_id = self.warehouse_id.lot_stock_id.id + @api.onchange('warehouse_id') + def _onchange_warehouse_id(self): + if self.direction: + self.direction = False + for stock_request in self.stock_request_ids: + if stock_request.route_id: + stock_request.route_id = False + def change_childs(self): super().change_childs() if not self._context.get("no_change_childs", False): From 648776327c9717c23e12d84ab79cbc29247b0624 Mon Sep 17 00:00:00 2001 From: Patrick Wilson <36892066+patrickrwilson@users.noreply.github.com> Date: Wed, 1 Apr 2020 16:43:24 -0500 Subject: [PATCH 2/5] [IMP] Add warehouse_id to existing onchange. --- stock_request_direction/models/stock_request_order.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/stock_request_direction/models/stock_request_order.py b/stock_request_direction/models/stock_request_order.py index f1b970180..3e5cd274b 100644 --- a/stock_request_direction/models/stock_request_order.py +++ b/stock_request_direction/models/stock_request_order.py @@ -14,7 +14,7 @@ class StockRequestOrder(models.Model): readonly=True, ) - @api.onchange("direction") + @api.onchange("warehouse_id", "direction") def _onchange_location_id(self): if self.direction == "outbound": # Stock Location set to Partner Locations/Customers @@ -22,11 +22,6 @@ class StockRequestOrder(models.Model): else: # Otherwise the Stock Location of the Warehouse self.location_id = self.warehouse_id.lot_stock_id.id - - @api.onchange('warehouse_id') - def _onchange_warehouse_id(self): - if self.direction: - self.direction = False for stock_request in self.stock_request_ids: if stock_request.route_id: stock_request.route_id = False From 10ba1ac8c57cac4c959c310066d5e375076dde20 Mon Sep 17 00:00:00 2001 From: Patrick Wilson <36892066+patrickrwilson@users.noreply.github.com> Date: Thu, 16 Apr 2020 16:00:51 -0500 Subject: [PATCH 3/5] [FIX] Conflict with stock_request onchange method The onchange method in the stock_request module is no longer needed so this overrides that to do nothing. --- stock_request_direction/models/stock_request_order.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stock_request_direction/models/stock_request_order.py b/stock_request_direction/models/stock_request_order.py index 3e5cd274b..10e545451 100644 --- a/stock_request_direction/models/stock_request_order.py +++ b/stock_request_direction/models/stock_request_order.py @@ -26,6 +26,11 @@ class StockRequestOrder(models.Model): if stock_request.route_id: stock_request.route_id = False + @api.onchange('warehouse_id') + def onchange_warehouse_id(self): + # Onchange no longer needed + pass + def change_childs(self): super().change_childs() if not self._context.get("no_change_childs", False): From 70651adb5915800469b489dcfeb9dec2f020cf7e Mon Sep 17 00:00:00 2001 From: Kitti U Date: Thu, 15 Apr 2021 22:46:23 +0700 Subject: [PATCH 4/5] [FIX] stock.request's location_id conflict with stock.request.order's --- stock_request_direction/models/stock_request.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stock_request_direction/models/stock_request.py b/stock_request_direction/models/stock_request.py index 03a0611ed..8c150edb5 100644 --- a/stock_request_direction/models/stock_request.py +++ b/stock_request_direction/models/stock_request.py @@ -17,8 +17,8 @@ class StockRequest(models.Model): @api.onchange("direction") def _onchange_location_id(self): if self.direction == "outbound": - # Partner Locations/Customers - self.location_id = self.env.ref("stock.stock_location_customers") + # Stock Location set to Partner Locations/Customers + self.location_id = self.company_id.partner_id.property_stock_customer.id else: # Otherwise the Stock Location of the Warehouse self.location_id = self.warehouse_id.lot_stock_id.id From bbd83c073bf0283ebf42b3ef48bc7939e85caad8 Mon Sep 17 00:00:00 2001 From: Kitti U Date: Thu, 15 Apr 2021 22:52:27 +0700 Subject: [PATCH 5/5] pre-commit fix --- stock_request_direction/models/stock_request_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stock_request_direction/models/stock_request_order.py b/stock_request_direction/models/stock_request_order.py index 10e545451..e794e6058 100644 --- a/stock_request_direction/models/stock_request_order.py +++ b/stock_request_direction/models/stock_request_order.py @@ -26,7 +26,7 @@ class StockRequestOrder(models.Model): if stock_request.route_id: stock_request.route_id = False - @api.onchange('warehouse_id') + @api.onchange("warehouse_id") def onchange_warehouse_id(self): # Onchange no longer needed pass