103 lines
3.0 KiB
Python
103 lines
3.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright 2026 Nexa Systems Inc.
|
|
# License OPL-1 (Odoo Proprietary License v1.0)
|
|
# Part of the Fusion Plating product family.
|
|
|
|
from odoo import fields, models
|
|
|
|
|
|
class FpFacility(models.Model):
|
|
"""A physical plating / finishing facility.
|
|
|
|
A company can operate 1..N facilities. Each facility has its own work
|
|
centers, tanks, operators, regulatory profile (ECA, sewer permit, waste
|
|
generator number), and capability footprint. Jobs are scheduled into
|
|
a facility based on capability matching.
|
|
|
|
Compliance add-on modules (fusion_plating_compliance_*) extend this
|
|
model with jurisdiction-specific fields via inheritance.
|
|
"""
|
|
_name = 'fusion.plating.facility'
|
|
_description = 'Fusion Plating — Facility'
|
|
_inherit = ['mail.thread', 'mail.activity.mixin']
|
|
_order = 'sequence, name'
|
|
|
|
name = fields.Char(
|
|
string='Facility',
|
|
required=True,
|
|
tracking=True,
|
|
)
|
|
code = fields.Char(
|
|
string='Code',
|
|
required=True,
|
|
tracking=True,
|
|
help='Short facility code used in job numbers and reports.',
|
|
)
|
|
sequence = fields.Integer(
|
|
string='Sequence',
|
|
default=10,
|
|
)
|
|
company_id = fields.Many2one(
|
|
'res.company',
|
|
string='Company',
|
|
required=True,
|
|
default=lambda self: self.env.company,
|
|
)
|
|
partner_id = fields.Many2one(
|
|
'res.partner',
|
|
string='Address',
|
|
help='Partner holding the facility postal address and contact details.',
|
|
)
|
|
active = fields.Boolean(
|
|
string='Active',
|
|
default=True,
|
|
)
|
|
|
|
# ----- Capability -----------------------------------------------------
|
|
capability_ids = fields.Many2many(
|
|
'fusion.plating.process.type',
|
|
'fp_facility_capability_rel',
|
|
'facility_id',
|
|
'process_type_id',
|
|
string='Capabilities',
|
|
help='Process types this facility can perform.',
|
|
)
|
|
|
|
# ----- Child records --------------------------------------------------
|
|
work_center_ids = fields.One2many(
|
|
'fusion.plating.work.center',
|
|
'facility_id',
|
|
string='Work Centers',
|
|
)
|
|
tank_ids = fields.One2many(
|
|
'fusion.plating.tank',
|
|
'facility_id',
|
|
string='Tanks',
|
|
)
|
|
work_center_count = fields.Integer(
|
|
compute='_compute_counts',
|
|
)
|
|
tank_count = fields.Integer(
|
|
compute='_compute_counts',
|
|
)
|
|
capability_count = fields.Integer(
|
|
compute='_compute_counts',
|
|
)
|
|
|
|
_sql_constraints = [
|
|
(
|
|
'fp_facility_code_company_uniq',
|
|
'unique(code, company_id)',
|
|
'Facility code must be unique within a company.',
|
|
),
|
|
]
|
|
|
|
def _compute_counts(self):
|
|
for rec in self:
|
|
rec.work_center_count = len(rec.work_center_ids)
|
|
rec.tank_count = len(rec.tank_ids)
|
|
rec.capability_count = len(rec.capability_ids)
|
|
|
|
def name_get(self):
|
|
return [(rec.id, f'{rec.name} [{rec.code}]') for rec in self]
|