From e650d20e4d8dacbfe8228fc3652fb507dab22185 Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Wed, 24 May 2023 15:08:35 +0000 Subject: [PATCH] [FIX] stock: don't set draft move with 0 quantity Usecase: - Create a picking and a move without quantity - Click or the show detail or save The picking goes into the state draft while it shouldn't. It happens because when a quantity done is set, it will goes to process_increase that will assign the move. With 0 qty, it's not assign and stay in draft (default value) The picking state is then computed based on the move state. To fix it, force the state to assign on stock.move in immediate transfer without quantity. Part-of: odoo/odoo#122445 --- addons/stock/models/stock_move.py | 3 +++ addons/stock/models/stock_picking.py | 1 - addons/stock/tests/test_report.py | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index e0ac7040f76..cd7aebd3198 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -656,6 +656,9 @@ Please change the quantity done or the rounding precision of your unit of measur for vals in vals_list: if vals.get('quantity_done') and 'lot_ids' in vals: vals.pop('lot_ids') + picking_id = self.env['stock.picking'].browse(vals.get('picking_id')) + if picking_id and picking_id.immediate_transfer and not vals.get('qty_done'): + vals['state'] = 'assigned' return super().create(vals_list) def write(self, vals): diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 967ab43e396..e39fe1ed28a 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -770,7 +770,6 @@ class Picking(models.Model): vals['immediate_transfer'] = False if self.env['ir.config_parameter'].sudo().get_param('stock.no_default_immediate_tranfer'): vals['immediate_transfer'] = False - pickings = super().create(vals_list) for picking, scheduled_date in zip(pickings, scheduled_dates): diff --git a/addons/stock/tests/test_report.py b/addons/stock/tests/test_report.py index d3aec426dd7..1ed9a89292b 100644 --- a/addons/stock/tests/test_report.py +++ b/addons/stock/tests/test_report.py @@ -1114,6 +1114,8 @@ class TestReports(TestReportsCommon): delivery2_form.scheduled_date = datetime.now() + timedelta(days=1) delivery2 = delivery2_form.save() delivery2.move_ids.quantity_done = delivery1.move_ids.quantity_done + # To avoid stealing the 150 unit in stock + delivery2.do_unreserve() self.assertEqual(delivery2.move_ids.forecast_availability, 100) # Check for both deliveries and receipts if the highlight (is_matched) corresponds to the correct picking