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:
@@ -17,7 +17,7 @@ class FpQualityHold(models.Model):
|
||||
"""
|
||||
_name = 'fusion.plating.quality.hold'
|
||||
_description = 'Fusion Plating — Quality Hold'
|
||||
_inherit = ['mail.thread', 'mail.activity.mixin']
|
||||
_inherit = ['mail.thread', 'mail.activity.mixin', 'fp.parent.numbered.mixin']
|
||||
_order = 'create_date desc'
|
||||
|
||||
name = fields.Char(
|
||||
@@ -124,6 +124,17 @@ class FpQualityHold(models.Model):
|
||||
# ------------------------------------------------------------------
|
||||
# Defaults / create
|
||||
# ------------------------------------------------------------------
|
||||
# Parent-numbered mixin hooks. Holds reach the SO through their
|
||||
# linked fp.job (the standard authoring path on the shop floor).
|
||||
def _fp_parent_sale_order(self):
|
||||
return self.job_id.sale_order_id if self.job_id else self.env['sale.order']
|
||||
|
||||
def _fp_name_prefix(self):
|
||||
return 'HOLD'
|
||||
|
||||
def _fp_parent_counter_field(self):
|
||||
return 'x_fc_pn_hold_count'
|
||||
|
||||
@api.model
|
||||
def _default_name(self):
|
||||
seq = self.env['ir.sequence'].next_by_code(
|
||||
@@ -135,8 +146,19 @@ class FpQualityHold(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.quality.hold') or 'New'
|
||||
self.env.cr.execute(
|
||||
"UPDATE fusion_plating_quality_hold SET name = %s WHERE id = %s",
|
||||
(seq, rec.id),
|
||||
)
|
||||
rec.invalidate_recordset(['name'])
|
||||
return records
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Actions
|
||||
|
||||
Reference in New Issue
Block a user