feat(numbering): wire NCR, CAPA, Hold, RMA into parent-numbered mixin

Hold derives parent via job_id.sale_order_id; RMA via sale_order_id
directly — both get HOLD-<parent> / RMA-<parent> names. NCR and CAPA
have no SO link in core, so they fall back to their legacy sequences
(NCR/YYYY/NNN, CAPA/YYYY/NNN); future modules can override the
_fp_parent_sale_order hook to enable parent naming.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsinghpal
2026-05-12 13:36:29 -04:00
parent 0d85063b5e
commit 95cb73d91a
5 changed files with 112 additions and 13 deletions

View File

@@ -17,7 +17,7 @@ class FpNcr(models.Model):
"""
_name = 'fusion.plating.ncr'
_description = 'Fusion Plating — Non-Conformance Report'
_inherit = ['mail.thread', 'mail.activity.mixin']
_inherit = ['mail.thread', 'mail.activity.mixin', 'fp.parent.numbered.mixin']
_order = 'reported_date desc, id desc'
name = fields.Char(
@@ -130,6 +130,22 @@ class FpNcr(models.Model):
)
active = fields.Boolean(default=True)
# ------------------------------------------------------------------
# Parent-numbered mixin hooks
# NCRs don't have a direct SO/job link in core yet — falls back to
# legacy fusion.plating.ncr sequence. When a future module adds a
# link, it can override _fp_parent_sale_order to enable parent
# naming retroactively without further changes here.
# ------------------------------------------------------------------
def _fp_parent_sale_order(self):
return self.env['sale.order']
def _fp_name_prefix(self):
return 'NCR'
def _fp_parent_counter_field(self):
return 'x_fc_pn_ncr_count'
@api.model
def _default_name(self):
seq = self.env['ir.sequence'].next_by_code('fusion.plating.ncr')
@@ -139,8 +155,19 @@ class FpNcr(models.Model):
def create(self, vals_list):
for vals in vals_list:
if not vals.get('name') or vals.get('name') == '/':
vals['name'] = self._default_name()
return super().create(vals_list)
vals['name'] = 'New'
records = super().create(vals_list)
for rec in records:
if rec.name and rec.name != 'New':
continue
if not rec._fp_assign_parent_name():
seq = self.env['ir.sequence'].next_by_code('fusion.plating.ncr') or 'New'
self.env.cr.execute(
"UPDATE fusion_plating_ncr SET name = %s WHERE id = %s",
(seq, rec.id),
)
rec.invalidate_recordset(['name'])
return records
@api.depends('capa_ids')
def _compute_capa_count(self):