Skip to content

Commit

Permalink
[MIG] maintenance_plan: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FernandoRomera committed Jul 24, 2024
1 parent dea209f commit ae17a34
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 43 deletions.
6 changes: 3 additions & 3 deletions maintenance_plan/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Maintenance Plan",
"summary": "Extends preventive maintenance planning",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"author": "Camptocamp SA, ForgeFlow, Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Maintenance",
Expand All @@ -18,8 +18,8 @@
"views/maintenance_equipment_views.xml",
"views/report_maintenance_request.xml",
],
"external_dependencies": {"python": ["dateutil"]},
"demo": ["data/demo_maintenance_plan.xml"],
"external_dependencies": {"python": ["python-dateutil"]},
"demo": ["demo/demo_maintenance_plan.xml"],
"post_init_hook": "post_init_hook",
"installable": True,
}
14 changes: 6 additions & 8 deletions maintenance_plan/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@

import logging

from odoo import SUPERUSER_ID, _, api
from odoo import _
from odoo.exceptions import UserError


def post_init_hook(cr, registry):
def post_init_hook(env):
logging.getLogger("odoo.addons.maintenance_plan").info(
"Migrating existing preventive maintenance"
)

env = api.Environment(cr, SUPERUSER_ID, {})

equipments = env["maintenance.equipment"].search([("period", "!=", False)])
equipments = env["maintenance.equipment"].search([("expected_mtbf", "!=", False)])

