Skip to content

Commit

Permalink
Merge PR #414 into 17.0
Browse files Browse the repository at this point in the history
Signed-off-by etobella
  • Loading branch information
OCA-git-bot committed Aug 8, 2024
2 parents eaa039c + 9f99863 commit aec528a
Show file tree
Hide file tree
Showing 34 changed files with 5,476 additions and 0 deletions.
138 changes: 138 additions & 0 deletions maintenance_plan/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
================
Maintenance Plan
================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:51d1395956daf1de19f24abe40f89528841450822d90006b04a75e26f1913828
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmaintenance-lightgray.png?logo=github
:target: https://github.com/OCA/maintenance/tree/17.0/maintenance_plan
:alt: OCA/maintenance
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/maintenance-17-0/maintenance-17-0-maintenance_plan
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/maintenance&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the functionality of Odoo Maintenance module by
allowing an equipment to have different preventive maintenance kinds.

**Table of contents**

.. contents::
:local:

Installation
============

Install the module.

Should you already use the maintenance module and have equipments with
field 'Preventive Maintenance Frequency' defined, a new maintenance plan
will be automatically created on these equipments with maintenance kind
'Install'.

Moreover if a Request of type 'preventive' exists, whose stage isn't
marked as 'Request done', and has a Request Date matching the
equipment's 'Next Preventive Maintenance', the request will be updated
with the 'Install' maintenance kind.

Make sure you don't have multiple 'preventive' requests at a stage which
isn't marked as 'Request done' and on the same 'Request date' as the
equipment or the module installation will fail with a User Error.

Usage
=====

Instead of defining a period and duration for only one preventive
maintenance per equipment, you can define multiple preventive
maintenance kind for each equipment.

Maintenance Kinds have to be defined through the configuration menu.
Their name have to be unique and can be set as active or inactive,
should these not be used anymore.

On any equipment over the maintenance tab, the maintenance plan be
accessible, allowing to add different maintenance kind with their own
frequency and duration. The next maintenance date will then be computed
automatically according to the start's date and the frequency defined,
but the maintenance request won't be created automatically as is the
case in Odoo's Maintenance module. In the plan there's also a field
allowing the user to set the maintenance horizon, insert the
instructions to follow on the maintenance that will be forwarded to the
maintenance request generated from the plan.

This module uses the original Cron job of Odoo's Maintenance module to
generate maintenance requests. To do so, it takes into account the
planning horizon and generates all maintenance requests whose schedule
date would fall inside that planning horizon. Therefore, the maintenance
manager can have a proper planning of how many maintenance requests are
programming for the future. Leaving planning horizon to 0 will only
create those maintenance request that are scheduled for today.

We can also create maintenance requests from a plan using a domain for
selecting the equipments. This way, we might have a single plan that
will generate all the requests. In order to use it, we need to mark the
Generate with Domain field.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/maintenance/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/maintenance/issues/new?body=module:%20maintenance_plan%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Camptocamp SA
* ForgeFlow

Contributors
------------

