# -*- 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, )