I’m trying to add a new customized report based on invoice.fodt (module account_invoice), and I have a different columns for prints taxes lines, if the products has a 5% tax rate go on first column, 10% second column… so I did a simple IF to prints it or not.
But it doesn’t work, I don’t know why its doesn’t match and nothing is printed. I tried to print only tax.rate just to see its value, and it shows me 0.05.
This is because 0.05 as float is not really 0.05 like Decimal('0.05') is. You must compare against Decimal('0.05') but you will need to add Decimal to the context.
But maybe it is better to add a flag on the tax Model such that you can make the distinction between each taxes.
I will try with the flag, but If I try using Decimal how can I adding it to the context, because now is showing an error because it. I have to put a import inside a input placeholder into the fodt file?
And just to know, the language using by the report what is its name? not exists a way to compare derectly floats like tax.rate == 0.05f or something like that?
Just to be extra clear, the problem you are having is because tax.rate is not a float, it’s a Python Decimal. So when you compare it to a float like 0.05 it is never the same.
As a last resort and work around if you are unable, or unwilling, to use one of the methods already suggested, then you might be able to convert it to a string and then do a string comparison.
Something like tax.rate.to_eng_string() == '0.05', but I haven’t tested this so it might not work.
So, I keep the original and my report as a second choice. I created a invoice_py.py file too who inherit invoice.py but here I don’t called Report module my whole imported are
import datetime
from sql import Literal
from sql.aggregate import Count
from trytond.i18n import gettext
from trytond.model.fields import field
from trytond.pool import Pool, PoolMeta
from trytond.model import ModelSQL, ModelView, fields, Unique
from trytond.pyson import Eval, Bool
from trytond.exceptions import UserError
from trytond.transaction import Transaction
__all__ = [
'Stamped',
'Establishment',
'ShippingPoint',
'Invoice',
'Sale',
]