43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright 2026 Nexa Systems Inc.
|
|
# License OPL-1 (Odoo Proprietary License v1.0)
|
|
# Part of the Fusion Plating product family.
|
|
|
|
import logging
|
|
|
|
from odoo import models
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class FpDelivery(models.Model):
|
|
"""Fire the 'final balance' invoice for Progress Billing / Net Terms
|
|
when a delivery is marked delivered.
|
|
"""
|
|
_inherit = 'fusion.plating.delivery'
|
|
|
|
def action_mark_delivered(self):
|
|
res = super().action_mark_delivered()
|
|
SaleOrder = self.env['sale.order']
|
|
# Sub 11 — MRP gone; resolve via delivery.job_ref → fp.job.name → fp.job.origin.
|
|
Job = self.env['fp.job'] if 'fp.job' in self.env else None
|
|
for delivery in self:
|
|
so = False
|
|
if delivery.job_ref and Job is not None:
|
|
job = Job.sudo().search(
|
|
[('name', '=', delivery.job_ref)], limit=1,
|
|
)
|
|
if job and job.origin:
|
|
so = SaleOrder.search(
|
|
[('name', '=', job.origin)], limit=1,
|
|
)
|
|
if not so:
|
|
continue
|
|
strategy = so.x_fc_invoice_strategy
|
|
if strategy not in ('progress', 'net_terms'):
|
|
continue
|
|
if so.invoice_status == 'invoiced':
|
|
continue
|
|
so._create_final_balance_invoice()
|
|
return res
|