I need to filter component tax lines so they can be reported at mandated levels (see previous topic for context). The way I have approached this is to save a reporting code on each account.tax.line
since the level depends on the day of the transaction and the customer’s shipping address. For the Open Tax Code wizard I use a search domain, and this is working great to get the correct lines for a tax code. But for the Chart of Tax Codes, I have taken the approach of storing the reporting code in the transaction context so it is available to the Tax._amount_where()
clause. This works if I set the context from a class method (e.g. TaxCode.get_amount()
), but if I set it from an instance property (TaxCodeLine.value
) where it needs to be set, the reporting code is missing from the context when I need it (Tax._amount_where()
, another class method). I have noticed that another transaction is created when the query is run on the Tax.get_amount
(a Function.getter) but I’m not sure whether that is related to the problem.
I’m new to Tryton and Python in general, so any help would be appreciated. I’m sure I am missing something obvious. Thanks in advance!
Here are some simplified code excerpts to show what I am trying to accomplish:
class Tax(metaclass=PoolMeta):
__name__ = 'account.tax'
@classmethod
def _amount_where(cls, tax_line, move_line, move):
context = Transaction().context
reporting_code = context.get('reporting_code')
if reporting_code:
return where & (tax_line.code == reporting_code)
else:
return where
class TaxCodeLine(metaclass=PoolMeta):
__name__ = 'account.tax.code.line'
@property
def value(self):
with Transaction().set_context(reporting_code=self.code.code):
v = super().value
return v