1
votes

I'm trying to implement this scenario on invoice lines.

Let's say I have 50 products on my invoice line, 40 products are tax affected, and 10 aren't.

So, in the result of my invoice, I have two fields to compute this

exe = fields.Float(string='Monto Exento', digits=dp.get_precision('Account'),
    store=True, readonly=True, compute='extras', track_visibility='always')

Should return the total of the 40 tax affected products, and this field

impo = fields.Float(string='Base Imponible', digits=dp.get_precision('Account'),
    store=True, readonly=True, compute='extras', track_visibility='always')

Should return the total of the 10 other products, which aren't tax affected.

Now, I call this from a function, and compute the results:

@api.one
@api.depends('invoice_line.price_subtotal', 'tax_line.amount')
def extras(self):
    self.exe = self.amount_untaxed + self.amount_tax
    self.impo = self.amount_untaxed + self.amount_tax

rec=0 

But it isn't working as expected, I don't know what could be wrong here, maybe it is because of how I'm handling this on extras function?

It just sums everything like the total amount of all the lines.

EDIT

Following @phillipstack answer, I've updated my code like this:

@api.one
@api.depends('invoice_line.price_subtotal', 'tax_line.amount')
def extras(self):
    self.exe = self.amount_untaxed + self.amount_tax if self.amount_tax and self.amount_tax > 0 else 0 
    self.impo = self.amount_untaxed + self.amount_tax if not self.amount_tax or self.amount_tax == 0 else 0  

But on impo field it just sums it all, taxed or not, I'm trying with one untaxed product, and one taxed.

On exe right it isn't showing any amount.

On exe it should show the total amount of untaxed products, and on impo it should show the total amount of taxed ones.

If You need more info please let me know.

1
Could you tell us on what model you are trying this? Seems to be account.invoice instead of sale.order? So you try to sum up values from invoice lines? - CZoellner
Yes it is account.invoice, but this is because the taxes come from there, sale.order also takes from account.invoice - NeoVe
I'm so sorry, this is on account.invoice, gotta edit my question, You know, when You so much work this things happen, lol - NeoVe
Done :), Sorry about the confusion, the question remains the same tho - NeoVe

1 Answers

1
votes

You need to provide an if statement to tell your script to not sum if it meets certain criteria. I dont know enough about your requirements however this might work. Or something like this.

@api.one
@api.depends('invoice_line.price_subtotal', 'tax_line.amount')
def extras(self):
    self.exe = self.amount_untaxed + self.amount_tax if self.amount_tax and self.amount_tax > 0 else 0 
    self.impo = self.amount_untaxed + self.amount_tax if not self.amount_tax or self.amount_tax == 0 else 0