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) <noreply@anthropic.com>
This commit is contained in:
gsinghpal
2026-05-17 03:16:22 -04:00
parent 28220f0732
commit f8586611c9

View File

@@ -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