Files
Odoo-Modules/fusion_plating/fusion_plating_receiving/migrations/19.0.3.19.0/post-migrate.py
gsinghpal 2645db40a2 fix(receiving): propagate qty_received to fp.job + drop duplicate carrier field
Bug surfaced on WO-30043 (2026-05-20): operator walked every step
including a fully closed receiving record, then hit
"Quantity Received is blank — close the receiving record for
SO SO-30043 before completing this job." Receiving WAS closed.

Root cause: the 2026-05-18 cert-creation gate
(fp.job.button_mark_done) blocks on job.qty_received but nothing
populated it. fp.receiving carried the qty on its line records,
fp.job stayed at 0 indefinitely. Two disconnected records on the
same SO.

Fix: when fp.receiving._update_so_receiving_status runs (i.e. on
every state transition — counted / staged / closed / accepted /
resolved), also mirror each line's received_qty onto the matching
fp.job by (sale_order_id + part_catalog_id). Single-part SOs map
1-to-1; multi-part SOs spawn one job per line so the same join
still works.

Two defensive guards in the hook:
- Skip silently when fusion_plating_jobs not installed
  (Job = env.get('fp.job') returns None).
- Skip silently when fp.job doesn't yet carry part_catalog_id /
  qty_received (test scope, unusual install topology).

Drive-by during cleanup:
- fp_parent_numbered_mixin._fp_assign_parent_name: guard
  so.x_fc_parent_number access with field-existence check. The
  column lives in fusion_plating_jobs; downstream modules that
  inherit the mixin (receiving) but don't depend on jobs were
  hitting AttributeError on every fp.receiving.create at test
  time. Falls through to the legacy sequence when the column
  isn't there.

- fp_receiving_views.xml: legacy carrier_name Char field rendered
  as a second carrier row labeled "Legacy Carrier" alongside the
  proper x_fc_carrier_id M2O — operators saw two carrier fields
  and got confused. Hide the legacy display (data stays in DB for
  audit; migration 19.0.3.10.0 already matched it to a real
  delivery.carrier).

Migration 19.0.3.19.0/post-migrate.py backfills qty_received from
closed receiving lines for any job stuck at 0 — fixes WO-30043
and two sibling jobs on entech.

Modules: fusion_plating 19.0.20.2.0, fusion_plating_receiving
19.0.3.19.0, fusion_plating_jobs 19.0.10.15.0.

All 19 tests green (TestCarrierFields 6, TestQtyReceivedPropagation 5
new, TestReceivingGate 8). Direct verification on entech: WO-30043
qty_received = 1, mark_done succeeds, delivery + cert auto-created.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-19 22:15:46 -04:00

45 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
# Copyright 2026 Nexa Systems Inc.
# License OPL-1 (Odoo Proprietary License v1.0)
#
# Backfill fp.job.qty_received from closed fp.receiving lines.
#
# Triggering issue (2026-05-20): WO-30043 — and any other job created
# before the new _update_job_qty_received hook shipped — has
# qty_received=0 even though its receiving is closed. The
# button_mark_done gate then blocks the operator with no obvious next
# step ("Quantity Received is blank — close the receiving record...").
# Receiving IS closed. The propagation was missing.
#
# This migration walks every (closed / accepted / resolved) receiving,
# matches lines to their corresponding fp.job by (sale_order_id +
# part_catalog_id), and writes received_qty onto the job. Idempotent.
import logging
_logger = logging.getLogger(__name__)
def migrate(cr, version):
"""Backfill fp.job.qty_received from already-closed receivings."""
# Match by SO + part_catalog. Same logic as the new runtime hook.
cr.execute("""
UPDATE fp_job j
SET qty_received = rl.received_qty
FROM fp_receiving r
JOIN fp_receiving_line rl ON rl.receiving_id = r.id
WHERE r.state IN ('closed', 'accepted', 'resolved')
AND r.sale_order_id = j.sale_order_id
AND rl.part_catalog_id = j.part_catalog_id
AND (j.qty_received IS NULL OR j.qty_received = 0)
AND rl.received_qty IS NOT NULL
AND rl.received_qty > 0
""")
updated = cr.rowcount
if updated:
_logger.info(
'fp.job.qty_received backfilled from receiving lines on '
'%d job(s) — fixes WO-30043 and any sibling stuck jobs.',
updated,
)