[IMP] mrp: stop creating return on done transfer

Before this commit
===================
In MO if a line is deleted or line has its to consume quantity reduced so in
done state transfers return is creating.

After this commit
===================
Stopped creating the return on done state transfer when quantity is reduced or
a line is deleted.

closes odoo/odoo#133696

Task: 3283010
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
Tejas Modi
2023-11-03 18:05:33 +00:00
committed by William Henrotin
parent 4048cd824e
commit cd53a24e0b
2 changed files with 32 additions and 0 deletions
+6
View File
@@ -305,6 +305,10 @@ class StockMove(models.Model):
to_assign = self.env['stock.move']
self._adjust_procure_method()
for move in self:
if float_compare(move.product_uom_qty - old_qties.get(move.id, 0), 0, precision_rounding=move.product_uom.rounding) < 0\
and move.procure_method == 'make_to_order'\
and all(m.state == 'done' for m in move.move_orig_ids):
continue
if float_compare(move.product_uom_qty, 0, precision_rounding=move.product_uom.rounding) > 0:
if move._should_bypass_reservation() \
or move.picking_type_id.reservation_method == 'at_confirm' \
@@ -313,6 +317,8 @@ class StockMove(models.Model):
if move.procure_method == 'make_to_order':
procurement_qty = move.product_uom_qty - old_qties.get(move.id, 0)
possible_reduceable_qty = -sum(move.move_orig_ids.filtered(lambda m: m.state not in ('done', 'cancel') and m.product_uom_qty).mapped('product_uom_qty'))
procurement_qty = max(procurement_qty, possible_reduceable_qty)
values = move._prepare_procurement_values()
origin = move._prepare_procurement_origin()
procurements.append(self.env['procurement.group'].Procurement(
+26
View File
@@ -3572,3 +3572,29 @@ class TestMrpOrder(TestMrpCommon):
# Force the warning
consumption_warning.action_confirm()
self.assertEqual(mo.state, 'done')
def test_cancel_return(self):
"""
check that the return picking is not created on done state transfer when reducing MO quantity.
"""
self.stock_location = self.env.ref('stock.stock_location_stock')
warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1)
warehouse.manufacture_steps = 'pbm'
mo, _bom, _p_final, p1, p2 = self.generate_mo(qty_final=5.0, qty_base_1=1.0, qty_base_2=1.0)
mo.action_confirm()
self.env['stock.quant']._update_available_quantity(p1, self.stock_location, 5.0)
self.env['stock.quant']._update_available_quantity(p2, self.stock_location, 5.0)
mo.picking_ids.move_ids[0].quantity = 5.0
mo.picking_ids.move_ids[1].quantity = 5.0
mo.picking_ids.button_validate()
update_quantity_wizard = self.env['change.production.qty'].create({
'mo_id': mo.id,
'product_qty': 4.0,
})
update_quantity_wizard.change_prod_qty()
new_picking = mo.picking_ids
self.assertEqual(len(new_picking), 1, "Return picking should not be created in done Transfer")