[ADD] maintenance_equipment_customer: add customer contact link
Store the company contact owning the equipment as a single many2one field, restricted to company partners. Expose linked equipment and installed services on the contact form and filters, so contacts can be searched by service and version.
This commit is contained in:
78
maintenance_equipment_customer/README.md
Normal file
78
maintenance_equipment_customer/README.md
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
# =================================== maintenance_equipment_customer
|
||||||
|
|
||||||
|
This module links maintenance equipment to the company contact that owns it. It also
|
||||||
|
exposes the equipment's installed services on the contact, so contacts can be filtered
|
||||||
|
by service and service version.
|
||||||
|
|
||||||
|
A single company contact is allowed per equipment. Individual contacts are rejected
|
||||||
|
because an equipment belongs to a structure, not to a person attached to that structure.
|
||||||
|
|
||||||
|
Features:
|
||||||
|
|
||||||
|
- **Customer contact on equipment**: a **Customer Contact** field is available under the
|
||||||
|
equipment name and is restricted to company contacts.
|
||||||
|
- **Equipment on contacts**: a stat button on the contact form opens the equipment
|
||||||
|
linked to that contact.
|
||||||
|
- **Service-based contact filtering**: contacts can be filtered by maintenance service
|
||||||
|
and service version (e.g. contacts having an Odoo 14 instance).
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
|
||||||
|
Use Odoo normal module installation procedure to install
|
||||||
|
`maintenance_equipment_customer`.
|
||||||
|
|
||||||
|
This module depends on:
|
||||||
|
|
||||||
|
- `maintenance`
|
||||||
|
- `maintenance_server_data`
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
|
||||||
|
No specific configuration is required. After installation, the new fields are available
|
||||||
|
on the maintenance equipment and contact forms.
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
|
## Linking equipment to a customer
|
||||||
|
|
||||||
|
1. Go to **Maintenance > Equipments**.
|
||||||
|
2. Open an equipment record.
|
||||||
|
3. Fill in the **Customer Contact** field under the equipment name.
|
||||||
|
4. Only company contacts can be selected.
|
||||||
|
|
||||||
|
## Viewing equipment from a contact
|
||||||
|
|
||||||
|
1. Go to **Contacts**.
|
||||||
|
2. Open a company contact.
|
||||||
|
3. Click the **Equipment** stat button to see its maintenance equipment.
|
||||||
|
|
||||||
|
## Filtering contacts by service
|
||||||
|
|
||||||
|
1. Go to **Contacts**.
|
||||||
|
2. In the search bar, select **Maintenance Service** and/or **Maintenance Service
|
||||||
|
Version**.
|
||||||
|
3. For example, select service **Odoo** and version **14.0** to find contacts with an
|
||||||
|
Odoo 14 instance.
|
||||||
|
|
||||||
|
# Bug Tracker
|
||||||
|
|
||||||
|
Bugs are tracked on
|
||||||
|
[our issues website](https://github.com/elabore-coop/maintenance-tools/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.
|
||||||
|
|
||||||
|
# Credits
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
- Stéphan Sainléger
|
||||||
|
|
||||||
|
## Funders
|
||||||
|
|
||||||
|
The development of this module has been financially supported by:
|
||||||
|
|
||||||
|
- Elabore (https://elabore.coop)
|
||||||
|
|
||||||
|
## Maintainer
|
||||||
|
|
||||||
|
This module is maintained by Elabore.
|
||||||
1
maintenance_equipment_customer/__init__.py
Normal file
1
maintenance_equipment_customer/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import models
|
||||||
25
maintenance_equipment_customer/__manifest__.py
Normal file
25
maintenance_equipment_customer/__manifest__.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Copyright 2026 Stéphan Sainléger (Elabore)
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "maintenance_equipment_customer",
|
||||||
|
"version": "18.0.1.0.0",
|
||||||
|
"author": "Elabore",
|
||||||
|
"website": "https://git.elabore.coop/elabore/maintenance-tools",
|
||||||
|
"maintainer": "Stéphan Sainléger",
|
||||||
|
"license": "AGPL-3",
|
||||||
|
"category": "Tools",
|
||||||
|
"summary": "Link maintenance equipment to customer company contacts.",
|
||||||
|
"depends": [
|
||||||
|
"base",
|
||||||
|
"maintenance",
|
||||||
|
"maintenance_server_data",
|
||||||
|
],
|
||||||
|
"data": [
|
||||||
|
"views/maintenance_equipment.xml",
|
||||||
|
"views/res_partner.xml",
|
||||||
|
],
|
||||||
|
"installable": True,
|
||||||
|
"auto_install": False,
|
||||||
|
"application": False,
|
||||||
|
}
|
||||||
79
maintenance_equipment_customer/i18n/fr.po
Normal file
79
maintenance_equipment_customer/i18n/fr.po
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
# Translation of Odoo Server.
|
||||||
|
# This file contains the translation of the following modules:
|
||||||
|
# * maintenance_equipment_customer
|
||||||
|
#
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: Odoo Server 18.0\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2026-11-17 16:10+0000\n"
|
||||||
|
"PO-Revision-Date: 2026-11-17 16:10+0000\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"Language: fr_FR\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: \n"
|
||||||
|
"Plural-Forms: \n"
|
||||||
|
|
||||||
|
#. module: maintenance_equipment_customer
|
||||||
|
#: model:ir.model,name:maintenance_equipment_customer.model_res_partner
|
||||||
|
msgid "Contact"
|
||||||
|
msgstr "Contact"
|
||||||
|
|
||||||
|
#. module: maintenance_equipment_customer
|
||||||
|
#: model:ir.model.fields,field_description:maintenance_equipment_customer.field_maintenance_equipment__customer_id
|
||||||
|
#: model_terms:ir.ui.view,arch_db:maintenance_equipment_customer.equipment_view_search_customer_inherit
|
||||||
|
msgid "Customer Contact"
|
||||||
|
msgstr "Contact client"
|
||||||
|
|
||||||
|
#. module: maintenance_equipment_customer
|
||||||
|
#: model_terms:ir.ui.view,arch_db:maintenance_equipment_customer.partner_view_form_maintenance_equipment
|
||||||
|
msgid "Equipment"
|
||||||
|
msgstr "Équipement"
|
||||||
|
|
||||||
|
#. module: maintenance_equipment_customer
|
||||||
|
#: model:ir.model,name:maintenance_equipment_customer.model_maintenance_equipment
|
||||||
|
#: model:ir.model.fields,field_description:maintenance_equipment_customer.field_res_partner__maintenance_equipment_ids
|
||||||
|
#: model:ir.model.fields,field_description:maintenance_equipment_customer.field_res_users__maintenance_equipment_ids
|
||||||
|
msgid "Maintenance Equipment"
|
||||||
|
msgstr "Équipement de maintenance"
|
||||||
|
|
||||||
|
#. module: maintenance_equipment_customer
|
||||||
|
#: model:ir.model.fields,field_description:maintenance_equipment_customer.field_res_partner__maintenance_equipment_count
|
||||||
|
#: model:ir.model.fields,field_description:maintenance_equipment_customer.field_res_users__maintenance_equipment_count
|
||||||
|
msgid "Maintenance Equipment Count"
|
||||||
|
msgstr "Nombre d'équipements de maintenance"
|
||||||
|
|
||||||
|
#. module: maintenance_equipment_customer
|
||||||
|
#: model_terms:ir.ui.view,arch_db:maintenance_equipment_customer.partner_view_search_maintenance_equipment
|
||||||
|
msgid "Maintenance Service"
|
||||||
|
msgstr "Service de maintenance"
|
||||||
|
|
||||||
|
#. module: maintenance_equipment_customer
|
||||||
|
#: model_terms:ir.ui.view,arch_db:maintenance_equipment_customer.partner_view_search_maintenance_equipment
|
||||||
|
msgid "Maintenance Service Version"
|
||||||
|
msgstr "Version de service de maintenance"
|
||||||
|
|
||||||
|
#. module: maintenance_equipment_customer
|
||||||
|
#: model:ir.model.fields,field_description:maintenance_equipment_customer.field_res_partner__maintenance_service_version_ids
|
||||||
|
#: model:ir.model.fields,field_description:maintenance_equipment_customer.field_res_users__maintenance_service_version_ids
|
||||||
|
msgid "Maintenance Service Versions"
|
||||||
|
msgstr "Versions de services de maintenance"
|
||||||
|
|
||||||
|
#. module: maintenance_equipment_customer
|
||||||
|
#: model:ir.model.fields,field_description:maintenance_equipment_customer.field_res_partner__maintenance_service_ids
|
||||||
|
#: model:ir.model.fields,field_description:maintenance_equipment_customer.field_res_users__maintenance_service_ids
|
||||||
|
msgid "Maintenance Services"
|
||||||
|
msgstr "Services de maintenance"
|
||||||
|
|
||||||
|
#. module: maintenance_equipment_customer
|
||||||
|
#. odoo-python
|
||||||
|
#: code:addons/maintenance_equipment_customer/models/maintenance_equipment.py:0
|
||||||
|
msgid "The customer contact of equipment %(equipment)s must be a company."
|
||||||
|
msgstr "Le contact client de l'équipement %(equipment)s doit être une société."
|
||||||
|
|
||||||
|
#. module: maintenance_equipment_customer
|
||||||
|
#: model_terms:ir.ui.view,arch_db:maintenance_equipment_customer.partner_view_search_maintenance_equipment
|
||||||
|
msgid "With Maintenance Equipment"
|
||||||
|
msgstr "Avec équipement de maintenance"
|
||||||
2
maintenance_equipment_customer/models/__init__.py
Normal file
2
maintenance_equipment_customer/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
from . import maintenance_equipment
|
||||||
|
from . import res_partner
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
from odoo import api, fields, models
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
|
class MaintenanceEquipment(models.Model):
|
||||||
|
"""Link maintenance equipment to the company contact it belongs to."""
|
||||||
|
|
||||||
|
_inherit = "maintenance.equipment"
|
||||||
|
|
||||||
|
customer_id = fields.Many2one(
|
||||||
|
"res.partner",
|
||||||
|
string="Customer Contact",
|
||||||
|
domain=[("is_company", "=", True)],
|
||||||
|
index=True,
|
||||||
|
ondelete="restrict",
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.constrains("customer_id")
|
||||||
|
def _check_customer_is_company(self):
|
||||||
|
"""Reject individual contacts: equipment belongs to a company.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValidationError: when the linked contact is not a company.
|
||||||
|
"""
|
||||||
|
for equipment in self:
|
||||||
|
if equipment.customer_id and not equipment.customer_id.is_company:
|
||||||
|
raise ValidationError(
|
||||||
|
self.env._(
|
||||||
|
"The customer contact of equipment %(equipment)s "
|
||||||
|
"must be a company.",
|
||||||
|
equipment=equipment.display_name,
|
||||||
|
)
|
||||||
|
)
|
||||||
116
maintenance_equipment_customer/models/res_partner.py
Normal file
116
maintenance_equipment_customer/models/res_partner.py
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class ResPartner(models.Model):
|
||||||
|
"""Expose maintenance equipment and installed services on contacts."""
|
||||||
|
|
||||||
|
_inherit = "res.partner"
|
||||||
|
|
||||||
|
maintenance_equipment_ids = fields.One2many(
|
||||||
|
"maintenance.equipment",
|
||||||
|
"customer_id",
|
||||||
|
)
|
||||||
|
maintenance_equipment_count = fields.Integer(
|
||||||
|
compute="_compute_maintenance_equipment_count",
|
||||||
|
)
|
||||||
|
maintenance_service_ids = fields.Many2many(
|
||||||
|
"service",
|
||||||
|
string="Maintenance Services",
|
||||||
|
store=False,
|
||||||
|
search="_search_maintenance_service_ids",
|
||||||
|
)
|
||||||
|
maintenance_service_version_ids = fields.Many2many(
|
||||||
|
"service.version",
|
||||||
|
string="Maintenance Service Versions",
|
||||||
|
store=False,
|
||||||
|
search="_search_maintenance_service_version_ids",
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.depends("maintenance_equipment_ids")
|
||||||
|
def _compute_maintenance_equipment_count(self):
|
||||||
|
"""Count the equipment records linked to this contact."""
|
||||||
|
for partner in self:
|
||||||
|
partner.maintenance_equipment_count = len(partner.maintenance_equipment_ids)
|
||||||
|
|
||||||
|
def _search_maintenance_service_ids(self, operator, value):
|
||||||
|
"""Filter contacts by services installed on their equipment.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
operator: Odoo search operator (``=``, ``!=``, ``in``, ``not in``,
|
||||||
|
``ilike``, ``not ilike``).
|
||||||
|
value: A service id, a text value, or a list of service ids.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: A domain selecting matching contacts.
|
||||||
|
"""
|
||||||
|
return self._search_maintenance_instances(operator, value, "service_id")
|
||||||
|
|
||||||
|
def _search_maintenance_service_version_ids(self, operator, value):
|
||||||
|
"""Filter contacts by service versions installed on their equipment.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
operator: Odoo search operator (``=``, ``!=``, ``in``, ``not in``,
|
||||||
|
``ilike``, ``not ilike``).
|
||||||
|
value: A version id, a text value, or a list of version ids.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: A domain selecting matching contacts.
|
||||||
|
"""
|
||||||
|
return self._search_maintenance_instances(operator, value, "version_id")
|
||||||
|
|
||||||
|
def _search_maintenance_instances(self, operator, value, instance_field):
|
||||||
|
"""Translate a service instance filter into a contact domain.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
operator: Odoo search operator applied to ``instance_field``.
|
||||||
|
value: A record id, a text value, a list of record ids, or ``False``.
|
||||||
|
instance_field: ``service_id`` or ``version_id`` on service instances.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: A domain selecting contacts with (or without) matching
|
||||||
|
service instances.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError: when the operator is not supported.
|
||||||
|
"""
|
||||||
|
supported_operators = ("=", "!=", "in", "not in", "ilike", "not ilike")
|
||||||
|
if operator not in supported_operators:
|
||||||
|
raise ValueError(
|
||||||
|
f"Unsupported operator for maintenance filtering: {operator}"
|
||||||
|
)
|
||||||
|
if value is False:
|
||||||
|
instances = self.env["service.instance"].search(
|
||||||
|
[(instance_field, "!=", False)]
|
||||||
|
)
|
||||||
|
partner_ids = instances.equipment_id.customer_id.ids
|
||||||
|
if operator in ("!=", "not in", "not ilike"):
|
||||||
|
return [("id", "in", partner_ids)]
|
||||||
|
return [("id", "not in", partner_ids)]
|
||||||
|
if operator in ("=", "in", "ilike"):
|
||||||
|
instances = self.env["service.instance"].search(
|
||||||
|
[(instance_field, operator, value)]
|
||||||
|
)
|
||||||
|
return [("id", "in", instances.equipment_id.customer_id.ids)]
|
||||||
|
instance_operator = {
|
||||||
|
"!=": "=",
|
||||||
|
"not in": "in",
|
||||||
|
"not ilike": "ilike",
|
||||||
|
}[operator]
|
||||||
|
instances = self.env["service.instance"].search(
|
||||||
|
[(instance_field, instance_operator, value)]
|
||||||
|
)
|
||||||
|
return [("id", "not in", instances.equipment_id.customer_id.ids)]
|
||||||
|
|
||||||
|
def action_view_maintenance_equipment(self):
|
||||||
|
"""Open the maintenance equipment list filtered on this contact.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: window action restricted to the contact's equipment.
|
||||||
|
"""
|
||||||
|
self.ensure_one()
|
||||||
|
action = self.env["ir.actions.act_window"]._for_xml_id(
|
||||||
|
"maintenance.hr_equipment_action"
|
||||||
|
)
|
||||||
|
action["domain"] = [("customer_id", "=", self.id)]
|
||||||
|
action["context"] = {"default_customer_id": self.id}
|
||||||
|
return action
|
||||||
1
maintenance_equipment_customer/tests/__init__.py
Normal file
1
maintenance_equipment_customer/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import test_maintenance_equipment_customer
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
from odoo.tests.common import TransactionCase
|
||||||
|
|
||||||
|
|
||||||
|
class TestMaintenanceEquipmentCustomer(TransactionCase):
|
||||||
|
"""Validate the equipment-to-customer link and service filtering."""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
cls.company = cls.env["res.partner"].create(
|
||||||
|
{"name": "Customer Company", "is_company": True}
|
||||||
|
)
|
||||||
|
cls.individual = cls.env["res.partner"].create(
|
||||||
|
{"name": "Individual Customer", "is_company": False}
|
||||||
|
)
|
||||||
|
cls.service_odoo = cls.env["service"].create({"name": "Odoo"})
|
||||||
|
cls.version_14 = cls.env["service.version"].create(
|
||||||
|
{"service_id": cls.service_odoo.id, "name": "14.0"}
|
||||||
|
)
|
||||||
|
cls.service_postgres = cls.env["service"].create({"name": "PostgreSQL"})
|
||||||
|
cls.version_16 = cls.env["service.version"].create(
|
||||||
|
{"service_id": cls.service_postgres.id, "name": "16"}
|
||||||
|
)
|
||||||
|
cls.equipment = cls.env["maintenance.equipment"].create(
|
||||||
|
{"name": "Customer Server", "customer_id": cls.company.id}
|
||||||
|
)
|
||||||
|
cls.service_instance = cls.env["service.instance"].create(
|
||||||
|
{
|
||||||
|
"equipment_id": cls.equipment.id,
|
||||||
|
"service_id": cls.service_odoo.id,
|
||||||
|
"version_id": cls.version_14.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_customer_link_is_visible_from_partner(self):
|
||||||
|
self.assertEqual(self.equipment.customer_id, self.company)
|
||||||
|
self.assertIn(self.equipment, self.company.maintenance_equipment_ids)
|
||||||
|
self.assertEqual(self.company.maintenance_equipment_count, 1)
|
||||||
|
|
||||||
|
def test_customer_must_be_a_company(self):
|
||||||
|
with self.assertRaises(ValidationError):
|
||||||
|
self.env["maintenance.equipment"].create(
|
||||||
|
{"name": "Individual Equipment", "customer_id": self.individual.id}
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_partners_can_be_filtered_by_service_and_version(self):
|
||||||
|
partners = self.env["res.partner"].search(
|
||||||
|
[
|
||||||
|
("maintenance_service_ids", "in", self.service_odoo.ids),
|
||||||
|
(
|
||||||
|
"maintenance_service_version_ids",
|
||||||
|
"in",
|
||||||
|
self.version_14.ids,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
self.assertIn(self.company, partners)
|
||||||
|
self.assertNotIn(self.individual, partners)
|
||||||
|
|
||||||
|
def test_service_filter_excludes_other_services(self):
|
||||||
|
partners = self.env["res.partner"].search(
|
||||||
|
[("maintenance_service_ids", "in", self.service_postgres.ids)]
|
||||||
|
)
|
||||||
|
self.assertNotIn(self.company, partners)
|
||||||
|
|
||||||
|
def test_service_change_updates_partner_filters(self):
|
||||||
|
self.service_instance.write(
|
||||||
|
{
|
||||||
|
"service_id": self.service_postgres.id,
|
||||||
|
"version_id": self.version_16.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
partners = self.env["res.partner"].search(
|
||||||
|
[
|
||||||
|
("maintenance_service_ids", "in", self.service_postgres.ids),
|
||||||
|
(
|
||||||
|
"maintenance_service_version_ids",
|
||||||
|
"in",
|
||||||
|
self.version_16.ids,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
self.assertIn(self.company, partners)
|
||||||
|
partners = self.env["res.partner"].search(
|
||||||
|
[
|
||||||
|
("maintenance_service_ids", "in", self.service_odoo.ids),
|
||||||
|
(
|
||||||
|
"maintenance_service_version_ids",
|
||||||
|
"in",
|
||||||
|
self.version_14.ids,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
self.assertNotIn(self.company, partners)
|
||||||
|
|
||||||
|
def test_transfer_equipment_to_another_company_updates_partners(self):
|
||||||
|
other_company = self.env["res.partner"].create(
|
||||||
|
{"name": "Other Customer Company", "is_company": True}
|
||||||
|
)
|
||||||
|
self.equipment.write({"customer_id": other_company.id})
|
||||||
|
self.assertFalse(self.company.maintenance_equipment_ids)
|
||||||
|
self.assertEqual(self.company.maintenance_equipment_count, 0)
|
||||||
|
self.assertIn(self.equipment, other_company.maintenance_equipment_ids)
|
||||||
|
partners = self.env["res.partner"].search(
|
||||||
|
[("maintenance_service_ids", "in", self.service_odoo.ids)]
|
||||||
|
)
|
||||||
|
self.assertIn(other_company, partners)
|
||||||
|
self.assertNotIn(self.company, partners)
|
||||||
|
|
||||||
|
def test_search_bar_ilike_filter_on_service(self):
|
||||||
|
partners = self.env["res.partner"].search(
|
||||||
|
[("maintenance_service_ids", "ilike", "Odoo")]
|
||||||
|
)
|
||||||
|
self.assertIn(self.company, partners)
|
||||||
|
self.assertNotIn(self.individual, partners)
|
||||||
|
|
||||||
|
def test_search_bar_ilike_filter_on_version(self):
|
||||||
|
partners = self.env["res.partner"].search(
|
||||||
|
[("maintenance_service_version_ids", "ilike", "14")]
|
||||||
|
)
|
||||||
|
self.assertIn(self.company, partners)
|
||||||
|
self.assertNotIn(self.individual, partners)
|
||||||
|
|
||||||
|
def test_search_bar_not_ilike_filter_on_service(self):
|
||||||
|
partners = self.env["res.partner"].search(
|
||||||
|
[("maintenance_service_ids", "not ilike", "Odoo")]
|
||||||
|
)
|
||||||
|
self.assertNotIn(self.company, partners)
|
||||||
|
partners = self.env["res.partner"].search(
|
||||||
|
[("maintenance_service_ids", "not ilike", "Postgre")]
|
||||||
|
)
|
||||||
|
self.assertIn(self.company, partners)
|
||||||
|
|
||||||
|
def test_filter_on_false_matches_partners_without_services(self):
|
||||||
|
partners = self.env["res.partner"].search(
|
||||||
|
[("maintenance_service_ids", "=", False)]
|
||||||
|
)
|
||||||
|
self.assertIn(self.individual, partners)
|
||||||
|
self.assertNotIn(self.company, partners)
|
||||||
|
|
||||||
|
def test_filter_not_false_matches_partners_with_services(self):
|
||||||
|
partners = self.env["res.partner"].search(
|
||||||
|
[("maintenance_service_ids", "!=", False)]
|
||||||
|
)
|
||||||
|
self.assertIn(self.company, partners)
|
||||||
|
self.assertNotIn(self.individual, partners)
|
||||||
|
|
||||||
|
def test_service_version_display_name_includes_service(self):
|
||||||
|
self.assertEqual(self.version_14.display_name, "Odoo 14.0")
|
||||||
|
self.assertEqual(self.version_16.display_name, "PostgreSQL 16")
|
||||||
|
|
||||||
|
def test_action_view_maintenance_equipment(self):
|
||||||
|
action = self.company.action_view_maintenance_equipment()
|
||||||
|
self.assertEqual(action["res_model"], "maintenance.equipment")
|
||||||
|
self.assertEqual(action["domain"], [("customer_id", "=", self.company.id)])
|
||||||
|
self.assertEqual(action["context"], {"default_customer_id": self.company.id})
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<odoo>
|
||||||
|
<record id="equipment_view_form_customer_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">maintenance.equipment.form.customer</field>
|
||||||
|
<field name="model">maintenance.equipment</field>
|
||||||
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//div[hasclass('oe_title')]" position="after">
|
||||||
|
<group name="customer">
|
||||||
|
<field name="customer_id" />
|
||||||
|
</group>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="equipment_view_list_customer_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">maintenance.equipment.list.customer</field>
|
||||||
|
<field name="model">maintenance.equipment</field>
|
||||||
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_tree" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='name']" position="after">
|
||||||
|
<field name="customer_id" optional="hide" />
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="equipment_view_search_customer_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">maintenance.equipment.search.customer</field>
|
||||||
|
<field name="model">maintenance.equipment</field>
|
||||||
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_search" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='owner_user_id']" position="after">
|
||||||
|
<field name="customer_id" />
|
||||||
|
</xpath>
|
||||||
|
<xpath expr="//group[@expand='0']" position="inside">
|
||||||
|
<filter
|
||||||
|
string="Customer Contact"
|
||||||
|
name="customer"
|
||||||
|
context="{'group_by': 'customer_id'}"
|
||||||
|
/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
51
maintenance_equipment_customer/views/res_partner.xml
Normal file
51
maintenance_equipment_customer/views/res_partner.xml
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<odoo>
|
||||||
|
<record id="partner_view_form_maintenance_equipment" model="ir.ui.view">
|
||||||
|
<field name="name">res.partner.form.maintenance.equipment</field>
|
||||||
|
<field name="model">res.partner</field>
|
||||||
|
<field name="inherit_id" ref="base.view_partner_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//div[@name='button_box']" position="inside">
|
||||||
|
<button
|
||||||
|
class="oe_stat_button"
|
||||||
|
type="object"
|
||||||
|
name="action_view_maintenance_equipment"
|
||||||
|
icon="fa-wrench"
|
||||||
|
invisible="maintenance_equipment_count == 0"
|
||||||
|
>
|
||||||
|
<field
|
||||||
|
string="Equipment"
|
||||||
|
name="maintenance_equipment_count"
|
||||||
|
widget="statinfo"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="partner_view_search_maintenance_equipment" model="ir.ui.view">
|
||||||
|
<field name="name">res.partner.search.maintenance.equipment</field>
|
||||||
|
<field name="model">res.partner</field>
|
||||||
|
<field name="inherit_id" ref="base.view_res_partner_filter" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='category_id']" position="after">
|
||||||
|
<field
|
||||||
|
name="maintenance_service_ids"
|
||||||
|
string="Maintenance Service"
|
||||||
|
/>
|
||||||
|
<field
|
||||||
|
name="maintenance_service_version_ids"
|
||||||
|
string="Maintenance Service Version"
|
||||||
|
/>
|
||||||
|
</xpath>
|
||||||
|
<xpath expr="//filter[@name='inactive']" position="before">
|
||||||
|
<filter
|
||||||
|
string="With Maintenance Equipment"
|
||||||
|
name="with_maintenance_equipment"
|
||||||
|
domain="[('maintenance_equipment_ids', '!=', False)]"
|
||||||
|
/>
|
||||||
|
<separator />
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
@@ -1,19 +1,35 @@
|
|||||||
from odoo import fields, models
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
class Service(models.Model):
|
class Service(models.Model):
|
||||||
_name = "service"
|
_name = "service"
|
||||||
|
|
||||||
name = fields.Char("Name", required=True)
|
name = fields.Char(required=True)
|
||||||
|
|
||||||
|
|
||||||
class ServiceVersion(models.Model):
|
class ServiceVersion(models.Model):
|
||||||
_name = "service.version"
|
_name = "service.version"
|
||||||
|
_rec_names_search = ["service_id.name", "name"]
|
||||||
|
|
||||||
service_id = fields.Many2one("service", string="Service", required=True)
|
service_id = fields.Many2one("service", string="Service", required=True)
|
||||||
name = fields.Char("Name")
|
name = fields.Char()
|
||||||
is_last_version = fields.Boolean("Is Last Version?")
|
is_last_version = fields.Boolean("Is Last Version?")
|
||||||
|
|
||||||
|
@api.depends("service_id.name", "name")
|
||||||
|
def _compute_display_name(self):
|
||||||
|
"""Display the version prefixed by its service name.
|
||||||
|
|
||||||
|
This keeps the version autocomplete unambiguous when several services
|
||||||
|
share the same version label, for example ``Odoo 14.0``.
|
||||||
|
"""
|
||||||
|
for version in self:
|
||||||
|
if version.service_id and version.name:
|
||||||
|
version.display_name = f"{version.service_id.name} {version.name}"
|
||||||
|
elif version.service_id:
|
||||||
|
version.display_name = version.service_id.name
|
||||||
|
else:
|
||||||
|
version.display_name = version.name or ""
|
||||||
|
|
||||||
|
|
||||||
class ServiceInstance(models.Model):
|
class ServiceInstance(models.Model):
|
||||||
_name = "service.instance"
|
_name = "service.instance"
|
||||||
@@ -21,11 +37,11 @@ class ServiceInstance(models.Model):
|
|||||||
equipment_id = fields.Many2one("maintenance.equipment", string="Equipment")
|
equipment_id = fields.Many2one("maintenance.equipment", string="Equipment")
|
||||||
service_id = fields.Many2one("service", string="Service", required=True)
|
service_id = fields.Many2one("service", string="Service", required=True)
|
||||||
version_id = fields.Many2one("service.version", string="Version")
|
version_id = fields.Many2one("service.version", string="Version")
|
||||||
service_url = fields.Char(string="Service Url")
|
service_url = fields.Char()
|
||||||
active = fields.Boolean(default=True)
|
active = fields.Boolean(default=True)
|
||||||
|
|
||||||
|
|
||||||
class BackupServer(models.Model):
|
class BackupServer(models.Model):
|
||||||
_name = "backup.server"
|
_name = "backup.server"
|
||||||
|
|
||||||
name = fields.Char("Name", required=True)
|
name = fields.Char(required=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user