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

[12.0] [MIG] maintenance_plan #15

Merged
merged 6 commits into from
Jul 19, 2019
Merged
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
117 changes: 117 additions & 0 deletions maintenance_plan/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
================
Maintenance Plan
================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/12.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-12-0/maintenance-12-0-maintenance_plan
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/240/12.0
:alt: Try me on Runbot

|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 will appear
as an embedded list view, allowing to add different maintenance kind with their
own period and duration. The next maintenance date will then be computed
automatically according to today's date and the period defined, but the
maintenance request won't be created automatically as is the case in Odoo's
Maintenance module.

Instead, this module uses the original Cron job of Odoo's Maintenance module
to generate maintenance requests, should there not be any requests which is not
done, at the request date matching the maintenance plan next_maintenance_date
for this equipment and this maintenance kind !

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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/maintenance/issues/new?body=module:%20maintenance_plan%0Aversion:%2012.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

Contributors
~~~~~~~~~~~~

* Akim Juillerat <akim.juillerat@camptocamp.com>
* Matteo Mazzoni <matteo@appcademy.tech>
* David Alonso <david.alonso@solvos.es>

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/12.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
23 changes: 23 additions & 0 deletions maintenance_plan/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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': '12.0.1.0.0',
'author': 'Odoo Community Association (OCA), Camptocamp SA',
'license': 'AGPL-3',
'category': 'Maintenance',
'website': 'https://github.com/OCA/maintenance',
'images': [],
'depends': [
'maintenance',
],
'data': [
'security/ir.model.access.csv',
'views/maintenance.xml'
],
'demo': [
'data/demo_maintenance_plan.xml'
],
'post_init_hook': 'post_init_hook',
'installable': True,
}
51 changes: 51 additions & 0 deletions maintenance_plan/data/demo_maintenance_plan.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data 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="period">30</field>
<field name="duration">2</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="period">30</field>
<field name="duration">2</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="period">30</field>
<field name="duration">2</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="period">30</field>
<field name="duration">4</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="period">7</field>
<field name="duration">1</field>
</record>

</data>
</odoo>
46 changes: 46 additions & 0 deletions maintenance_plan/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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


def post_init_hook(cr, registry):

logging.getLogger('odoo.addons.maintenance_plan').info(
'Migrating existing preventive maintenance')

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

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

if equipments:

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

for equipment in equipments:
request = equipment.maintenance_ids.filtered(
lambda r: 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 %s next action date (%s). Please leave only "
"one preventive request on the date of equipment's next "
"action to install the module."
) % (equipment.name, 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.maintenance_duration,
'period': equipment.period
})
1 change: 1 addition & 0 deletions maintenance_plan/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import maintenance
Loading