I'm working on a custom tax module and am trying to use the existing
modules as a reference.
I've run into some snags trying to sort out exactly what I must
implement and how these methods are used.
The following is my attempt at documenting my current understanding of
the built-in tax modules using ``
tax.modules.no`` as a starting point
[1]. Please let me know if I've got anything wrong. Once I've got this
sorted out I will submit a patch to at least add docstrings to the
``
tax.modules.no`` module so it will hopefully be an easier to
understand starting point.
``by_product()`` is never called as far as I can tell. In fact,
searching through the project this method is merely defined on the
built-in tax modules and there is a similarly named method on
product.ProductPriceLookupManager. Perhaps I'm missing something?
``by_orderitem()`` is only used by ``OrderItem.update_tax()`` to
calculate the total tax for the given quantity of an ``OrderItem``
object.
``by_price()`` is used in several places to calculate the tax on
whatever price is passed in. If you have a tax rate, this should just
return rate * price.
``shipping()`` is only used internally in the ``area`` tax module in
the ``process()`` method so one could optionally calculate tax on the
shipping charges.
``process()`` appears to only be called in
``satchmo_store.shop.Order.force_recalculate_total()``. This method is
apparently required to return a tuple where the first element is the
tax amount expressed as a Decimal object. The second element of the
tuple is expected to be a dictionary which can be empty or optionally
contain taxClass names as keys and their respective rates as values.
``get_percent()`` is only used by the ``tax_rate`` template tag for
display purposes. Seems we could just have the template tag use
``get_rate()`` and push the display logic down to the tag?
``get_rate()`` is never called externally, only some of the processors
call this method internally in other 'public' methods. The ``percent``
module defines ``get_rate()`` but this is never called internally or
otherwise.
Judging from some of the modules, ``get_rate()`` should return
something like Decimal("0.0825") while ``get_percent()`` should return
something like Decimal("8.25"). Does that sound about right? The
naming is a bit confusing as ``get_rate()`` often returns a config
option like ``Decimal(config_value('TAX','PERCENT'))`` or an attribute
like ``rate.percentage``.
Thanks,
John-Scott
[1]
http://bitbucket.org/chris1610/satchmo/src/tip/satchmo/apps/tax/modules/no/processor.py