Skip to content

Commit

Permalink
[imp] add model_create_multi to create method
Browse files Browse the repository at this point in the history
  • Loading branch information
is-ife authored and rf-ife committed Nov 28, 2024
1 parent 0c56bb4 commit 6b65c3a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
21 changes: 11 additions & 10 deletions maintenance_equipment_sequence/models/maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@ 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)
@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)
self._compute_equipment_code()
return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ def test_01_maintenance_equipment_sequence(self):
sequence number has been set
"""
# Create category
seq_0 = self.sequence_obj.create(
{
"name": "Test Sequence",
"implementation": "no_gap",
"prefix": "TTC_TEST",
"padding": 4,
"number_increment": 1,
"use_date_range": False,
}
)
categ_0 = self.maintenance_equipment_categ_obj.create(
{
"name": "Test Category 0",
"sequence_id": seq_0.id,
}
)
self.assertEqual(categ_0.sequence_prefix, seq_0.prefix)

categ_1 = self.maintenance_equipment_categ_obj.create(
{
"name": "Test Category",
Expand Down

0 comments on commit 6b65c3a

Please sign in to comment.