[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
This commit is contained in:
Arnold Moyaux
2023-05-30 13:03:20 +02:00
committed by William Henrotin
parent 71711f864e
commit e650d20e4d
3 changed files with 5 additions and 1 deletions
+3
View File
@@ -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):
-1
View File
@@ -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):
+2
View File
@@ -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