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:
@@ -36,7 +36,7 @@ _logger = logging.getLogger(__name__)
|
||||
class FpRma(models.Model):
|
||||
_name = 'fusion.plating.rma'
|
||||
_description = 'Fusion Plating — Return Material Authorisation'
|
||||
_inherit = ['mail.thread', 'mail.activity.mixin']
|
||||
_inherit = ['mail.thread', 'mail.activity.mixin', 'fp.parent.numbered.mixin']
|
||||
_order = 'create_date desc, id desc'
|
||||
_rec_name = 'name'
|
||||
|
||||
@@ -243,6 +243,17 @@ class FpRma(models.Model):
|
||||
# ------------------------------------------------------------------
|
||||
# Defaults / create / name
|
||||
# ------------------------------------------------------------------
|
||||
# Parent-numbered mixin hooks. RMAs reach the SO directly via
|
||||
# sale_order_id (set at create-time from the original order).
|
||||
def _fp_parent_sale_order(self):
|
||||
return self.sale_order_id
|
||||
|
||||
def _fp_name_prefix(self):
|
||||
return 'RMA'
|
||||
|
||||
def _fp_parent_counter_field(self):
|
||||
return 'x_fc_pn_rma_count'
|
||||
|
||||
@api.model
|
||||
def _default_name(self):
|
||||
seq = self.env['ir.sequence'].next_by_code('fusion.plating.rma')
|
||||
@@ -252,8 +263,19 @@ class FpRma(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.rma') or 'New'
|
||||
self.env.cr.execute(
|
||||
"UPDATE fusion_plating_rma SET name = %s WHERE id = %s",
|
||||
(seq, rec.id),
|
||||
)
|
||||
rec.invalidate_recordset(['name'])
|
||||
return records
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Computes
|
||||
|
||||
Reference in New Issue
Block a user