refactor(jobs): gate fp.job lifecycle hooks on fp_jobs_migration context

Migration script now sets context fp_jobs_migration=True before
creating fp.job records. action_confirm and button_mark_done check
this flag and skip side-effects (portal job creation, QC check,
racking inspection, delivery, certificate, notification dispatch)
when migrating.

Without this, the migration would double-create portal jobs / QC
checks / racking inspections — once via bridge_mrp's original
create on the source MO, once via jobs module's lifecycle hook on
the new fp.job mirror. With the gate, the migration script
explicitly rebinds the existing dependents via x_fc_job_id.

Manifest 19.0.2.0.0 → 19.0.2.1.0.

Part of: native job model migration (spec 2026-04-25)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsinghpal
2026-04-25 00:19:17 -04:00
parent f2f98aa9f6
commit 97861df74d
3 changed files with 18 additions and 4 deletions

View File

@@ -267,6 +267,11 @@ class FpJob(models.Model):
# ------------------------------------------------------------------
def action_confirm(self):
result = super().action_confirm()
# During migration, lifecycle side-effects are skipped — the
# migration script directly rebinds existing portal/QC/inspection
# records via x_fc_job_id. See scripts/migrate_to_fp_jobs.py.
if self.env.context.get('fp_jobs_migration'):
return result
for job in self:
job._fp_create_portal_job()
job._fp_create_qc_check_if_needed()
@@ -383,6 +388,8 @@ class FpJob(models.Model):
- Auto-creates a draft fusion.plating.delivery
- Triggers certificate auto-generation (best-effort)
"""
# During migration, side-effects are skipped — see action_confirm.
skip_side_effects = self.env.context.get('fp_jobs_migration')
for job in self:
if job.state == 'done':
continue
@@ -392,9 +399,10 @@ class FpJob(models.Model):
)
job.state = 'done'
job.date_finished = fields.Datetime.now()
job._fp_create_delivery()
job._fp_create_certificates()
job._fp_fire_notification('job_complete')
if not skip_side_effects:
job._fp_create_delivery()
job._fp_create_certificates()
job._fp_fire_notification('job_complete')
return True
# ------------------------------------------------------------------