Skip to content

Commit

Permalink
[MIG] maintenance_equipment_sequence: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Anxo82 committed Jun 4, 2024
1 parent 90f7a5e commit f636a75
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 11 deletions.
2 changes: 1 addition & 1 deletion maintenance_equipment_sequence/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"summary": """
Adds sequence to maintenance equipment defined in the equipment's
category""",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"author": "ForgeFlow S.L.," "Odoo Community Association (OCA)",
"maintainers": ["AdriaGForgeFlow"],
Expand Down
8 changes: 4 additions & 4 deletions maintenance_equipment_sequence/models/maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def create(self, vals):
vals["sequence_prefix"] = (
self.env["ir.sequence"].browse(vals["sequence_id"]).prefix
)
result = super(MaintenanceEquipmentCategory, self).create(vals)
result = super().create(vals)
self._compute_equipment_code()
return result

Expand All @@ -84,7 +84,7 @@ def write(self, vals):
vals["sequence_prefix"] = (
self.env["ir.sequence"].browse(vals["sequence_id"]).prefix
)
result = super(MaintenanceEquipmentCategory, self).write(vals)
result = super().write(vals)
self._compute_equipment_code()
return result

Expand All @@ -109,7 +109,7 @@ class MaintenanceEquipment(models.Model):

@api.model
def create(self, vals):
equipment = super(MaintenanceEquipment, self).create(vals)
equipment = super().create(vals)
if equipment.category_id and not equipment.serial_no:
sequence_id = (
self.env["maintenance.equipment.category"]
Expand All @@ -121,7 +121,7 @@ def create(self, vals):
return equipment

def write(self, vals):
result = super(MaintenanceEquipment, self).write(vals)
result = super().write(vals)
for rec in self:
if rec.category_id and not rec.serial_no and rec.category_id.sequence_id:
rec.serial_no = rec.category_id.sequence_id._next()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class TestMaintenanceEquipmentSequence(TransactionCase):
def setUp(self):
super(TestMaintenanceEquipmentSequence, self).setUp()
super().setUp()
self.maintenance_equipment_categ_obj = self.env[
"maintenance.equipment.category"
]
Expand Down Expand Up @@ -59,3 +59,92 @@ 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_compute_seq_number_next(self):
"""Test Compute 'sequence_number_next' according to the current sequence in use,
an ir.sequence or an ir.sequence.date_range."""

sequence = self.sequence_obj.create(
{
"name": "Test Sequence",
"prefix": "TST",
"padding": 3,
"number_next": 5,
"use_date_range": False,
}
)

category = self.maintenance_equipment_categ_obj.create(
{
"name": "Test Category with Sequence",
"sequence_id": sequence.id,
}
)

category._compute_seq_number_next()
self.assertEqual(category.sequence_number_next, 5)

sequence.write({"number_next_actual": 10})
category._compute_seq_number_next()
self.assertEqual(category.sequence_number_next, 10)

category_no_seq = self.maintenance_equipment_categ_obj.create(
{
"name": "Test Category without Sequence",
}
)

category_no_seq._compute_seq_number_next()
self.assertEqual(category_no_seq.sequence_number_next, 1)

def test_03_create_with_existing_sequence(self):
"""Test def create(self, vals):"""

existing_sequence = self.sequence_obj.create(
{
"name": "Existing Sequence",
"prefix": "EXS",
"padding": 3,
"number_increment": 1,
"use_date_range": False,
}
)

category_with_seq = self.maintenance_equipment_categ_obj.create(
{
"name": "Category with Existing Sequence",
"sequence_id": existing_sequence.id,
}
)

self.assertEqual(category_with_seq.sequence_prefix, "EXS")
self.assertEqual(category_with_seq.sequence_id.id, existing_sequence.id)

def test_04_compute_equipment_code(self):
"""Test def _compute_equipment_code(self):"""

seq_01 = self.sequence_obj.create(
{
"name": "Test Sequence",
"prefix": "TST",
"padding": 3,
"number_increment": 1,
"use_date_range": False,
}
)

cat_01 = self.maintenance_equipment_categ_obj.create(
{"name": "Test Category", "sequence_id": seq_01.id}
)

equipment_01 = self.env["maintenance.equipment"].create(
{
"name": "Test Equipment",
"category_id": cat_01.id,
"serial_no": False,
}
)

cat_01._compute_equipment_code()

self.assertEqual(equipment_01.serial_no, "TST001")
8 changes: 3 additions & 5 deletions maintenance_equipment_sequence/views/maintenance_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
<field name="arch" type="xml">
<group name="group_alias" position="after">
<group>
<field
name="sequence_prefix"
attrs="{'readonly': [('sequence_id', '!=', False)]}"
/>
<field name="sequence_prefix" readonly="sequence_id != False" />
<field
name="sequence_number_next"
style="padding-right: 1.0em"
attrs="{'readonly': [('sequence_id', '!=', False)], 'invisible': [('sequence_prefix', '=', False)]}"
readonly="sequence_id != False"
invisible="sequence_prefix == False"
/>
<field name="sequence_id" required="0" />
</group>
Expand Down

0 comments on commit f636a75

Please sign in to comment.