if equipments:
maintenance_kind = env["maintenance.kind"].create(
Expand All @@ -23,7 +21,7 @@ def post_init_hook(cr, registry):

for equipment in equipments:
request = equipment.maintenance_ids.filtered(
lambda r: r.maintenance_type == "preventive"
lambda r, equipment=equipment: r.maintenance_type == "preventive"
and not r.stage_id.done
and r.request_date == equipment.next_action_date
)
Expand All @@ -44,7 +42,7 @@ def post_init_hook(cr, registry):
{
"equipment_id": equipment.id,
"maintenance_kind_id": maintenance_kind.id,
"duration": equipment.maintenance_duration,
"interval": equipment.period,
"duration": equipment.mtbf,
"interval": equipment.expected_mtbf,
}
)
2 changes: 1 addition & 1 deletion maintenance_plan/models/maintenance_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def unlink(self):
requests of this kind which are not done for its equipment"""
for plan in self:
request = plan.equipment_id.mapped("maintenance_ids").filtered(
lambda r: (
lambda r, plan=plan: (
r.maintenance_kind_id == plan.maintenance_kind_id
and not r.stage_id.done
and r.maintenance_type == "preventive"
Expand Down
4 changes: 1 addition & 3 deletions maintenance_plan/security/maintenance_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
<field name="name">Maintenance plan multi-company</field>
<field name="model_id" ref="model_maintenance_plan" />
<field name="global" eval="True" />
<field
name="domain_force"
>['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
<field name="domain_force">[('company_id', 'in', company_ids + [False])]</field>
</record>
<record id="maintenance_plan_rule_user" model="ir.rule">
<field
Expand Down
11 changes: 2 additions & 9 deletions maintenance_plan/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import odoo.tests.common as test_common

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT


class TestMaintenancePlanBase(test_common.TransactionCase):
@classmethod
Expand All @@ -13,15 +15,6 @@ def setUpClass(cls):
freezer = freeze_time("2023-01-25 15:30:00")
freezer.__enter__()
cls.addClassCleanup(freezer.__exit__)
# Remove this variable in v16 and put instead:
# from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
DISABLED_MAIL_CONTEXT = {
"tracking_disable": True,
"mail_create_nolog": True,
"mail_create_nosubscribe": True,
"mail_notrack": True,
"no_reset_password": True,
}
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.maintenance_request_obj = cls.env["maintenance.request"]
cls.maintenance_plan_obj = cls.env["maintenance.plan"]
Expand Down
14 changes: 6 additions & 8 deletions maintenance_plan/views/maintenance_equipment_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
/>
</button>
</div>
<xpath expr="//group[@name='maintenance']" position="attributes">
<attribute name="attrs">{'invisible': 1}</attribute>
<xpath expr="//group[@name='statistics']" position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
<xpath expr="//group[@name='maintenance']/.." position="after">
<xpath expr="//group[@name='statistics']/.." position="after">
<field
name="maintenance_plan_ids"
nolabel="1"
context="{'default_equipment_id': active_id, 'hide_equipment_id': 1}"
context="{'default_equipment_id': id, 'hide_equipment_id': 1}"
>
<tree>
<field name="maintenance_kind_id" string="Kind" />
Expand All @@ -47,12 +47,10 @@
</field>
</xpath>
<field name="maintenance_team_id" position="after">
<field name="maintenance_team_required" attrs="{'invisible': 1}" />
<field name="maintenance_team_required" invisible="True" />
</field>
<field name="maintenance_team_id" position="attributes">
<attribute
name="attrs"
>{'required': [('maintenance_team_required', '=', True)]}</attribute>
<attribute name="required">maintenance_team_required</attribute>
</field>
</field>
</record>
Expand Down
22 changes: 11 additions & 11 deletions maintenance_plan/views/maintenance_plan_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<field name="binding_model_id" ref="model_maintenance_plan" />
<field name="view_mode">kanban,tree,form,pivot,graph,calendar</field>
<field name="context">{
'default_maintenance_plan_id': active_id,
'default_maintenance_plan_id': id,
}</field>
<field name="domain">[('maintenance_plan_id', '=', active_id)]</field>
<field name="domain">[('maintenance_plan_id', '=', id)]</field>
</record>
<record id="maintenance_plan_view_form" model="ir.ui.view">
<field name="name">maintenance.plan.form</field>
Expand All @@ -21,17 +21,17 @@
string="Generate requests for current threshold"
help="If not clicked, the scheduled action will do it for you."
type="object"
attrs="{'invisible' : ['|', ('id', '=', False),('interval', '=', 0)]}"
invisible="not id or interval == 0"
/>
</header>
<sheet>
<widget
name="web_ribbon"
title="Archived"
bg_color="bg-danger"
attrs="{'invisible': [('active', '=', True)]}"
invisible="active"
/>
<field name="active" attrs="{'invisible': 1}" />
<field name="active" invisible="True" />
<div class="oe_button_box" name="button_box">
<button
name="%(hr_equipment_request_action_from_plan)d"
Expand All @@ -52,7 +52,7 @@
<field
name="name"
placeholder="e.g. Calibration"
attrs="{'required': [('equipment_id', '=', False)]}"
required="not equipment_id"
/>
</h1>
</div>
Expand All @@ -65,17 +65,17 @@
<field name="maintenance_kind_id" />
<field
name="maintenance_team_id"
attrs="{'required': [('equipment_id', '=', False)]}"
required="not equipment_id"
/>
<field
name="generate_with_domain"
attrs="{'invisible': [('equipment_id', '!=', False)]}"
invisible="equipment_id"
/>
<field
name="generate_domain"
widget="domain"
options="{'model': 'maintenance.equipment', 'in_dialog': True}"
attrs="{'invisible': ['|', ('equipment_id', '!=', False), ('generate_with_domain', '=', False)]}"
invisible="equipment_id or not generate_with_domain"
/>
</group>
<group>
Expand Down Expand Up @@ -188,10 +188,10 @@
<field name="view_mode">tree,form</field>
<field name="view_id" ref="maintenance_plan_view_tree" />
<field name="context">{
'default_equipment_id': active_id, 'hide_equipment_id': 0
'default_equipment_id': id, 'hide_equipment_id': 0
}</field>
<field name="domain">['|', ('active', '=', True), ('active', '=',
False), ('search_equipment_id', '=', active_id)]
False), ('search_equipment_id', '=', id)]
</field>
</record>
<menuitem
Expand Down

0 comments on commit ae17a34

Please sign in to comment.