changes
This commit is contained in:
@@ -202,9 +202,9 @@ class FpJob(models.Model):
|
||||
job.racking_inspection_state = ri.state if ri else False
|
||||
|
||||
def action_view_racking_inspection(self):
|
||||
"""Open the racking inspection. Auto-create if missing (e.g. job
|
||||
was created before Sub 8 shipped, or auto-create silently failed
|
||||
at action_confirm time)."""
|
||||
"""Open the racking inspection. Auto-create if missing, or seed
|
||||
lines from the SO if it exists but was created before line auto-
|
||||
seeding shipped (the helper handles both cases idempotently)."""
|
||||
self.ensure_one()
|
||||
if 'fp.racking.inspection' not in self.env:
|
||||
from odoo.exceptions import UserError
|
||||
@@ -212,9 +212,12 @@ class FpJob(models.Model):
|
||||
'Sub 8 racking inspection module not installed. '
|
||||
'Install fusion_plating_receiving to enable.'
|
||||
))
|
||||
if not self.racking_inspection_id:
|
||||
self._fp_create_racking_inspection()
|
||||
self.invalidate_recordset(['racking_inspection_ids'])
|
||||
# Always call the helper — it short-circuits for already-populated
|
||||
# draft inspections and creates fresh ones when missing. This is
|
||||
# also the entry point that backfills lines on inspections that
|
||||
# pre-date the line-seeding feature.
|
||||
self._fp_create_racking_inspection()
|
||||
self.invalidate_recordset(['racking_inspection_ids'])
|
||||
ri = self.racking_inspection_id or self.racking_inspection_ids[:1]
|
||||
if not ri:
|
||||
from odoo.exceptions import UserError
|
||||
@@ -239,11 +242,39 @@ class FpJob(models.Model):
|
||||
'context': {'default_job_id': self.id},
|
||||
}
|
||||
|
||||
def action_finish_current_step(self):
|
||||
"""Steelhead-style header button: finish whatever's currently
|
||||
in_progress and auto-start the next pending/ready step. If
|
||||
nothing is running yet, start the lowest-sequence pending step
|
||||
instead — operator's first click on a fresh job just begins
|
||||
the line.
|
||||
"""
|
||||
self.ensure_one()
|
||||
running = self.step_ids.filtered(lambda s: s.state == 'in_progress')[:1]
|
||||
if running:
|
||||
return running.action_finish_and_advance()
|
||||
# No running step — kick off the first pending/ready one.
|
||||
first = self.step_ids.filtered(
|
||||
lambda s: s.state in ('pending', 'ready', 'paused')
|
||||
).sorted('sequence')[:1]
|
||||
if not first:
|
||||
raise UserError(_(
|
||||
'No runnable step found on this job — either every step '
|
||||
'is done or the job is still in draft.'
|
||||
))
|
||||
first.with_context(fp_skip_predecessor_check=True).button_start()
|
||||
self.message_post(body=_(
|
||||
'Started first step "%s".'
|
||||
) % first.name)
|
||||
return True
|
||||
|
||||
def action_open_move_wizard(self):
|
||||
"""Header button — opens the Move wizard pre-filled with the
|
||||
currently in-progress (or most recently in-progress) step as the
|
||||
from-step. Lets the manager move the job forward without first
|
||||
clicking into a specific step row.
|
||||
"""Original Move wizard — kept available for cross-station moves
|
||||
and rework / scrap transfers. The simple "finish current → start
|
||||
next" flow is now action_finish_current_step (header button).
|
||||
|
||||
Opens the wizard pre-filled with the currently in-progress (or
|
||||
most recently in-progress) step as the from-step.
|
||||
"""
|
||||
self.ensure_one()
|
||||
active_step = self.step_ids.filtered(
|
||||
@@ -871,6 +902,9 @@ class FpJob(models.Model):
|
||||
production_id too so legacy reports keep working.
|
||||
|
||||
Idempotent — if an inspection already exists for this job, skip.
|
||||
Either way the inspection's lines are seeded from the SO's
|
||||
plating order lines so the racker walks into a pre-populated
|
||||
checklist instead of an empty form.
|
||||
"""
|
||||
self.ensure_one()
|
||||
if 'fp.racking.inspection' not in self.env:
|
||||
@@ -883,17 +917,62 @@ class FpJob(models.Model):
|
||||
('x_fc_job_id', '=', self.id),
|
||||
], limit=1)
|
||||
if existing:
|
||||
# Self-heal: pre-existing inspections from before line seeding
|
||||
# was added show up empty. Top them up now if still empty +
|
||||
# the inspection isn't already finalised (don't rewrite history).
|
||||
if not existing.line_ids and existing.state == 'draft':
|
||||
self._fp_seed_racking_lines(existing)
|
||||
return
|
||||
# Phase 6 (Sub 11) — production_id retired; bind by x_fc_job_id only.
|
||||
vals = {'x_fc_job_id': self.id}
|
||||
try:
|
||||
Inspection.create(vals)
|
||||
insp = Inspection.create(vals)
|
||||
self._fp_seed_racking_lines(insp)
|
||||
except Exception as e:
|
||||
_logger.warning(
|
||||
"Job %s: failed to auto-create racking inspection: %s",
|
||||
self.name, e,
|
||||
)
|
||||
|
||||
def _fp_seed_racking_lines(self, inspection):
|
||||
"""Populate the inspection with one line per SO plating order line.
|
||||
|
||||
Walks sale_order_line_ids (the M2M of SO lines tied to this job),
|
||||
falling back to the linked SO's order_line. Each line carries the
|
||||
part_catalog and the quoted qty as the expected count — the
|
||||
racker confirms or amends on the floor.
|
||||
"""
|
||||
self.ensure_one()
|
||||
if not inspection or inspection.line_ids:
|
||||
return
|
||||
Line = self.env['fp.racking.inspection.line'].sudo()
|
||||
# Source preference: explicit M2M of plating lines bound to this
|
||||
# job (fast-order multi-part jobs), falling back to the SO header.
|
||||
so_lines = self.sale_order_line_ids
|
||||
if not so_lines and self.sale_order_id:
|
||||
so_lines = self.sale_order_id.order_line
|
||||
plating_lines = so_lines.filtered(
|
||||
lambda l: l.x_fc_part_catalog_id and not l.display_type
|
||||
)
|
||||
if not plating_lines:
|
||||
return
|
||||
seq = 10
|
||||
for sol in plating_lines:
|
||||
try:
|
||||
Line.create({
|
||||
'inspection_id': inspection.id,
|
||||
'sequence': seq,
|
||||
'part_catalog_id': sol.x_fc_part_catalog_id.id,
|
||||
'qty_expected': int(sol.product_uom_qty or 0),
|
||||
'condition': 'ok',
|
||||
})
|
||||
except Exception as e:
|
||||
_logger.warning(
|
||||
"Job %s: failed to seed racking line for SO line %s: %s",
|
||||
self.name, sol.id, e,
|
||||
)
|
||||
seq += 10
|
||||
|
||||
def _fp_create_portal_job(self):
|
||||
"""Create the fusion.plating.portal.job mirror record."""
|
||||
self.ensure_one()
|
||||
|
||||
Reference in New Issue
Block a user