Skip to content

Commit

Permalink
Merge pull request #51 from YuriyGural/16.0
Browse files Browse the repository at this point in the history
[16.0][UPDATE] itm
  • Loading branch information
mtelahun authored Jun 21, 2024
2 parents 5da9704 + fb4f44b commit 85f3d38
Show file tree
Hide file tree
Showing 26 changed files with 748 additions and 205 deletions.
50 changes: 50 additions & 0 deletions hr_itm/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
=================================
IT Infrastructure Management - HR
=================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file was generated by gen-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-trevi--software%2Ftrevi--misc-lightgray.png?logo=github
:target: https://github.com/trevi-software/trevi-misc/tree/16.0/hr_itm
:alt: trevi-software/trevi-misc

|badge1| |badge2| |badge3|

This module allows to assign employee and/or department as the owner of the equipment.
It is convenient to filter and group equipment by employees/departments.
A module is based on a similar module hr_maintenance.

**Table of contents**

.. contents::
:local:

Creditos
========

Authors
~~~~~~~

* TREVI Software
* Yuriy Gural

Other credits
~~~~~~~~~~~~~

* Yuriy Gural <[email protected]>

Maintainers
~~~~~~~~~~~

This module is part of the `trevi-software/trevi-misc <https://github.com/trevi-software/trevi-misc/tree/16.0/hr_itm>`_ project on GitHub.

You are welcome to contribute.
3 changes: 3 additions & 0 deletions hr_itm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
20 changes: 20 additions & 0 deletions hr_itm/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (C) 2024 Yuriy Gural <[email protected]>
# Based on the hr_maintenance module
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "IT Infrastructure Management - HR",
"version": "16.0.1.0.1",
"category": "Human Resources",
"summary": "Bridge between HR and IT Infrastructure Management",
"author": """TREVI Software,
Yuriy Gural""",
"license": "AGPL-3",
"depends": ["hr", "itm"],
"data": [
"views/equipment_views.xml",
],
"installable": True,
"application": False,
"auto_install": False,
}
3 changes: 3 additions & 0 deletions hr_itm/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import equipment
61 changes: 61 additions & 0 deletions hr_itm/models/equipment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright (C) 2024 Yuriy Gural <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class ItEquipment(models.Model):
_inherit = "itm.equipment"

employee_id = fields.Many2one(
"hr.employee",
compute="_compute_equipment_assign",
store=True,
readonly=False,
string="Assigned Employee",
tracking=True,
)
department_id = fields.Many2one(
"hr.department",
compute="_compute_equipment_assign",
store=True,
readonly=False,
string="Assigned Department",
tracking=True,
)
equipment_assign_to = fields.Selection(
[("department", "Department"), ("employee", "Employee"), ("other", "Other")],
string="Used By",
required=True,
default="employee",
)
owner = fields.Char(compute="_compute_owner", store=True)
assign_date = fields.Date(
compute="_compute_equipment_assign",
tracking=True,
store=True,
readonly=False,
copy=True,
)

@api.depends("employee_id", "department_id", "equipment_assign_to")
def _compute_owner(self):
for equipment in self:
if equipment.equipment_assign_to == "employee":
equipment.owner = equipment.employee_id.name
elif equipment.equipment_assign_to == "department":
equipment.owner = equipment.department_id.manager_id.name

@api.depends("equipment_assign_to")
def _compute_equipment_assign(self):
for equipment in self:
if equipment.equipment_assign_to == "employee":
equipment.department_id = False
equipment.employee_id = equipment.employee_id
elif equipment.equipment_assign_to == "department":
equipment.employee_id = False
equipment.department_id = equipment.department_id
else:
equipment.department_id = equipment.department_id
equipment.employee_id = equipment.employee_id
equipment.assign_date = fields.Date.context_today(self)
4 changes: 4 additions & 0 deletions hr_itm/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2024 Yuriy Gural <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_equipment
57 changes: 57 additions & 0 deletions hr_itm/tests/test_equipment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (C) 2024 Yuriy Gural <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields
from odoo.tests.common import TransactionCase


