changes
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
{
|
||||
'name': 'Fusion Plating — Native Jobs',
|
||||
'version': '19.0.10.16.8',
|
||||
'version': '19.0.10.16.9',
|
||||
'category': 'Manufacturing/Plating',
|
||||
'summary': 'Native plating job model — replaces mrp.production / mrp.workorder bridge.',
|
||||
'author': 'Nexa Systems Inc.',
|
||||
|
||||
@@ -1675,34 +1675,73 @@ class FpJob(models.Model):
|
||||
look up by job_ref. Setting both ends keeps every consumer
|
||||
happy.
|
||||
|
||||
Phase A — mirrors x_fc_carrier_id and x_fc_outbound_shipment_id
|
||||
from the linked receiving so the delivery carries the shipping
|
||||
choices made at receipt time. Shipping crew can override later.
|
||||
Auto-populates everything we can resolve from upstream
|
||||
records so the shipping crew doesn't have to re-type
|
||||
addresses / contacts / dates that already exist on the SO:
|
||||
- delivery_address_id, contact_name, contact_phone — SO's
|
||||
partner_shipping_id (falls back to partner_id)
|
||||
- scheduled_date — SO.commitment_date
|
||||
- source_facility_id — job.facility_id
|
||||
- x_fc_carrier_id, x_fc_outbound_shipment_id — from the
|
||||
SO's first receiving record (set at receive time)
|
||||
- coc_attachment_id — issued cert.attachment_id for this
|
||||
job (if a CoC is already issued before delivery exists;
|
||||
otherwise the cert's action_issue back-fills it later)
|
||||
|
||||
Everything skips silently when the source field doesn't
|
||||
exist or the source value is blank, so older install
|
||||
topologies and partially-configured jobs still get a
|
||||
delivery — just less pre-filled.
|
||||
"""
|
||||
self.ensure_one()
|
||||
if self.delivery_id:
|
||||
return
|
||||
Delivery = self.env['fusion.plating.delivery'].sudo()
|
||||
vals = self._fp_resolve_delivery_defaults(Delivery)
|
||||
try:
|
||||
delivery = Delivery.create(vals)
|
||||
self.delivery_id = delivery.id
|
||||
except Exception as e:
|
||||
_logger.warning(
|
||||
"Job %s: failed to auto-create delivery: %s", self.name, e,
|
||||
)
|
||||
|
||||
def _fp_resolve_delivery_defaults(self, Delivery):
|
||||
"""Build the create-vals for a fresh delivery, OR the
|
||||
write-vals for refreshing an existing one. Centralised so
|
||||
the create path, the per-cert post-issue sync, and any
|
||||
future 'Refresh from Source' button all stay consistent.
|
||||
"""
|
||||
self.ensure_one()
|
||||
vals = {'partner_id': self.partner_id.id}
|
||||
if 'x_fc_job_id' in Delivery._fields:
|
||||
vals['x_fc_job_id'] = self.id
|
||||
if 'job_ref' in Delivery._fields:
|
||||
vals['job_ref'] = self.name
|
||||
if 'x_fc_job_id' not in Delivery._fields \
|
||||
and 'job_ref' not in Delivery._fields:
|
||||
_logger.warning(
|
||||
"Job %s: fusion.plating.delivery has no job link field; "
|
||||
"delivery created without job back-reference.", self.name,
|
||||
)
|
||||
# Mirror outbound carrier + shipment from the SO's first
|
||||
# receiving record. If there are multiple receivings (split
|
||||
# shipments), the shipping crew can change either field on the
|
||||
# delivery form. Defensive: skip when fields aren't present
|
||||
# (older instance) or no receiving exists.
|
||||
if (self.sale_order_id
|
||||
and 'x_fc_receiving_ids' in self.sale_order_id._fields
|
||||
and self.sale_order_id.x_fc_receiving_ids):
|
||||
recv = self.sale_order_id.x_fc_receiving_ids[:1]
|
||||
# Delivery address + contact details from the SO. shipping
|
||||
# partner is preferred (that's where parts physically go);
|
||||
# fall back to the SO's main partner when no separate ship-to.
|
||||
so = self.sale_order_id
|
||||
ship_to = (so.partner_shipping_id or so.partner_id) if so else False
|
||||
if ship_to:
|
||||
if 'delivery_address_id' in Delivery._fields:
|
||||
vals['delivery_address_id'] = ship_to.id
|
||||
if 'contact_name' in Delivery._fields and ship_to.name:
|
||||
vals['contact_name'] = ship_to.name
|
||||
if 'contact_phone' in Delivery._fields:
|
||||
vals['contact_phone'] = ship_to.phone or ship_to.mobile or ''
|
||||
# Scheduled date — operator can adjust; this just primes it
|
||||
# so they're not staring at a blank field.
|
||||
if so and so.commitment_date and 'scheduled_date' in Delivery._fields:
|
||||
vals['scheduled_date'] = so.commitment_date
|
||||
# Source facility comes from the job (where it was plated).
|
||||
if self.facility_id and 'source_facility_id' in Delivery._fields:
|
||||
vals['source_facility_id'] = self.facility_id.id
|
||||
# Outbound carrier + shipment mirrored from the SO's first
|
||||
# receiving record (the crew chose these at receipt time).
|
||||
if (so and 'x_fc_receiving_ids' in so._fields
|
||||
and so.x_fc_receiving_ids):
|
||||
recv = so.x_fc_receiving_ids[:1]
|
||||
if 'x_fc_carrier_id' in Delivery._fields \
|
||||
and 'x_fc_carrier_id' in recv._fields \
|
||||
and recv.x_fc_carrier_id:
|
||||
@@ -1713,13 +1752,21 @@ class FpJob(models.Model):
|
||||
vals['x_fc_outbound_shipment_id'] = (
|
||||
recv.x_fc_outbound_shipment_id.id
|
||||
)
|
||||
try:
|
||||
delivery = Delivery.create(vals)
|
||||
self.delivery_id = delivery.id
|
||||
except Exception as e:
|
||||
_logger.warning(
|
||||
"Job %s: failed to auto-create delivery: %s", self.name, e,
|
||||
)
|
||||
# CoC PDF — if a cert for this job is already issued and
|
||||
# the delivery field accepts an attachment, link it. The
|
||||
# cert's action_issue also calls _fp_sync_to_delivery for
|
||||
# the case where the cert issues AFTER the delivery exists.
|
||||
Cert = self.env.get('fp.certificate')
|
||||
if Cert is not None and 'coc_attachment_id' in Delivery._fields:
|
||||
issued_cert = Cert.sudo().search([
|
||||
('x_fc_job_id', '=', self.id),
|
||||
('certificate_type', '=', 'coc'),
|
||||
('state', '=', 'issued'),
|
||||
('attachment_id', '!=', False),
|
||||
], order='issue_date desc, id desc', limit=1)
|
||||
if issued_cert and issued_cert.attachment_id:
|
||||
vals['coc_attachment_id'] = issued_cert.attachment_id.id
|
||||
return vals
|
||||
|
||||
def _fp_create_certificates(self):
|
||||
"""Auto-create one draft fp.certificate per type returned by
|
||||
|
||||
Reference in New Issue
Block a user