feat(numbering): wire CoC/RCV/DLV/PU into parent-numbered mixin + rename counters
Per-model counter fields on sale.order renamed to x_fc_pn_*_count to avoid collision with pre-existing compute fields of the same short name in bridge_mrp / receiving / configurator (silent compute-override was suppressing the storage). 4 child models (fp.certificate, fp.receiving, fusion.plating.delivery, fusion.plating.pickup.request) now derive names as PFX-<parent> with -NN suffix from the 2nd onward. fusion.plating.pickup.request gains a sale_order_id field (optional) so pickups created against an SO get parent-derived names, while standalone pickups (pre-SO) fall back to PU/YYYY/NNNN. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -20,7 +20,7 @@ class FpCertificate(models.Model):
|
||||
"""
|
||||
_name = 'fp.certificate'
|
||||
_description = 'Fusion Plating — Certificate'
|
||||
_inherit = ['mail.thread', 'mail.activity.mixin']
|
||||
_inherit = ['mail.thread', 'mail.activity.mixin', 'fp.parent.numbered.mixin']
|
||||
_order = 'issue_date desc, id desc'
|
||||
|
||||
name = fields.Char(string='Reference', readonly=True, copy=False, default='New')
|
||||
@@ -271,14 +271,22 @@ class FpCertificate(models.Model):
|
||||
rec.trend_alert = alert
|
||||
rec.trend_explanation = explanation
|
||||
|
||||
# ----- Sequence + spec-limit auto-fill ---------------------------------
|
||||
# ----- Parent-numbered mixin hooks -------------------------------------
|
||||
def _fp_parent_sale_order(self):
|
||||
return self.sale_order_id
|
||||
|
||||
def _fp_name_prefix(self):
|
||||
return 'CoC'
|
||||
|
||||
def _fp_parent_counter_field(self):
|
||||
return 'x_fc_pn_cert_count'
|
||||
|
||||
# ----- Create: parent-derived name (fallback to legacy sequence) -------
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
SaleOrder = self.env['sale.order']
|
||||
for vals in vals_list:
|
||||
if vals.get('name', 'New') == 'New':
|
||||
vals['name'] = self.env['ir.sequence'].next_by_code('fp.certificate') or 'New'
|
||||
# Pull thickness spec limits from coating config if not set
|
||||
# Spec-limit auto-fill (existing behaviour, preserved).
|
||||
already_set = vals.get('spec_min_mils') or vals.get('spec_max_mils')
|
||||
if not already_set and vals.get('sale_order_id'):
|
||||
so = SaleOrder.browse(vals['sale_order_id'])
|
||||
@@ -286,7 +294,23 @@ class FpCertificate(models.Model):
|
||||
if cfg and cfg.thickness_uom == 'mils':
|
||||
vals.setdefault('spec_min_mils', cfg.thickness_min or 0.0)
|
||||
vals.setdefault('spec_max_mils', cfg.thickness_max or 0.0)
|
||||
return super().create(vals_list)
|
||||
# Defer naming: let the record exist so the mixin can write
|
||||
# name via raw SQL, then fall back to the legacy sequence if
|
||||
# no parent SO is reachable.
|
||||
if not vals.get('name'):
|
||||
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('fp.certificate') or 'New'
|
||||
self.env.cr.execute(
|
||||
"UPDATE fp_certificate SET name = %s WHERE id = %s",
|
||||
(seq, rec.id),
|
||||
)
|
||||
rec.invalidate_recordset(['name'])
|
||||
return records
|
||||
|
||||
# ----- State actions ----------------------------------------------------
|
||||
def action_issue(self):
|
||||
|
||||
Reference in New Issue
Block a user