From f8586611c910908d6c0808cf9e01337f2c2182e7 Mon Sep 17 00:00:00 2001 From: gsinghpal Date: Sun, 17 May 2026 03:16:22 -0400 Subject: [PATCH] fix(portal): derive portal_job initial state from fp.job.state on create _fp_create_portal_job hardcoded state='in_progress'. Now uses the same _FP_JOB_STATE_TO_PORTAL_STATE map as write(), so a portal job created for an already-confirmed (but not yet started) fp.job lands in 'received' instead of jumping to 'in_progress'. Falls back to 'received' for unmapped states. Co-Authored-By: Claude Opus 4.7 (1M context) --- fusion_plating/fusion_plating_jobs/models/fp_job.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fusion_plating/fusion_plating_jobs/models/fp_job.py b/fusion_plating/fusion_plating_jobs/models/fp_job.py index 3560b710..d1bca49b 100644 --- a/fusion_plating/fusion_plating_jobs/models/fp_job.py +++ b/fusion_plating/fusion_plating_jobs/models/fp_job.py @@ -1368,15 +1368,24 @@ class FpJob(models.Model): seq += 10 def _fp_create_portal_job(self): - """Create the fusion.plating.portal.job mirror record.""" + """Create the fusion.plating.portal.job mirror record. + + Initial state derived from the fp.job state via the same map + used by write() — so a job that's already 'in_progress' when + the portal mirror is created (e.g. a manual catch-up create) + doesn't reset to 'received'. + """ self.ensure_one() if self.portal_job_id: return # already exists — idempotent Portal = self.env['fusion.plating.portal.job'].sudo() + initial_state = self._FP_JOB_STATE_TO_PORTAL_STATE.get( + self.state, 'received', + ) portal = Portal.create({ 'name': self.name, 'partner_id': self.partner_id.id, - 'state': 'in_progress', + 'state': initial_state, 'x_fc_job_id': self.id, }) self.portal_job_id = portal.id