taler-docs

Documentation for GNU Taler components, APIs and protocols
Log | Files | Refs | README | LICENSE

078-taxes.rst (12491B)


      1 DD 78: Taxes
      2 ############
      3 
      4 Summary
      5 =======
      6 
      7 We've received various requests for the merchant backend to provide
      8 transaction reports for accountants. While not always stated explicitly, we
      9 believe this is largely also related to tax reporting. This document explains
     10 the plan for how we intend to deal with periodic reporting.
     11 
     12 Motivation
     13 ==========
     14 
     15 Making tax-reporting easy for merchants will lower the barrier for them to
     16 adopt GNU Taler.  Furthermore, customers will often require receipts which
     17 state the specific tax amounts that were paid, so including tax information in
     18 digital receipts (and thus the Taler contracts) is important.  The current
     19 situation where taxes are specified per-product is not great, as a merchant
     20 would have to update all products if a tax-percentage were to change, and also
     21 has to re-calculate the tax every time a product price changes.
     22 
     23 
     24 Requirements
     25 ============
     26 
     27 * Deal with the complexity of tax calculations across different jurisdictions.
     28   Sure, we may not cover all cases globally, but we should at least cover the
     29   most common scenarios.  This likely includes different ways how taxes
     30   should be computed in terms of rounding, and computing taxes given
     31   prices in gross or net amounts.
     32 * Make it as easy as possible for the merchant to manage taxes.  If possible,
     33   have some backend-wide defaults so that merchants do not have to enter
     34   common taxes that apply across the currency domain.
     35 * Ensure customers get correct tax receipts as part of their contracts.
     36 * Incorporate the tax data when informing the merchant about their transaction
     37   history, including showing which taxes applied to which purchases so that
     38   merchants can easily account for applicable taxes.
     39 * Treat *donations* and *gifts* as a special-cases as again special tax
     40   rules likely apply.
     41 * A single product may have multiple applicable taxes (say VAT and luxury
     42   tax).
     43 * A single order may contain multiple products (some with known tax
     44   rules and others without) and thus a mix of applicable taxes.
     45 * A merchant may need to override or adapt the tax details for each
     46   order, for example because reverse VAT rules may shift the responsibility
     47   to pay taxes to the buyer.
     48 
     49 
     50 Proposed Solution
     51 =================
     52 
     53 We borrow ideas from ERPnext.
     54 
     55 Phase 1: Products groups
     56 ------------------------
     57 
     58 This is inspired by ERPnext's "item groups".
     59 
     60 A **product group** allows multiple products to be treated in the
     61 same way for accounting and tax purposes, avoiding the need to
     62 configure each product individually.
     63 
     64 There can only be one group per product, all products that are not explicitly
     65 in a group should be in some ``__default__`` group that always exists. The
     66 product groups will be used for sales statistics (revenue per group) and will
     67 be the basis for associating taxes with products in the next phase(s).
     68 
     69 Unlike categories, product group membership is mutually exclusive and not used
     70 for the point-of-sale app display. Re-using categories would confuse a feature
     71 for taxes/accounting with a feature for user-interfaces of sales people.
     72 
     73 * Add a ``product_group`` table with:
     74 
     75      (0) product group serial number
     76      (1) instance ID (foreign key)
     77      (2) product group name (unique with instance ID)
     78      (3) product group description
     79 
     80 * Expand ``inventory_products`` table with:
     81 
     82      (1) product group serial number (foreign key), allow NULL for default
     83      (2) price_is_net boolean flag to indicate if the given price is the net
     84          price and all taxes should be added on top of it, or if it is a
     85          fixed retail price and the merchant covers all applicable taxes,
     86          at the expense of profits if taxes vary (for example, to preserve
     87          the price structure even if taxes vary between dine-in and take-out).
     88 
     89 
     90 Phase 2: Money pots
     91 -------------------
     92 
     93 This is inspired by ERPnext's "accounts".
     94 
     95 A **money pot** allow users aggregate amounts over time periods for accounting.
     96 
     97 Money pots can be for different types of taxes, but also for tips or to
     98 separate out different kinds of internal accounts as well as fees paid to the
     99 exchange.
    100 
    101 When an order is created, the total amount paid by the customer will be split
    102 into the various money pots based on rules that can be given per product,
    103 product group or taxes, and also later overriden explicitly in the contract
    104 terms.
    105 
    106 The increments to the various pots will also be shown in the various accounting
    107 statistics.
    108 
    109 * Add a ``money_pot`` table with:
    110 
    111      (0) money pot serial number
    112      (1) instance ID (foreign key)
    113      (2) money pot name (unique with instance ID)
    114      (3) money pot description
    115      (4) money pot total amount
    116 
    117 * Code should update statistics whenever the money pot
    118   total amount is incremented.
    119 
    120 
    121 
    122 Phase 3: Tax Class
    123 ------------------
    124 
    125 This is inspired by ERPnext's "item tax templates".
    126 
    127 A **tax class** specifies a possible tax and how it is to be calculated for a
    128 given product or order.
    129 
    130 * Add a ``tax_class`` table with:
    131 
    132     (0) tax class serial number
    133     (1) instance ID (foreign key)
    134     (2) tax class name (unique with instance ID)
    135     (3) tax rate (percentage), for taxes charged per value
    136     (4) charge amount (multiplied with quantity of the product,
    137         for example for tourist overnight tax per night,
    138         for taxes charged per unit and not per value)
    139     (5) tax description
    140     (6) i18n description
    141     (7) calculation mode (net total, cummulative)
    142     (8) rounding mode (up, down, nearest)
    143     (9) rounding unit (amount)
    144     (10) money pot (where to accumulate taxes paid under this tax class).
    145     to track known tax rules. Unique should be "instance+tax class name".
    146 
    147 * When "rounding up" is used, round up from net to gross, but round
    148   down from gross to net. Similarly, when "rounding down" is used,
    149   round down from net to gross, but round up from gross to net.
    150   Finally, "round-to-nearest" implies rounding in the same way for
    151   both conversion directions, and rounding up from the exact
    152   mid-point between multiples of the rounding unit.
    153 
    154 * When cummulative calculation is used, the order in which tax classes
    155   are applied starts to matter. This will become important when defining
    156   tax rules later.
    157 
    158 * Orders can specify that a particular tax class and amount is to
    159   be applied to specific products or to the entire order,
    160   but not both. In this case, the backend adds the exact
    161   amounts to the contract terms and the respective pot-statistics.
    162 
    163 * Orders can specify that only a particular tax class is to be applied
    164   to a product or the entire order, but without giving the tax amount.
    165   In this case, the backend computes the applicable
    166   tax and adds the exact amounts to the contract terms and the
    167   respective pot-statistics. It is also possible that for some products
    168   in the order the frontend calculated the exact amount, while for
    169   others the calculation is left to the backend.
    170 
    171 * When generating the contract terms, append the tax class details
    172   of applicable taxes (rates, descriptions) from the database
    173   to the contract.
    174 
    175 * Allow the client to define and use additional custom tax classes
    176   per order.
    177 
    178 * Add new configuration sections "[taxes-$ID]" that specify common tax
    179   classes (name and description as string) and rates (floating point)
    180   and per-quantity charges (amount) with calculation and rounding mode
    181   that should be automatically provided to all instances. When creating
    182   a new instance, populate the tax class table with these values.  Add a
    183   command-line tool to add all configured taxes to all existing
    184   instances (for example, to update default taxes for the next year).
    185 
    186 * When an order is paid, make sure to add the tax totals to each
    187   of the money pots.
    188 
    189 * For tipping, specifying a "tax" ``tip-$STAFF`` with a custom amount can
    190   thus be easily assigned to the tip money pot of ``$STAFF``.
    191 
    192 Phase 4: Tax Rules
    193 ------------------
    194 
    195 This is inspired by ERPnext's "tax rules".
    196 
    197 A **tax rule** specifies whether a tax class applies to a particular
    198 product, group of products, or order.
    199 
    200 * There should be an optional ``__fallback__`` tax rule that is applied to all
    201   orders and products that do not match a specific rule.
    202 
    203 * Except for the ``__fallback__`` tax rule, it is possible that multiple
    204   tax rules apply, in which case they *all* apply at the same time.
    205   Only the "fallback" rule only applies if no other rules apply.
    206 
    207 * Add a table "tax_rules" with
    208 
    209   (0) tax rule serial number
    210   (1) instance ID (foreign key)
    211   (2) tax rule name (unique with instance ID), ``__fallback__`` is reserved
    212       for the fallback rule
    213   (3) tax class serial number (foreign key)
    214   (4) filter: array of product group serial IDs, NULL for all, [] for none
    215   (5) filter: array of product ID serial IDs, NULL for all, [] for none
    216   (6) filter: total_only (boolean), true if the tax rule only applies to the
    217       final total of the order, and not individual products; if total_only
    218       is true, then the product and product group arrays MUST both be empty
    219 
    220   In the future, we *may* want to expand this to add per-order filters,
    221   like on the shipping address; however, for now we will limit the
    222   filters to make this more implementable.
    223 
    224 * Orders can specify an *array* of tax rules (by tax rule name)
    225   to apply to each product or the entire order (depending on the
    226   filter of the tax rule). In this case, the tax rules are applied
    227   in the sequence specified in the array to compute which
    228   tax classes to apply to each product or the entire order.
    229   Tax rules must not be specified when an order already specifies
    230   a tax class for the entire order.
    231 
    232 * However, it is possible to specify tax classes for some products
    233   and then tax rules would still apply for other products
    234   or the entire order. But if a product in the order is specified
    235   as having an explicit tax class, the order-wide product-specific
    236   tax rules will no longer apply to it.  Order-wide tax rules
    237   on the order total would still be applied.
    238 
    239 * If a tax rule is specified for an order but it does not
    240   apply to the order or a product in it, the rule is simply
    241   ignored.
    242 
    243 
    244 
    245 Phase 5: Tax Regimes
    246 --------------------
    247 
    248 This is inspired by ERPnext's "tax categories".
    249 
    250 A **tax regime** determines which set of tax rules to apply in
    251 which order (with cummulative taxes, the order may matter).
    252 The idea here is that for some customers or transactions completely
    253 different sets of rules may apply, but still the sets of rules
    254 are frequently the same.
    255 
    256 * There should be a "default" tax regime that is applied to all
    257   orders where the client did not specify a tax regime.
    258   Basically, not specified implies ``__default__``. However, if
    259   a default tax regime is not configured, this is not an error
    260   and simply no taxes are applied.
    261 
    262 * Add a table "tax_regime" with
    263 
    264   (0) tax regime serial number
    265   (1) instance ID (foreign key)
    266   (2) tax regime name (unique with instance ID), ``__default__`` is reserved
    267       for the default regime
    268   (3) array of applicable tax rules
    269 
    270 * Orders can specify a tax regime instead of an array of
    271   tax rules. In this case, the array of tax rules is simply
    272   obtained from the tax regime.
    273 
    274 * Orders that specify a tax regime must not also specify an
    275   array of tax rules.
    276 
    277 
    278 Test Plan
    279 =========
    280 
    281 * Unit tests for the rounding functions.
    282 * Shell-script tests for the CRUD API on taxes and automatic
    283   import of tax classes from the configuration.
    284 * Shell-script tests to check tax calculations in created orders
    285   and to test statistics on taxes paid.
    286 * Manual tests for SPA.
    287 * Manual tests on PDF report generation.
    288 * Manual tests on rendering taxes in wallets.
    289 
    290 
    291 Definition of Done
    292 ==================
    293 
    294 * Specification updated
    295 * Database updated
    296 * Merchant backend updated:
    297 
    298   * CRUD API for tax definitions
    299   * INI-based tax class importer
    300   * CRUD API update for product management
    301   * Order creation update
    302   * Statistics update on order paid
    303 
    304 * Merchant backend SPA updated:
    305 
    306   * CRUD for tax class definitions
    307   * CRUD for associating tax classes with products
    308   * Order creation with tax-class override (at least for the entire order,
    309     not necessarily per-product)
    310   * Statistics page rendering tax statistics
    311 
    312 * Wallets updated to render taxes (upon request, in detailed view
    313   on payment or from order history)
    314 
    315 
    316 Alternatives
    317 ============
    318 
    319 Communism? Crypto-anarchy?
    320 
    321 
    322 Drawbacks
    323 =========
    324 
    325 * Quite a bit of extra complexity
    326 
    327 
    328 Discussion / Q&A
    329 ================
    330 
    331 (This should be filled in with results from discussions on mailing lists / personal communication.)