Helloo Someone,
Below is a computed field that I use to show the total amount of all invoiced products from the Odoo sale order line.
billed_amount = fields.Float(string="Billed amount", compute="_get_billed_amount", store=True)
@api.depends('invoice_lines.price_total', 'invoice_lines', 'invoice_lines.move_id')
def _get_billed_amount(self):
for record in self:
if record.invoice_lines:
record.billed_amount = sum(record.invoice_lines.mapped('price_total'))
else:
record.billed_amount = 0.0
But now, the flaw of this code is that whenever an invoice is added to the credit note (or when the invoiced line has been refunded), instead of removing the amount or not doing anything, the value of the amount in the credit note also gets added to the billed_amount of invoiced quantity.
I want to be able to remove the invoices that were added to the credit note or prevent them from being added to the already existing invoice lines.
Thanks a lot.