[FIX] mrp: set backorder name with custom sequence name
If the prefix of the production sequence contains some dashes, it can
lead to undesirable behaviors
To reproduce the error:
(Enable debug mode)
1. Settings > Technical > Sequences & Identifiers > Sequences, edit "San
Francisco Sequence production":
- Prefix: "WH-MO-"
2. Create a MO
- Quantity: 2
3. Confirm, Edit:
- Quantity: 1/2
4. (Keep MO's name in mind and) Validate + Create backorder
Error: Backorder's name is "WH-MO-002" instead of "WH-MO-0000X-002".
Going back to the initial MO, its name became "WH-MO-001" (was
"WH-MO-0000X")
OPW-2618971
closes odoo/odoo#75270
X-original-commit: 076fe045f219dcb018b3b18215bfc3a0cfb3aa46
Signed-off-by: Rémy Voet <ryv-odoo@users.noreply.github.com>
Signed-off-by: Adrien Widart <adwid@users.noreply.github.com>
This commit is contained in:
@@ -1395,7 +1395,7 @@ class MrpProduction(models.Model):
|
||||
return name
|
||||
seq_back = "-" + "0" * (SIZE_BACK_ORDER_NUMERING - 1 - int(math.log10(sequence))) + str(sequence)
|
||||
regex = re.compile(r"-\d+$")
|
||||
if regex.search(name):
|
||||
if regex.search(name) and sequence > 1:
|
||||
return regex.sub(seq_back, name)
|
||||
return name + seq_back
|
||||
|
||||
@@ -1418,6 +1418,7 @@ class MrpProduction(models.Model):
|
||||
for production in self:
|
||||
if production.backorder_sequence == 0: # Activate backorder naming
|
||||
production.backorder_sequence = 1
|
||||
production.name = self._get_name_backorder(production.name, production.backorder_sequence)
|
||||
backorder_mo = production.copy(default=production._get_backorder_mo_vals())
|
||||
if close_mo:
|
||||
production.move_raw_ids.filtered(lambda m: m.state not in ('done', 'cancel')).write({
|
||||
@@ -1449,8 +1450,6 @@ class MrpProduction(models.Model):
|
||||
else:
|
||||
wo.qty_producing = wo.qty_remaining
|
||||
|
||||
production.name = self._get_name_backorder(production.name, production.backorder_sequence)
|
||||
|
||||
# We need to adapt `duration_expected` on both the original workorders and their
|
||||
# backordered workorders. To do that, we use the original `duration_expected` and the
|
||||
# ratio of the quantity really produced and the quantity to produce.
|
||||
|
||||
@@ -280,6 +280,38 @@ class TestMrpProductionBackorder(TestMrpCommon):
|
||||
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final, self.stock_location), nb_product_todo, f'You should have the {nb_product_todo} final product in stock')
|
||||
self.assertEqual(len(production.procurement_group_id.mrp_production_ids), nb_product_todo)
|
||||
|
||||
def test_backorder_name(self):
|
||||
def produce_one(mo):
|
||||
mo_form = Form(mo)
|
||||
mo_form.qty_producing = 1
|
||||
mo = mo_form.save()
|
||||
action = mo.button_mark_done()
|
||||
backorder = Form(self.env['mrp.production.backorder'].with_context(**action['context']))
|
||||
backorder.save().action_backorder()
|
||||
return mo.procurement_group_id.mrp_production_ids[-1]
|
||||
|
||||
default_picking_type_id = self.env['mrp.production']._get_default_picking_type()
|
||||
default_picking_type = self.env['stock.picking.type'].browse(default_picking_type_id)
|
||||
mo_sequence = default_picking_type.sequence_id
|
||||
|
||||
mo_sequence.prefix = "WH-MO-"
|
||||
initial_mo_name = mo_sequence.prefix + str(mo_sequence.number_next_actual).zfill(mo_sequence.padding)
|
||||
|
||||
production = self.generate_mo(qty_final=5)[0]
|
||||
self.assertEqual(production.name, initial_mo_name)
|
||||
|
||||
backorder = produce_one(production)
|
||||
self.assertEqual(production.name, initial_mo_name + "-001")
|
||||
self.assertEqual(backorder.name, initial_mo_name + "-002")
|
||||
|
||||
backorder.backorder_sequence = 998
|
||||
|
||||
for seq in [998, 999, 1000]:
|
||||
new_backorder = produce_one(backorder)
|
||||
self.assertEqual(backorder.name, initial_mo_name + "-" + str(seq))
|
||||
self.assertEqual(new_backorder.name, initial_mo_name + "-" + str(seq + 1))
|
||||
backorder = new_backorder
|
||||
|
||||
|
||||
class TestMrpWorkorderBackorder(TransactionCase):
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user