Skip to content

Commit

Permalink
[MIG] cb_maintenance: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kluna1998 committed Oct 17, 2024
1 parent e717594 commit ddb2f3f
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 109 deletions.
3 changes: 1 addition & 2 deletions cb_maintenance/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Cb Maintenance",
"summary": """
CB maintenance base""",
"version": "14.0.3.0.0",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "CreuBlanca",
"website": "https://github.com/tegin/cb-maintenance",
Expand All @@ -17,7 +17,6 @@
"maintenance_equipment_image",
"maintenance_equipment_hierarchy",
"maintenance_location",
"maintenance_request_custom_info",
"maintenance_request_sequence",
"maintenance_request_stage_transition",
"maintenance_team_hierarchy",
Expand Down
10 changes: 0 additions & 10 deletions cb_maintenance/i18n/cb_maintenance.pot
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,6 @@ msgstr ""
msgid "Created on"
msgstr ""

#. module: cb_maintenance
#: model:ir.model.fields,field_description:cb_maintenance.field_maintenance_equipment_category__custom_info_template_id
msgid "Custom Info Template"
msgstr ""

#. module: cb_maintenance
#: model:ir.model.fields,field_description:cb_maintenance.field_maintenance_request__custom_info_template_id
msgid "Custom Information Template"
msgstr ""

#. module: cb_maintenance
#: model:ir.model.fields,help:cb_maintenance.field_maintenance_request__request_date
msgid "Date requested for the maintenance to happen"
Expand Down
10 changes: 0 additions & 10 deletions cb_maintenance/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,6 @@ msgstr "Creadas por mí"
msgid "Created on"
msgstr "Creado el"

#. module: cb_maintenance
#: model:ir.model.fields,field_description:cb_maintenance.field_maintenance_equipment_category__custom_info_template_id
msgid "Custom Info Template"
msgstr "Plantilla de inf. personalizada"

#. module: cb_maintenance
#: model:ir.model.fields,field_description:cb_maintenance.field_maintenance_request__custom_info_template_id
msgid "Custom Information Template"
msgstr "Plantilla de inf. personalizada"

#. module: cb_maintenance
#: model:ir.model.fields,help:cb_maintenance.field_maintenance_request__request_date
msgid "Date requested for the maintenance to happen"
Expand Down
21 changes: 2 additions & 19 deletions cb_maintenance/models/maintenance_equipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ class MaintenanceEquipment(models.Model):
_inherit = "maintenance.equipment"
_rec_name = "complete_name"
_order = "code desc"
_rec_names_search = ["complete_name", "code"]

complete_name = fields.Char(
"Complete Name", compute="_compute_complete_name", store=True
)
complete_name = fields.Char(compute="_compute_complete_name", store=True)
company_id = fields.Many2one("res.company", readonly=True)

partner_technician_id = fields.Many2one(
Expand Down Expand Up @@ -41,8 +40,6 @@ def _prepare_request_from_plan(self, maintenance_plan, next_maintenance_date):

def _create_new_request(self, maintenance_plan):
requests = super()._create_new_request(maintenance_plan)
for request in requests:
request._onchange_custom_info_template_id()
return requests

@api.depends("name", "code")
Expand All @@ -62,17 +59,3 @@ def create(self, mvals):
or "/"
)
return equipments

@api.model
def name_search(self, name="", args=None, operator="ilike", limit=100):
# Make a search with default criteria
names1 = super().name_search(
name=name, args=args, operator=operator, limit=limit
)
# Make the other search
names2 = []
if name:
domain = [("code", "=ilike", name + "%")]
names2 = self.search(domain, limit=limit).name_get()
# Merge both results
return list(set(names1) | set(names2))[:limit]
10 changes: 3 additions & 7 deletions cb_maintenance/models/maintenance_equipment_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@ class MaintenanceEquipmentCategory(models.Model):

maintenance_team_id = fields.Many2one("maintenance.team")
selectable = fields.Boolean(string="Selectable by users")
requires_equipment = fields.Boolean(string="Requires Equipment")
requires_location = fields.Boolean(string="Requires Location")
requires_equipment = fields.Boolean()
requires_location = fields.Boolean()

maintenance_team_id_member_ids = fields.Many2many(
"res.users",
relation="selectable_maintenance_members",
compute="_compute_maintenance_team_id_member_ids",
)
sequence = fields.Integer(string="Sequence", default=10)

custom_info_template_id = fields.Many2one(
"custom.info.template", domain=[("model", "=", "maintenance.request")]
)
sequence = fields.Integer(default=10)

@api.depends("maintenance_team_id")
def _compute_maintenance_team_id_member_ids(self):
Expand Down
3 changes: 0 additions & 3 deletions cb_maintenance/models/maintenance_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
class MaintenanceRequest(models.Model):
_inherit = "maintenance.request"

custom_info_template_id = fields.Many2one(
related="category_id.custom_info_template_id", store=True
)
company_id = fields.Many2one(default=False)
days_to_close = fields.Integer(store=True, compute="_compute_days_to_close")
hours_to_close = fields.Float(store=True, compute="_compute_hours_to_close")
Expand Down
31 changes: 2 additions & 29 deletions cb_maintenance/tests/test_cb_maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.exceptions import ValidationError
from odoo.tests.common import Form, SavepointCase
from odoo.tests.common import Form, TransactionCase


