diff --git a/maintenance_equipment_sequence/models/maintenance.py b/maintenance_equipment_sequence/models/maintenance.py index c8348060f..f8b3fcc1a 100644 --- a/maintenance_equipment_sequence/models/maintenance.py +++ b/maintenance_equipment_sequence/models/maintenance.py @@ -63,17 +63,18 @@ def _inverse_seq_number_next(self): sequence = category.sequence_id._get_current_sequence() sequence.sudo().number_next = category.sequence_number_next - @api.model - def create(self, vals): - if not vals.get("sequence_id", False): - if vals.get("sequence_prefix", False): - vals["sequence_id"] = self.sudo()._create_sequence(vals).id - else: - vals["sequence_prefix"] = ( - self.env["ir.sequence"].browse(vals["sequence_id"]).prefix - ) - result = super(MaintenanceEquipmentCategory, self).create(vals) - self._compute_equipment_code() + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if not vals.get("sequence_id", False): + if vals.get("sequence_prefix", False): + vals["sequence_id"] = self.sudo()._create_sequence(vals).id + else: + vals["sequence_prefix"] = ( + self.env["ir.sequence"].browse(vals["sequence_id"]).prefix + ) + result = super().create(vals_list) + result._compute_equipment_code() return result def write(self, vals): diff --git a/maintenance_equipment_sequence/tests/test_maintenance_equipment_sequence.py b/maintenance_equipment_sequence/tests/test_maintenance_equipment_sequence.py index 176cf5a33..b6bb5b6db 100644 --- a/maintenance_equipment_sequence/tests/test_maintenance_equipment_sequence.py +++ b/maintenance_equipment_sequence/tests/test_maintenance_equipment_sequence.py @@ -59,3 +59,27 @@ def test_01_maintenance_equipment_sequence(self): # Remove code and be automatically set to sequence next value equipment_1.write({"serial_no": False}) self.assertEqual(equipment_1.serial_no, "TTC0002") + + def test_02_maintenance_equipment_sequence(self): + """Create an equipment category linked to a default sequence with a prefix, + and verify that the category correctly inherits the sequence prefix. + """ + # Create a sequence + seq_1 = self.sequence_obj.create( + { + "name": "Test Sequence", + "implementation": "no_gap", + "prefix": "TTC_TEST", + "padding": 4, + "number_increment": 1, + "use_date_range": False, + } + ) + # Create an equipment category linked to the sequence + categ_1 = self.maintenance_equipment_categ_obj.create( + { + "name": "Test Category 0", + "sequence_id": seq_1.id, + } + ) + self.assertEqual(categ_1.sequence_prefix, seq_1.prefix)