From bb42ac43966c5e5dc4ba225ec804b745f2a09451 Mon Sep 17 00:00:00 2001 From: JF Aubert Date: Fri, 23 Sep 2022 06:48:24 +0000 Subject: [PATCH] [FIX] stock: fix replenishment report MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the choice of available stock effective (previously the total quantity was always applied). Show warehouses with the most available stock first. Show quantity warning only when appropriate. closes odoo/odoo#101010 Task: 2985735 X-original-commit: 483764412985163168333e2731bed359cc588bbb Signed-off-by: Arnold Moyaux (arm) Signed-off-by: Jean-François Aubert --- .../stock/wizard/stock_replenishment_info.py | 19 +++++++++++-------- .../stock/wizard/stock_replenishment_info.xml | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/addons/stock/wizard/stock_replenishment_info.py b/addons/stock/wizard/stock_replenishment_info.py index 27b877b86ab..8efbed0cf52 100644 --- a/addons/stock/wizard/stock_replenishment_info.py +++ b/addons/stock/wizard/stock_replenishment_info.py @@ -29,7 +29,7 @@ class StockReplenishmentInfo(models.TransientModel): replenishment_info.wh_replenishment_option_ids = self.env['stock.replenishment.option'].create([ {'product_id': replenishment_info.product_id.id, 'route_id': route_id.id, 'replenishment_info_id': replenishment_info.id} for route_id in replenishment_info.warehouseinfo_ids - ]) + ]).sorted(lambda o: o.free_qty, reverse=True) @api.depends('orderpoint_id') def _compute_json_lead_days(self): @@ -122,13 +122,15 @@ class StockReplenishmentOption(models.TransientModel): @api.depends('warehouse_id', 'free_qty', 'uom', 'qty_to_order') def _compute_warning_message(self): + self.warning_message = '' for record in self: - self.warning_message = _('{0} can only provide {1} {2}, while the quantity to order is {3} {2}.').format( - record.warehouse_id.name, - record.free_qty, - record.uom, - record.qty_to_order - ) + if record.free_qty < record.qty_to_order: + record.warning_message = _('{0} can only provide {1} {2}, while the quantity to order is {3} {2}.').format( + record.warehouse_id.name, + record.free_qty, + record.uom, + record.qty_to_order + ) def select_route(self): if self.free_qty < self.qty_to_order: @@ -143,8 +145,9 @@ class StockReplenishmentOption(models.TransientModel): return self.order_all() def order_avbl(self): + self.replenishment_info_id.orderpoint_id.route_id = self.route_id self.replenishment_info_id.orderpoint_id.qty_to_order = self.free_qty - return self.order_all() + return {'type': 'ir.actions.act_window_close'} def order_all(self): self.replenishment_info_id.orderpoint_id.route_id = self.route_id diff --git a/addons/stock/wizard/stock_replenishment_info.xml b/addons/stock/wizard/stock_replenishment_info.xml index 54f162680bf..a7ad9d6ed41 100644 --- a/addons/stock/wizard/stock_replenishment_info.xml +++ b/addons/stock/wizard/stock_replenishment_info.xml @@ -65,7 +65,7 @@