- Akim Juillerat <akim.juillerat@camptocamp.com>
- Matteo Mazzoni <matteo@appcademy.tech>
- David Alonso <david.alonso@solvos.es>
- Adrià Gil Sorribes <adria.gil@forgeflow.com>
- Jordi Ballester Alomar <jordi.ballester@forgeflow.com>
- Lois Rilo <lois.rilo@forgeflow.com>
- Enric Tobella <enric.tobella@dixmit.com>
- Alexei Rivera <arivera@archeti.com>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/maintenance <https://github.com/OCA/maintenance/tree/17.0/maintenance_plan>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions maintenance_plan/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import post_init_hook
26 changes: 26 additions & 0 deletions maintenance_plan/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Maintenance Plan",
"summary": "Extends preventive maintenance planning",
"version": "17.0.1.0.0",
"author": "Camptocamp SA, ForgeFlow, Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Maintenance",
"website": "https://github.com/OCA/maintenance",
"images": [],
"depends": ["base_maintenance"],
"data": [
"security/ir.model.access.csv",
"security/maintenance_security.xml",
"data/ir_cron.xml",
"views/maintenance_kind_views.xml",
"views/maintenance_plan_views.xml",
"views/maintenance_equipment_views.xml",
"views/report_maintenance_request.xml",
],
"external_dependencies": {"python": ["python-dateutil"]},
"demo": ["demo/demo_maintenance_plan.xml"],
"post_init_hook": "post_init_hook",
"installable": True,
}
13 changes: 13 additions & 0 deletions maintenance_plan/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding='UTF-8' ?>
<odoo>
<record id="maintenance_requests_cron" model="ir.cron">
<field name="name">Maintenance: generate preventive maintenance requests</field>
<field name="model_id" ref="model_maintenance_equipment" />
<field name="state">code</field>
<field name="code">model._cron_generate_requests()</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
</record>
</odoo>
57 changes: 57 additions & 0 deletions maintenance_plan/demo/demo_maintenance_plan.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<!-- Maintenance kinds -->
<record id="maintenance_kind_monthly" model="maintenance.kind">
<field name="name">Monthly</field>
<field name="active" eval="True" />
</record>
<record id="maintenance_kind_weekly" model="maintenance.kind">
<field name="name">Weekly</field>
<field name="active" eval="True" />
</record>
<!-- Maintenance plans -->
<record id="maintenance_plan_monthly_monitor1" model="maintenance.plan">
<field name="equipment_id" ref="maintenance.equipment_monitor1" />
<field name="maintenance_kind_id" ref="maintenance_kind_monthly" />
<field name="interval">1</field>
<field name="interval_step">month</field>
<field name="duration">2</field>
<field name="maintenance_plan_horizon">2</field>
<field name="planning_step">month</field>
</record>
<record id="maintenance_plan_monthly_monitor4" model="maintenance.plan">
<field name="equipment_id" ref="maintenance.equipment_monitor4" />
<field name="maintenance_kind_id" ref="maintenance_kind_monthly" />
<field name="interval">1</field>
<field name="interval_step">month</field>
<field name="duration">2</field>
<field name="maintenance_plan_horizon">2</field>
<field name="planning_step">month</field>
</record>
<record id="maintenance_plan_monthly_monitor6" model="maintenance.plan">
<field name="equipment_id" ref="maintenance.equipment_monitor6" />
<field name="maintenance_kind_id" ref="maintenance_kind_monthly" />
<field name="interval">1</field>
<field name="interval_step">month</field>
<field name="duration">2</field>
<field name="maintenance_plan_horizon">1</field>
<field name="planning_step">month</field>
</record>
<record id="maintenance_plan_monthly_printer1" model="maintenance.plan">
<field name="equipment_id" ref="maintenance.equipment_printer1" />
<field name="maintenance_kind_id" ref="maintenance_kind_monthly" />
<field name="interval">1</field>
<field name="interval_step">month</field>
<field name="duration">4</field>
<field name="maintenance_plan_horizon">3</field>
<field name="planning_step">month</field>
</record>
<record id="maintenance_plan_weekly_printer1" model="maintenance.plan">
<field name="equipment_id" ref="maintenance.equipment_printer1" />
<field name="maintenance_kind_id" ref="maintenance_kind_weekly" />
<field name="interval">7</field>
<field name="duration">2</field>
<field name="maintenance_plan_horizon">1</field>
<field name="planning_step">month</field>
</record>
</odoo>
48 changes: 48 additions & 0 deletions maintenance_plan/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging

from odoo import _
from odoo.exceptions import UserError


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

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

if equipments:
maintenance_kind = env["maintenance.kind"].create(
{"name": "Install", "active": True}
)

for equipment in equipments:
request = equipment.maintenance_ids.filtered(
lambda r, equipment=equipment: r.maintenance_type == "preventive"
and not r.stage_id.done
and r.request_date == equipment.next_action_date
)
if len(request) > 1:
raise UserError(
_(
"You have multiple preventive maintenance requests on "
"equipment %(name)s next action date (%(date)s). "
"Please leave only one preventive request on the "
"date of equipment's next action to install the module.",
name=equipment.name,
date=equipment.next_action_date,
)
)
elif len(request) == 1:
request.write({"maintenance_kind_id": maintenance_kind.id})
env["maintenance.plan"].create(
{
"equipment_id": equipment.id,
"maintenance_kind_id": maintenance_kind.id,
"duration": equipment.mtbf,
"interval": equipment.expected_mtbf,
}
)
Loading

0 comments on commit aec528a

Please sign in to comment.