48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Backfill one fp.certificate.part per existing certificate from its
|
|
# legacy singular fields, so pre-existing certs render identically under
|
|
# the new multi-part CoC. Lives in fusion_plating_jobs (not certificates)
|
|
# because it reads x_fc_job_id, a jobs-module field; the part-line table
|
|
# itself is created by the certificates upgrade, which runs first.
|
|
import logging
|
|
|
|
from odoo import api, SUPERUSER_ID
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
def migrate(cr, version):
|
|
env = api.Environment(cr, SUPERUSER_ID, {})
|
|
if 'fp.certificate.part' not in env:
|
|
return
|
|
certs = env['fp.certificate'].search([])
|
|
made = 0
|
|
for cert in certs:
|
|
if cert.part_line_ids:
|
|
continue
|
|
try:
|
|
pid = cert._fp_resolve_part_identity() # (number, name, serials)
|
|
except Exception:
|
|
pid = ('', '', '')
|
|
job = cert.x_fc_job_id if 'x_fc_job_id' in cert._fields else False
|
|
part = job.part_catalog_id if (job and 'part_catalog_id' in job._fields) else False
|
|
try:
|
|
desc = cert._fp_resolve_customer_facing_description() or cert.process_description or ''
|
|
except Exception:
|
|
desc = cert.process_description or ''
|
|
spec = cert.customer_spec_id if 'customer_spec_id' in cert._fields else False
|
|
env['fp.certificate.part'].create({
|
|
'certificate_id': cert.id, 'sequence': 10,
|
|
'part_catalog_id': part.id if part else False,
|
|
'part_number': cert.part_number or (pid[0] or ''),
|
|
'part_name': pid[1] or '',
|
|
'description': desc,
|
|
'serial': pid[2] or '',
|
|
'customer_spec_id': spec.id if spec else False,
|
|
'spec_reference': cert.spec_reference or '',
|
|
'quantity_shipped': cert.quantity_shipped or 0,
|
|
'nc_quantity': cert.nc_quantity or 0,
|
|
})
|
|
made += 1
|
|
_logger.info('fp.certificate.part backfill: created %s part-line(s)', made)
|