changes
This commit is contained in:
@@ -102,6 +102,79 @@ class FpPortalJob(models.Model):
|
||||
tracking_ref = fields.Char(
|
||||
string='Tracking Reference',
|
||||
)
|
||||
x_fc_tracking_url = fields.Char(
|
||||
string='Tracking URL',
|
||||
compute='_compute_x_fc_tracking_url',
|
||||
help='Resolved carrier tracking URL with the tracking number '
|
||||
'substituted. Used by the portal template to render the '
|
||||
'tracking_ref as a clickable link. Walks portal job → '
|
||||
'fp.job → sale_order → fp.receiving → carrier.',
|
||||
)
|
||||
|
||||
@api.depends('tracking_ref')
|
||||
def _compute_x_fc_tracking_url(self):
|
||||
Job = self.env.get('fp.job')
|
||||
for rec in self:
|
||||
url = ''
|
||||
if rec.tracking_ref and Job is not None:
|
||||
job = Job.sudo().search(
|
||||
[('portal_job_id', '=', rec.id)], limit=1,
|
||||
)
|
||||
so = job.sale_order_id if job else False
|
||||
recv = (
|
||||
so.x_fc_receiving_ids[:1]
|
||||
if so and 'x_fc_receiving_ids' in so._fields else False
|
||||
)
|
||||
carrier = (
|
||||
recv.x_fc_carrier_id
|
||||
if recv and 'x_fc_carrier_id' in recv._fields else False
|
||||
)
|
||||
tpl = (carrier.tracking_url or '') if carrier else ''
|
||||
if tpl:
|
||||
placeholder = '<shipmenttrackingnumber>'
|
||||
if placeholder in tpl:
|
||||
url = tpl.replace(placeholder, rec.tracking_ref)
|
||||
else:
|
||||
url = tpl + rec.tracking_ref
|
||||
rec.x_fc_tracking_url = url
|
||||
|
||||
# ---- Tracking history exposure ----------------------------------------
|
||||
# Pulls fusion.tracking.event records from the outbound shipment linked
|
||||
# via fp.job → fp.receiving → x_fc_outbound_shipment_id. Used by the
|
||||
# portal job page to render a timeline of carrier scan events.
|
||||
x_fc_tracking_event_ids = fields.Many2many(
|
||||
'fusion.tracking.event',
|
||||
string='Tracking Events',
|
||||
compute='_compute_x_fc_tracking_event_ids',
|
||||
)
|
||||
|
||||
@api.depends('tracking_ref')
|
||||
def _compute_x_fc_tracking_event_ids(self):
|
||||
Job = self.env.get('fp.job')
|
||||
Event = self.env.get('fusion.tracking.event')
|
||||
empty = self.env['fusion.tracking.event'] if Event is not None else None
|
||||
for rec in self:
|
||||
events = empty
|
||||
if Event is not None and Job is not None and rec.tracking_ref:
|
||||
job = Job.sudo().search(
|
||||
[('portal_job_id', '=', rec.id)], limit=1,
|
||||
)
|
||||
so = job.sale_order_id if job else False
|
||||
recv = (
|
||||
so.x_fc_receiving_ids[:1]
|
||||
if so and 'x_fc_receiving_ids' in so._fields else False
|
||||
)
|
||||
ship = (
|
||||
recv.x_fc_outbound_shipment_id
|
||||
if recv and 'x_fc_outbound_shipment_id' in recv._fields
|
||||
else False
|
||||
)
|
||||
if ship:
|
||||
events = ship.tracking_event_ids.sorted(
|
||||
key=lambda e: e.event_datetime or fields.Datetime.now(),
|
||||
reverse=True,
|
||||
)
|
||||
rec.x_fc_tracking_event_ids = events
|
||||
coc_attachment_id = fields.Many2one(
|
||||
'ir.attachment',
|
||||
string='Certificate of Conformance',
|
||||
|
||||
Reference in New Issue
Block a user