Files
maintenance-tools/maintenance_equipment_customer/models/maintenance_equipment.py
Stéphan Sainléger 1593eb2222
Some checks failed
tests / test (pull_request) Successful in 1m11s
pre-commit / pre-commit (pull_request) Failing after 1m35s
[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.
2026-11-17 17:57:13 +01:00

34 lines
1.1 KiB
Python

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