How can i get the sum of more than one invoice?

232 Views Asked by At

Can someone help me to create a function for total invoice? This is my first test

@api.one  
@api.onchange('facture_ids.total_a_payer')     
def _invoice_total(self):
    if self.facture_ids.type=="npay":
        self.total_invoiced = sum(line.facture_ids.total_a_payer 
                                  for record in self.browse())
1

There are 1 best solutions below

0
On

You can simple change in @api.one to @api.multi because of @api.one is ony give a record but @api.multi is give a list of recorded set

and you function give a list of recorded set that's way you use the @api.multi and you can sum of more than one invoice

 @api.multi 
 @api.onchange('facture_ids.total_a_payer')     
 def _invoice_total(self):
     if self.facture_ids.type=="npay":
         self.total_invoiced = sum(line.facture_ids.total_a_payer 
                                   for record in self.browse())