This commit is contained in:
2026-03-26 15:43:45 +01:00
parent f9010ddefd
commit 3e5320cf9e
4 changed files with 201 additions and 9 deletions

View File

@@ -7,6 +7,8 @@ class Invoice(metaclass=PoolMeta):
__name__ = 'account.invoice'
def _get_report_sale(self):
# Bridge invoice templates to the originating sale so FODT files can
# reuse stable sale.report_* properties instead of complex expressions.
sales = list(self.sales or [])
return sales[0] if sales else None
@@ -15,6 +17,24 @@ class Invoice(metaclass=PoolMeta):
if sale and sale.lines:
return sale.lines[0]
def _get_report_lot(self):
line = self._get_report_sale_line()
if line and line.lots:
for lot in line.lots:
if lot.lot_type == 'physic':
return lot
return line.lots[0]
def _get_report_shipment(self):
lot = self._get_report_lot()
if not lot:
return None
return (
getattr(lot, 'lot_shipment_in', None)
or getattr(lot, 'lot_shipment_out', None)
or getattr(lot, 'lot_shipment_internal', None)
)
@property
def report_address(self):
sale = self._get_report_sale()
@@ -111,3 +131,61 @@ class Invoice(metaclass=PoolMeta):
if net == '':
return ''
return Decimal(net) * Decimal('2.20462')
@property
def report_bl_date(self):
shipment = self._get_report_shipment()
if shipment:
return shipment.bl_date
@property
def report_loading_port(self):
shipment = self._get_report_shipment()
if shipment and shipment.from_location:
return shipment.from_location.rec_name
return ''
@property
def report_discharge_port(self):
shipment = self._get_report_shipment()
if shipment and shipment.to_location:
return shipment.to_location.rec_name
return ''
@property
def report_incoterm(self):
sale = self._get_report_sale()
if not sale:
return ''
incoterm = sale.incoterm.code if sale.incoterm else ''
location = sale.incoterm_location.party_name if sale.incoterm_location else ''
if incoterm and location:
return f"{incoterm} {location}"
return incoterm or location
@property
def report_proforma_invoice_number(self):
lot = self._get_report_lot()
if lot and lot.sale_invoice_line_prov and lot.sale_invoice_line_prov.invoice:
return lot.sale_invoice_line_prov.invoice.number or ''
return ''
@property
def report_proforma_invoice_date(self):
lot = self._get_report_lot()
if lot and lot.sale_invoice_line_prov and lot.sale_invoice_line_prov.invoice:
return lot.sale_invoice_line_prov.invoice.invoice_date
@property
def report_controller_name(self):
shipment = self._get_report_shipment()
if shipment and shipment.controller:
return shipment.controller.rec_name
return ''
@property
def report_si_number(self):
shipment = self._get_report_shipment()
if shipment:
return shipment.number or ''
return ''