Lot invoicing + fee padding

This commit is contained in:
2026-06-23 13:12:37 +02:00
parent ef8d914820
commit fbf3842e6c
3 changed files with 200 additions and 10 deletions

View File

@@ -130,13 +130,43 @@ class Invoice(metaclass=PoolMeta):
lots[getattr(lot, 'id', id(lot))] = lot
return list(lots.values())
@classmethod
def _fee_updates_on_delete(cls, invoices):
reset_fees = {}
clear_dn_cn_fees = {}
for invoice in invoices:
if getattr(invoice, 'number', None):
continue
invoice_id = getattr(invoice, 'id', None)
for line in getattr(invoice, 'lines', None) or []:
fee = getattr(line, 'fee', None)
if not fee:
continue
fee_key = getattr(fee, 'id', None) or id(fee)
dn_cn = getattr(fee, 'dn_cn', None)
dn_cn_id = getattr(dn_cn, 'id', dn_cn)
if invoice_id and dn_cn_id == invoice_id:
clear_dn_cn_fees[fee_key] = fee
else:
reset_fees[fee_key] = fee
return list(reset_fees.values()), list(clear_dn_cn_fees.values())
@classmethod
def delete(cls, invoices):
Lot = Pool().get('lot.lot')
Fee = Pool().get('fee.fee')
padding_lots = cls._sale_padding_lots_to_clear_on_delete(invoices)
reset_fees, clear_dn_cn_fees = cls._fee_updates_on_delete(invoices)
super().delete(invoices)
if padding_lots:
Lot.write(padding_lots, {'sale_invoice_padding': Decimal(0)})
if reset_fees:
Fee.write(reset_fees, {
'state': 'not invoiced',
'dn_cn': None,
})
if clear_dn_cn_fees:
Fee.write(clear_dn_cn_fees, {'dn_cn': None})
def do_lot_invoicing(self):
super().do_lot_invoicing()