[FIX] mrp: backorder sequence fallback

In case a production order loses its procurement group. The backorder
generation process do not have access to the last backorder sequence
used. This commit set a default value to avoid any traceback.

The new backorder  name will not be guaranteed exact related to the
production sequence but will be unique in any cases.

closes odoo/odoo#76091

X-original-commit: aae07e88a8166cf26a8c81bb8ee37d630fd6672c
Signed-off-by: William Henrotin <Whenrow@users.noreply.github.com>
This commit is contained in:
William Henrotin
2021-09-07 15:50:25 +00:00
parent 7dbc9ec17a
commit 3ee10159db
2 changed files with 19 additions and 1 deletions
+1 -1
View File
@@ -1441,7 +1441,7 @@ class MrpProduction(models.Model):
def _get_backorder_mo_vals(self):
self.ensure_one()
next_seq = max(self.procurement_group_id.mrp_production_ids.mapped("backorder_sequence"))
next_seq = max(self.procurement_group_id.mrp_production_ids.mapped("backorder_sequence"), default=1)
return {
'name': self._get_name_backorder(self.name, next_seq + 1),
'backorder_sequence': next_seq + 1,
+18
View File
@@ -312,6 +312,24 @@ class TestMrpProductionBackorder(TestMrpCommon):
self.assertEqual(new_backorder.name, initial_mo_name + "-" + str(seq + 1))
backorder = new_backorder
def test_backorder_name_without_procurement_group(self):
production = self.generate_mo(qty_final=5)[0]
mo_form = Form(production)
mo_form.qty_producing = 1
mo = mo_form.save()
# Remove pg to trigger fallback on backorder name
mo.procurement_group_id = False
action = mo.button_mark_done()
backorder_form = Form(self.env['mrp.production.backorder'].with_context(**action['context']))
backorder_form.save().action_backorder()
# The pg is back
self.assertTrue(production.procurement_group_id)
backorder_ids = production.procurement_group_id.mrp_production_ids[1]
self.assertEqual(production.name.split('-')[0], backorder_ids.name.split('-')[0])
self.assertEqual(int(production.name.split('-')[1]) + 1, int(backorder_ids.name.split('-')[1]))
class TestMrpWorkorderBackorder(TransactionCase):
@classmethod