[FIX] stock: auto assign backorder

When a backorder is created, the quantities are not reserved. This is an
issue: the module should try to directly assign these quantities if the
reservation method of the associated operation type is "At Confirmation"

(Forward port of 723d4b35f9fa9c49249c1b4e9b8dc93e51c5d359)

OPW-2658469

closes odoo/odoo#79980

X-original-commit: ae19ae04192d21ad956af05e5739bde8c6bca746
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Adrien Widart <awt@odoo.com>
This commit is contained in:
Adrien Widart
2021-11-18 07:53:36 +00:00
parent c5b72fa895
commit 65a2e46572
2 changed files with 38 additions and 0 deletions
+5
View File
@@ -1119,6 +1119,7 @@ class Picking(models.Model):
picking, the backorder, and move the stock.moves that are not `done` or `cancel` into it.
"""
backorders = self.env['stock.picking']
bo_to_assign = self.env['stock.picking']
for picking in self:
moves_to_backorder = picking.move_ids.filtered(lambda x: x.state not in ('done', 'cancel'))
if moves_to_backorder:
@@ -1135,6 +1136,10 @@ class Picking(models.Model):
moves_to_backorder.mapped('package_level_id').write({'picking_id':backorder_picking.id})
moves_to_backorder.mapped('move_line_ids').write({'picking_id': backorder_picking.id})
backorders |= backorder_picking
if backorder_picking.picking_type_id.reservation_method == 'at_confirm':
bo_to_assign |= backorder_picking
if bo_to_assign:
bo_to_assign.action_assign()
return backorders
def _log_activity_get_documents(self, orig_obj_changes, stream_field, stream, groupby_method=False):
+33
View File
@@ -2068,3 +2068,36 @@ class TestStockFlow(TestStockCommon):
validate_picking(in02)
self.assertEqual(out02.state, 'confirmed')
self.assertEqual(out03.state, 'assigned')
def test_auto_assign_backorder(self):
""" When a backorder is created, the quantities should be assigned if the reservation method
is set on 'At Confirmation' """
stock_location = self.env['stock.location'].browse(self.stock_location)
picking_type_out = self.env['stock.picking.type'].browse(self.picking_type_out)
self.env['stock.quant']._update_available_quantity(self.productA, stock_location, 10)
picking_type_out.reservation_method = 'at_confirm'
picking_out = self.PickingObj.create({
'picking_type_id': picking_type_out.id,
'location_id': stock_location.id,
'location_dest_id': self.customer_location,
})
move_out = self.MoveObj.create({
'name': self.productA.name,
'product_id': self.productA.id,
'product_uom_qty': 10,
'product_uom': self.productA.uom_id.id,
'picking_id': picking_out.id,
'location_id': stock_location.id,
'location_dest_id': self.customer_location
})
move_out.quantity_done = 7
action_dict = picking_out.button_validate()
backorder_wizard = Form(self.env[action_dict['res_model']].with_context(action_dict['context'])).save()
backorder_wizard.process()
bo = self.env['stock.picking'].search([('backorder_id', '=', picking_out.id)])
self.assertEqual(bo.state, 'assigned')