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.