Skip to content

Commit

Permalink
add maintenance_equipment_hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiBForgeFlow authored and FrancoMaxime committed Oct 10, 2022
1 parent e41d7da commit 30bcaa3
Show file tree
Hide file tree
Showing 13 changed files with 710 additions and 0 deletions.
75 changes: 75 additions & 0 deletions maintenance_equipment_hierarchy/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
================================
Maintenance Equipments Hierarchy
================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmaintenance-lightgray.png?logo=github
:target: https://github.com/OCA/maintenance/tree/11.0/maintenance_equipment_hierarchy
:alt: OCA/maintenance
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/maintenance-11-0/maintenance-11-0-maintenance_equipment_hierarchy
: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/11.0
:alt: Try me on Runbot

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

This module allows to manage a hierarchy of equipments.

**Table of contents**

.. contents::
:local:

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_equipment_hierarchy%0Aversion:%2011.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
~~~~~~~

* Eficent

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

* Adrià Gil Sorribes <[email protected]>
* Jordi Ballester Alomar <[email protected]>
* David Alonso <[email protected]>

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/11.0/maintenance_equipment_hierarchy>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions maintenance_equipment_hierarchy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions maintenance_equipment_hierarchy/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
'name': 'Maintenance Equipments Hierarchy',
'summary': 'Manage equipment hierarchy',
'author': 'Eficent, Odoo Community Association (OCA)',
'website': 'http://github.com/OCA/maintenance',
'category': 'Equipments, Assets, Internal Hardware, Allocation Tracking',
'version': '11.0.1.0.0',
'license': 'LGPL-3',
'depends': [
'maintenance',
],
'data': [
'views/maintenance_equipment_views.xml',
],
'demo': [
'data/demo_maintenance_equipment_hierarchy.xml'
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">

<record id="equipment_computer9_1" model="maintenance.equipment">
<field name="name">HP Laptop battery</field>
<field name="category_id" ref="maintenance.equipment_computer"/>
<field name="owner_user_id" ref="base.user_root"/>
<field name="technician_user_id" ref="base.user_demo"/>
<field name="assign_date" eval="time.strftime('%Y-%m-11')"/>
<field name="serial_no">LP/303/28292090/BAT</field>
<field name="model">17-j059nr-bat</field>
<field name="parent_id" ref="maintenance.equipment_computer9"/>
</record>

<record id="equipment_computer9_2" model="maintenance.equipment">
<field name="name">HP Laptop case</field>
<field name="category_id" ref="maintenance.equipment_computer"/>
<field name="owner_user_id" ref="base.user_root"/>
<field name="technician_user_id" ref="base.user_demo"/>
<field name="assign_date" eval="time.strftime('%Y-%m-11')"/>
<field name="serial_no">LP/303/28292090/CAS</field>
<field name="model">17-j059nr-cas</field>
<field name="parent_id" ref="maintenance.equipment_computer9"/>
</record>

</data>
</odoo>
1 change: 1 addition & 0 deletions maintenance_equipment_hierarchy/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import maintenance_equipment
68 changes: 68 additions & 0 deletions maintenance_equipment_hierarchy/models/maintenance_equipment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import api, fields, models, _
from odoo.exceptions import ValidationError


class MaintenanceEquipment(models.Model):

_inherit = 'maintenance.equipment'
_parent_name = "parent_id"
_parent_store = True
_parent_order = 'name'

parent_id = fields.Many2one('maintenance.equipment', 'Parent Equipment',
index=True, ondelete='cascade')
child_ids = fields.One2many('maintenance.equipment', 'parent_id',
'Child Equipments')
parent_left = fields.Integer('Left Parent', index=1)
parent_right = fields.Integer('Right Parent', index=1)
child_count = fields.Integer(
compute='_compute_child_count',
string="Number of child equipments")
display_name = fields.Char(compute='_compute_display_name')
complete_name = fields.Char(compute='_compute_complete_name', store=True)

def name_get(self):
return [(equipment.id, equipment.complete_name) for equipment in self]

@api.depends('child_ids')
def _compute_child_count(self):
for equipment in self:
equipment.child_count = len(equipment.child_ids)

def _compute_display_name(self):
for equipment in self:
equipment.display_name = equipment.complete_name

@api.depends('name', 'parent_id.complete_name') # recursive definition
def _compute_complete_name(self):
for equipment in self:
if equipment.parent_id:
parent_name = equipment.parent_id.complete_name
equipment.complete_name = parent_name + ' / ' + equipment.name
else:
equipment.complete_name = equipment.name

@api.constrains('parent_id')
def _check_equipment_recursion(self):
if not self._check_recursion():
raise ValidationError(
_('Error ! You cannot create a recursive '
'equipment hierarchy.'))
return True

def preview_child_list(self):
return {
'name': 'Child equipment of %s' % self.name,
'type': 'ir.actions.act_window',
'res_model': 'maintenance.equipment',
'res_id': self.id,
'view_mode': 'list,form',
'context': {
**self.env.context,
'default_parent_id': self.id,
'parent_id_editable': False},
'domain': [('id', 'in', self.child_ids.ids)],
}
3 changes: 3 additions & 0 deletions maintenance_equipment_hierarchy/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Adrià Gil Sorribes <[email protected]>
* Jordi Ballester Alomar <[email protected]>
* David Alonso <[email protected]>
1 change: 1 addition & 0 deletions maintenance_equipment_hierarchy/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows to manage a hierarchy of equipments.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 30bcaa3

Please sign in to comment.