Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] maintenance_equipment_sequence: add model_create_multi to create method #435

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions maintenance_equipment_sequence/models/maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading