[ADD] maintenance_equipment_customer: add customer contact link
Some checks failed
tests / test (pull_request) Successful in 1m11s
pre-commit / pre-commit (pull_request) Failing after 1m35s

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:
Stéphan Sainléger
2026-11-17 17:21:11 +01:00
parent 01cf43a97e
commit 1593eb2222
12 changed files with 608 additions and 5 deletions

View File

@@ -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,
)
)