class TestEquipment(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()

cls.partner = cls.env["res.partner"].create(
{
"name": "Partner X",
"email": "[email protected]",
}
)
cls.site = cls.env["itm.site"].create(
{
"name": "Site X",
}
)
cls.employee = cls.env["hr.employee"].create(
{
"name": "Employee X",
}
)
cls.department = cls.env["hr.department"].create(
{
"name": "Department X",
}
)

def test_equipment_assign_to(self):

equipment = self.env["itm.equipment"].create(
{
"name": "My Equipment",
"partner_id": self.partner.id,
"site_id": self.site.id,
}
)

equipment.equipment_assign_to = "department"
equipment.department_id = self.department
today = fields.Date.today()
self.assertFalse(equipment.employee_id)
self.assertEqual(equipment.assign_date, today, "Assign date should be today")

equipment.equipment_assign_to = "other"
equipment.employee_id = self.employee
self.assertEqual(
equipment.department_id,
self.department,
"Equipment should be assigned to both the employee and the department",
)
110 changes: 110 additions & 0 deletions hr_itm/views/equipment_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="itm_equipment_search_hr" model='ir.ui.view'>
<field name="name">itm.equipment.search.hr</field>
<field name="model">itm.equipment</field>
<field name="inherit_id" ref="itm.itm_equipment_search" />
<field name="arch" type="xml">
<field name="partner_id" position="before">
<field name="employee_id" />
<field name="department_id" />
</field>
<xpath expr="//filter[@name='is_backup']" position="before">
<filter
string="Assigned"
name="assigned"
domain="['|', ('employee_id', '!=', False), ('department_id', '!=', False)]"
/>
<filter
string="Unassigned"
name="available"
domain="[('employee_id', '=', False), ('department_id', '=', False)]"
/>
<separator />
</xpath>
<group position="inside">
<filter
string="Employee"
name="by_employee"
domain="[]"
context="{'group_by': 'employee_id'}"
/>
<filter
string="Department"
name="by_department"
domain="[]"
context="{'group_by': 'department_id'}"
/>
</group>
</field>
</record>

<record id="itm_equipment_form_hr" model="ir.ui.view">
<field name="name">itm.equipment.form.hr</field>
<field name="model">itm.equipment</field>
<field name="inherit_id" ref="itm.itm_equipment_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='owner']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//field[@name='owner']" position="after">
<field name="equipment_assign_to" widget="radio" />
<field
name="employee_id"
string="Employee"
attrs="{'invisible': ['|', ('equipment_assign_to', '=', 'department'), ('equipment_assign_to', '=', False)]}"
/>
<field
name="department_id"
string="Department"
attrs="{'invisible': ['|', ('equipment_assign_to', '=', 'employee'), ('equipment_assign_to', '=', False)]}"
/>
</xpath>
</field>
</record>

<record id="itm_equipment_kanban_hr" model="ir.ui.view">
<field name="name">itm.equipment.kanban.hr</field>
<field name="model">itm.equipment</field>
<field name="inherit_id" ref="itm.itm_equipment_kanban" />
<field name="arch" type="xml">
<xpath expr="//field[@name='owner']" position="after">
<field name="employee_id" />
<field name="department_id" />
</xpath>
<xpath expr="//templates//field[@name='owner']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//templates//field[@name='owner']/.." position="after">
<div
t-if="!record.employee_id.raw_value and !record.department_id.value"
>
Unassigned
</div>
<div t-if="record.employee_id.value">
<field name="employee_id" widget="many2one_avatar_employee" />
<t t-esc="record.employee_id.value" />
</div>
<div t-if="record.department_id.value">
<field name="department_id" />
</div>
</xpath>
</field>
</record>

<record id="itm_equipment_tree_hr" model="ir.ui.view">
<field name="name">itm.equipment.tree.hr</field>
<field name="model">itm.equipment</field>
<field name="inherit_id" ref="itm.itm_equipment_tree" />
<field name="arch" type="xml">
<xpath expr="//field[@name='owner']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//field[@name='owner']" position="after">
<field name="employee_id" string="Employee" optional="show" />
<field name="department_id" string="Department" optional="show" />
</xpath>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions itm/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Other credits

* Leandro Ezequiel Baldi <[email protected]>
* Altela Eleviansyah Pramardhika <[email protected]>
* Yuriy Gural <[email protected]>

Maintainers
~~~~~~~~~~~
Expand Down
5 changes: 3 additions & 2 deletions itm/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

{
"name": "IT Infrastructure Management",
"version": "16.0.2.0.2",
"version": "16.0.2.0.3",
"license": "AGPL-3",
"category": "IT Infrastructure Management",
"summary": """IT Assets, Credentials, Backups, Applications.""",
"author": """TREVI Software,
Leandro Ezequiel Baldi""",
Leandro Ezequiel Baldi,
Yuriy Gural""",
"website": "https://github.com/trevi-software/trevi-misc",
"images": [
"static/src/img/main_screenshot.png",
Expand Down
12 changes: 12 additions & 0 deletions itm/migrations/16.0.2.0.3/pre-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (C) 2024 Yuriy Gural <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging

_logger = logging.getLogger(__name__)


def migrate(cr, version):
if version == "16.0.2.0.2":
cr.execute("UPDATE itm_equipment SET brand_id = brand WHERE brand_id IS NULL")
_logger.info("Updated %s itm_equipment", cr.rowcount)
Loading

0 comments on commit 85f3d38

Please sign in to comment.