57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright 2026 Nexa Systems Inc.
|
|
# License OPL-1 (Odoo Proprietary License v1.0)
|
|
#
|
|
# Phase 3 / Phase 9 — native-job link on fp.racking.inspection.
|
|
# Coexists with the legacy production_id (mrp.production) link; either
|
|
# (or both) may be set.
|
|
|
|
from odoo import _, api, fields, models
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
class FpRackingInspection(models.Model):
|
|
_inherit = 'fp.racking.inspection'
|
|
|
|
# x_fc_job_id is declared in the base receiving module so its views
|
|
# can reference it. We add help/depends here.
|
|
|
|
@api.depends('x_fc_job_id.name', 'partner_id.name')
|
|
def _compute_name(self):
|
|
for rec in self:
|
|
if rec.x_fc_job_id:
|
|
rec.name = _('Inspection — %s') % rec.x_fc_job_id.name
|
|
else:
|
|
rec.name = _('Racking Inspection')
|
|
|
|
@api.depends('x_fc_job_id.sale_order_id')
|
|
def _compute_sale_order(self):
|
|
for rec in self:
|
|
so = (rec.x_fc_job_id.sale_order_id
|
|
if rec.x_fc_job_id and rec.x_fc_job_id.sale_order_id
|
|
else False)
|
|
rec.sale_order_id = so or False
|
|
rec.partner_id = so.partner_id if so else False
|
|
|
|
@api.constrains('x_fc_job_id')
|
|
def _check_link_present(self):
|
|
for rec in self:
|
|
if not rec.x_fc_job_id:
|
|
raise ValidationError(_(
|
|
'Racking inspection must reference a plating job.'
|
|
))
|
|
|
|
@api.constrains('x_fc_job_id')
|
|
def _check_job_unique(self):
|
|
for rec in self:
|
|
if not rec.x_fc_job_id:
|
|
continue
|
|
dup = self.search_count([
|
|
('x_fc_job_id', '=', rec.x_fc_job_id.id),
|
|
('id', '!=', rec.id),
|
|
])
|
|
if dup:
|
|
raise ValidationError(_(
|
|
'Only one racking inspection per plating job.'
|
|
))
|