feat(numbering): WO grouping by recipe + parent-derived bulk naming
Replaces x_fc_wo_group_tag grouping with resolved-recipe grouping. Bare WO-<parent> when 1 recipe, WO-<parent>-NN zero-padded for N>1 ordered by min line sequence. fp.job inherits parent-numbered mixin for the manual-add path; bulk SO-confirm sets names explicitly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -51,7 +51,7 @@ class FpJob(models.Model):
|
||||
dt = pytz.UTC.localize(dt)
|
||||
return dt.astimezone(tz).strftime(fmt)
|
||||
_description = 'Work Order'
|
||||
_inherit = ['mail.thread', 'mail.activity.mixin']
|
||||
_inherit = ['mail.thread', 'mail.activity.mixin', 'fp.parent.numbered.mixin']
|
||||
# Sub 12d — state-aware sort. Active work bubbles to the top
|
||||
# (in_progress → confirmed/draft → on_hold → done → cancelled),
|
||||
# then high-priority first within each state, then nearest deadline.
|
||||
@@ -389,12 +389,50 @@ class FpJob(models.Model):
|
||||
continue
|
||||
job.current_step_id = False
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Parent-numbered mixin hooks (2026-05-12 numbering hierarchy)
|
||||
# ------------------------------------------------------------------
|
||||
def _fp_parent_sale_order(self):
|
||||
return self.sale_order_id
|
||||
|
||||
def _fp_name_prefix(self):
|
||||
return 'WO'
|
||||
|
||||
def _fp_parent_counter_field(self):
|
||||
return 'x_fc_wo_count'
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
"""fp.job naming priority:
|
||||
1. Caller-provided name (bulk SO-confirm path sets these explicitly).
|
||||
2. Mixin parent-derived name (manual WO add to an existing SO).
|
||||
3. Legacy fp.job sequence (standalone job, no SO link).
|
||||
"""
|
||||
# Pass A: fall back to legacy 'New' sentinel for records that
|
||||
# don't get a parent-derived name. The mixin's post-create
|
||||
# _fp_assign_parent_name() will override 'New' once the record
|
||||
# exists if a parent SO is reachable.
|
||||
for vals in vals_list:
|
||||
if vals.get('name', _('New')) == _('New'):
|
||||
vals['name'] = self.env['ir.sequence'].next_by_code('fp.job') or _('New')
|
||||
return super().create(vals_list)
|
||||
if not vals.get('name'):
|
||||
vals['name'] = _('New')
|
||||
records = super().create(vals_list)
|
||||
# Pass B: any record that came through with 'New' (no explicit
|
||||
# name from the bulk SO path) tries the parent-derived path,
|
||||
# falling back to the legacy sequence if there's no parent SO.
|
||||
for rec in records:
|
||||
if rec.name and rec.name != _('New') and rec.name != 'New':
|
||||
continue # caller set an explicit name (e.g. bulk SO confirm)
|
||||
if not rec._fp_assign_parent_name():
|
||||
seq = self.env['ir.sequence'].next_by_code('fp.job') or _('New')
|
||||
# Raw SQL — fp.job has no immutability guard yet in this
|
||||
# task, but Task 11 will add one. Using SQL here keeps the
|
||||
# fallback path consistent across all child models.
|
||||
self.env.cr.execute(
|
||||
"UPDATE fp_job SET name = %s WHERE id = %s",
|
||||
(seq, rec.id),
|
||||
)
|
||||
rec.invalidate_recordset(['name'])
|
||||
return records
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# State machine — actions
|
||||
|
||||
Reference in New Issue
Block a user