This commit is contained in:
gsinghpal
2026-04-26 15:05:17 -04:00
parent 160198edb1
commit d9f58b9851
110 changed files with 6210 additions and 1182 deletions

View File

@@ -517,6 +517,12 @@ class FpJob(models.Model):
if self.env.context.get('fp_jobs_migration'):
return result
for job in self:
# Auto-generate steps from the recipe — was previously only
# called by seed scripts, which meant real-life confirmed
# jobs sat with zero operations. Idempotent: the generator
# short-circuits when steps already exist.
if job.recipe_id and not job.step_ids:
job._generate_steps_from_recipe()
job._fp_create_portal_job()
job._fp_create_qc_check_if_needed()
job._fp_create_racking_inspection()
@@ -526,36 +532,28 @@ class FpJob(models.Model):
def _fp_create_racking_inspection(self):
"""Auto-create a draft racking inspection on job confirm.
Mirrors bridge_mrp's behaviour for MO confirm. Best-effort: the
legacy fp.racking.inspection model still requires a production_id
(mrp.production), so we can only create one when this job is
bound to an MO via bridge_mrp. Otherwise we skip cleanly — Phase
9 will flip the required-FK to fp.job.
Phase 9 — production_id is now optional on fp.racking.inspection,
so we always create one bound by `x_fc_job_id`. When the job is
also linked to an MO (legacy bridge_mrp coexistence), populate
production_id too so legacy reports keep working.
Idempotent — if an inspection already exists for this job, skip.
"""
self.ensure_one()
if 'fp.racking.inspection' not in self.env:
return
Inspection = self.env['fp.racking.inspection'].sudo()
# The model still requires production_id today. If the job has
# no MO link (which it won't in pure-native mode), skip rather
# than crash. The link exists when fusion_plating_bridge_mrp is
# installed and a production was created in parallel.
production = False
if 'production_id' in self._fields and self.production_id:
production = self.production_id
elif 'mrp_production_id' in self._fields and getattr(
self, 'mrp_production_id', False):
production = self.mrp_production_id
if not production:
_logger.debug(
"Job %s: no MO link — skipping racking-inspection auto-create "
"(required production_id not yet on fp.job).", self.name,
)
if 'x_fc_job_id' not in Inspection._fields:
# Schema not yet upgraded — skip.
return
existing = Inspection.search([
('x_fc_job_id', '=', self.id),
], limit=1)
if existing:
return
# Phase 6 (Sub 11) — production_id retired; bind by x_fc_job_id only.
vals = {'x_fc_job_id': self.id}
try:
vals = {'production_id': production.id}
if 'x_fc_job_id' in Inspection._fields:
vals['x_fc_job_id'] = self.id
Inspection.create(vals)
except Exception as e:
_logger.warning(