Skip to Content
Menu
This question has been flagged
1 Reply
1517 Views

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. 

Avatar
Discard
Author Best Answer

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.filtered(lambda x: not x.move_id.reversal_move_id and not x.move_id.reversed_entry_id).mapped('price_total'))
else:
record.billed_amount = 0.0

This works for me, especially in a case of multiple invoices and refunds. 

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
1486
1
Nov 24
1195
2
Sep 24
1047
1
Aug 24
2455
3
Aug 24
2687