taler-docs

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

078-taxes.rst (12505B)


      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.
    146          Unique should be "instance+tax class name".
    147 
    148 * When "rounding up" is used, round up from net to gross, but round
    149   down from gross to net. Similarly, when "rounding down" is used,
    150   round down from net to gross, but round up from gross to net.
    151   Finally, "round-to-nearest" implies rounding in the same way for
    152   both conversion directions, and rounding up from the exact
    153   mid-point between multiples of the rounding unit.
    154 
    155 * When cummulative calculation is used, the order in which tax classes
    156   are applied starts to matter. This will become important when defining
    157   tax rules later.
    158 
    159 * Orders can specify that a particular tax class and amount is to
    160   be applied to specific products or to the entire order,
    161   but not both. In this case, the backend adds the exact
    162   amounts to the contract terms and the respective pot-statistics.
    163 
    164 * Orders can specify that only a particular tax class is to be applied
    165   to a product or the entire order, but without giving the tax amount.
    166   In this case, the backend computes the applicable
    167   tax and adds the exact amounts to the contract terms and the
    168   respective pot-statistics. It is also possible that for some products
    169   in the order the frontend calculated the exact amount, while for
    170   others the calculation is left to the backend.
    171 
    172 * When generating the contract terms, append the tax class details
    173   of applicable taxes (rates, descriptions) from the database
    174   to the contract.
    175 
    176 * Allow the client to define and use additional custom tax classes
    177   per order.
    178 
    179 * Add new configuration sections "[taxes-$ID]" that specify common tax
    180   classes (name and description as string) and rates (floating point)
    181   and per-quantity charges (amount) with calculation and rounding mode
    182   that should be automatically provided to all instances. When creating
    183   a new instance, populate the tax class table with these values.  Add a
    184   command-line tool to add all configured taxes to all existing
    185   instances (for example, to update default taxes for the next year).
    186 
    187 * When an order is paid, make sure to add the tax totals to each
    188   of the money pots.
    189 
    190 * For tipping, specifying a "tax" ``tip-$STAFF`` with a custom amount can
    191   thus be easily assigned to the tip money pot of ``$STAFF``.
    192 
    193 Phase 4: Tax Rules
    194 ------------------
    195 
    196 This is inspired by ERPnext's "tax rules".
    197 
    198 A **tax rule** specifies whether a tax class applies to a particular
    199 product, group of products, or order.
    200 
    201 * There should be an optional ``__fallback__`` tax rule that is applied to all
    202   orders and products that do not match a specific rule.
    203 
    204 * Except for the ``__fallback__`` tax rule, it is possible that multiple
    205   tax rules apply, in which case they *all* apply at the same time.
    206   Only the "fallback" rule only applies if no other rules apply.
    207 
    208 * Add a table "tax_rules" with
    209 
    210   (0) tax rule serial number
    211   (1) instance ID (foreign key)
    212   (2) tax rule name (unique with instance ID), ``__fallback__`` is reserved
    213       for the fallback rule
    214   (3) tax class serial number (foreign key)
    215   (4) filter: array of product group serial IDs, NULL for all, [] for none
    216   (5) filter: array of product ID serial IDs, NULL for all, [] for none
    217   (6) filter: total_only (boolean), true if the tax rule only applies to the
    218       final total of the order, and not individual products; if total_only
    219       is true, then the product and product group arrays MUST both be empty
    220 
    221   In the future, we *may* want to expand this to add per-order filters,
    222   like on the shipping address; however, for now we will limit the
    223   filters to make this more implementable.
    224 
    225 * Orders can specify an *array* of tax rules (by tax rule name)
    226   to apply to each product or the entire order (depending on the
    227   filter of the tax rule). In this case, the tax rules are applied
    228   in the sequence specified in the array to compute which
    229   tax classes to apply to each product or the entire order.
    230   Tax rules must not be specified when an order already specifies
    231   a tax class for the entire order.
    232 
    233 * However, it is possible to specify tax classes for some products
    234   and then tax rules would still apply for other products
    235   or the entire order. But if a product in the order is specified
    236   as having an explicit tax class, the order-wide product-specific
    237   tax rules will no longer apply to it.  Order-wide tax rules
    238   on the order total would still be applied.
    239 
    240 * If a tax rule is specified for an order but it does not
    241   apply to the order or a product in it, the rule is simply
    242   ignored.
    243 
    244 
    245 
    246 Phase 5: Tax Regimes
    247 --------------------
    248 
    249 This is inspired by ERPnext's "tax categories".
    250 
    251 A **tax regime** determines which set of tax rules to apply in
    252 which order (with cummulative taxes, the order may matter).
    253 The idea here is that for some customers or transactions completely
    254 different sets of rules may apply, but still the sets of rules
    255 are frequently the same.
    256 
    257 * There should be a "default" tax regime that is applied to all
    258   orders where the client did not specify a tax regime.
    259   Basically, not specified implies ``__default__``. However, if
    260   a default tax regime is not configured, this is not an error
    261   and simply no taxes are applied.
    262 
    263 * Add a table "tax_regime" with
    264 
    265   (0) tax regime serial number
    266   (1) instance ID (foreign key)
    267   (2) tax regime name (unique with instance ID), ``__default__`` is reserved
    268       for the default regime
    269   (3) array of applicable tax rules
    270 
    271 * Orders can specify a tax regime instead of an array of
    272   tax rules. In this case, the array of tax rules is simply
    273   obtained from the tax regime.
    274 
    275 * Orders that specify a tax regime must not also specify an
    276   array of tax rules.
    277 
    278 
    279 Test Plan
    280 =========
    281 
    282 * Unit tests for the rounding functions.
    283 * Shell-script tests for the CRUD API on taxes and automatic
    284   import of tax classes from the configuration.
    285 * Shell-script tests to check tax calculations in created orders
    286   and to test statistics on taxes paid.
    287 * Manual tests for SPA.
    288 * Manual tests on PDF report generation.
    289 * Manual tests on rendering taxes in wallets.
    290 
    291 
    292 Definition of Done
    293 ==================
    294 
    295 * Specification updated
    296 * Database updated
    297 * Merchant backend updated:
    298 
    299   * CRUD API for tax definitions
    300   * INI-based tax class importer
    301   * CRUD API update for product management
    302   * Order creation update
    303   * Statistics update on order paid
    304 
    305 * Merchant backend SPA updated:
    306 
    307   * CRUD for tax class definitions
    308   * CRUD for associating tax classes with products
    309   * Order creation with tax-class override (at least for the entire order,
    310     not necessarily per-product)
    311   * Statistics page rendering tax statistics
    312 
    313 * Wallets updated to render taxes (upon request, in detailed view
    314   on payment or from order history)
    315 
    316 
    317 Alternatives
    318 ============
    319 
    320 Communism? Crypto-anarchy?
    321 
    322 
    323 Drawbacks
    324 =========
    325 
    326 * Quite a bit of extra complexity
    327 
    328 
    329 Discussion / Q&A
    330 ================
    331 
    332 (This should be filled in with results from discussions on mailing lists / personal communication.)