class TestCbMaintenance(SavepointCase):
class TestCbMaintenance(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down Expand Up @@ -186,30 +186,3 @@ def test_request_creation(self):
for r in request:
self.assertIn("Description", r.note)
self.assertFalse(r.description)

def test_custom_info(self):
model = self.env["ir.model"].search([("model", "=", "maintenance.request")])
template_id = self.env["custom.info.template"].create(
{
"name": "Template",
"model_id": model.id,
"property_ids": [(0, 0, {"name": "Prop 1"})],
}
)
self.categ_id.write({"custom_info_template_id": template_id.id})
maintenance_plan = self.env["maintenance.plan"].create(
{
"equipment_id": self.equipment_id.id,
"category_id": self.categ_id.id,
"interval": 1,
"interval_step": "month",
"maintenance_plan_horizon": 1,
"planning_step": "week",
}
)
requests = self.equipment_id.env["maintenance.equipment"]._create_new_request(
maintenance_plan
)
requests.custom_info_ids.invalidate_cache()
self.assertTrue(requests.custom_info_template_id)
self.assertTrue(requests.custom_info_ids)
1 change: 0 additions & 1 deletion cb_maintenance/views/maintenance_equipment_category.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<field name="selectable" />
<field name="requires_equipment" />
<field name="requires_location" />
<field name="custom_info_template_id" />
</field>
<group name="group_alias" position="attributes">
<attribute name="invisible">1</attribute>
Expand Down
24 changes: 5 additions & 19 deletions cb_maintenance/views/maintenance_request.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
<record model="ir.ui.view" id="hr_equipment_request_view_form">
<field name="name">maintenance.request.form (in cb_maintenance)</field>
<field name="model">maintenance.request</field>
<field
name="inherit_id"
ref="maintenance_request_custom_info.hr_equipment_request_view_form"
/>
<field name="inherit_id" ref="maintenance.hr_equipment_request_view_form" />
<field name="priority">99</field>
<field name="arch" type="xml">
<form position="attributes">
Expand Down Expand Up @@ -148,9 +145,6 @@
<field name="company_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="custom_info_template_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="owner_user_id" position="attributes">
<attribute name="invisible">0</attribute>
</field>
Expand Down Expand Up @@ -184,14 +178,11 @@
>maintenance.request.form (in cb_maintenance for manager)</field>
<field name="model">maintenance.request</field>
<field name="inherit_id" ref="hr_equipment_request_view_form" />
<field
name="groups_id"
eval="[(4, ref('maintenance.group_equipment_manager'))]"
/>
<field name="arch" type="xml">
<form position="attributes">
<attribute name="create">true</attribute>
<attribute name="edit">true</attribute>
<attribute name="groups">maintenance.group_equipment_manager</attribute>
</form>
</field>
</record>
Expand Down Expand Up @@ -233,13 +224,11 @@
>maintenance.request.tree (in cb_maintenance for manager)</field>
<field name="model">maintenance.request</field>
<field name="inherit_id" ref="maintenance_request_tree_view" />
<field
name="groups_id"
eval="[(4, ref('maintenance.group_equipment_manager'))]"
/>

<field name="arch" type="xml">
<tree position="attributes">
<attribute name="create">true</attribute>
<attribute name="groups">maintenance.group_equipment_manager</attribute>
</tree>
</field>
</record>
Expand Down Expand Up @@ -273,13 +262,10 @@
>maintenance.request.kanban (in cb_maintenance for manager)</field>
<field name="model">maintenance.request</field>
<field name="inherit_id" ref="maintenance_request_kanban_view" />
<field
name="groups_id"
eval="[(4, ref('maintenance.group_equipment_manager'))]"
/>
<field name="arch" type="xml">
<kanban position="attributes">
<attribute name="create">true</attribute>
<attribute name="groups">maintenance.group_equipment_manager</attribute>
</kanban>
</field>
</record>
Expand Down
2 changes: 0 additions & 2 deletions cb_maintenance/wizards/wizard_create_maintenance_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class WizardCreateMaintenanceRequest(models.TransientModel):

priority = fields.Selection(
[("0", "Normal"), ("1", "Low"), ("2", "High"), ("3", "Very High")],
string="Priority",
default="0",
)
equipment_category = fields.Many2one(
Expand Down Expand Up @@ -62,7 +61,6 @@ def create_request_vals(self):
def create_request(self):
self.ensure_one()
request = self.env["maintenance.request"].create(self.create_request_vals())
request._onchange_custom_info_template_id()
original_request = self.env.context.get("original_request", False)
if original_request:
original_request = self.env["maintenance.request"].browse(original_request)
Expand Down
13 changes: 6 additions & 7 deletions cb_maintenance/wizards/wizard_mass_change_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ def set_stage(self):
if request.stage_id not in self.stage_id.previous_stage_ids:
raise ValidationError(
_(
"Stage of request %s is not valid."
" Transition from %s to %s is not allowed"
)
% (
request.display_name,
request.stage_id.name,
self.stage_id.name,
"Stage of request %(request_display_name)s is not valid."
" Transition from %(request_stage_name)s to"
" %(stage_name)s is not allowed",
request_display_name=request.display_name,
request_stage_name=request.stage_id.name,
stage_name=self.stage_id.name,
)
)
return requests.with_context(
Expand Down

0 comments on commit ddb2f3f

Please sign in to comment.