@@ -81,7 +81,7 @@ price. The following options are available:
8181  tax-excluded sales price
8282- :ref: `Percentage of Price Tax Included  <taxes/computation/percentage-of-price-tax-included >`: a
8383  percentage of the tax-included total
84- - :ref: `Python Code   <taxes/computation/python-code >`: a custom user-defined formula
84+ - :ref: `Custom Formula   <taxes/computation/python-code >`: a custom user-defined formula
8585
8686.. _taxes/computation/group-of-taxes :
8787
@@ -129,12 +129,12 @@ which determines whether the sales price should be treated as tax-excluded or ta
129129.. tabs ::
130130   .. tab :: Tax-excluded 
131131
132-       If :guilabel: `Included in Price ` is disabled , the computation is  :math: ` \text {tax amount} 
133-       = \text {sales price} \times  \text {tax rate}`.
132+       If :guilabel: `Included in Price ` is :guilabel: ` Tax Excluded ` , the computation is
133+       :math: ` \text {tax amount}  = \text {sales price} \times  \text {tax rate}`.
134134
135135      .. example ::
136136         A product has a sales price of $1000, and we apply a 10% :guilabel: `Percentage of Price `
137-          tax that is not  :guilabel: `Included in Price `. We then have:
137+          tax that is :guilabel: `Tax Excluded `. We then have:
138138
139139         +-------------+-------------+----------+----------+ 
140140         |  Product     |  Price       |  Tax      |  Total    | 
@@ -145,12 +145,13 @@ which determines whether the sales price should be treated as tax-excluded or ta
145145
146146   .. tab :: Tax-included 
147147
148-       If :guilabel: `Included in Price ` is enabled, the computation is :math: `\text {tax amount} =
149-       \text {sales price} \times  \frac {\text {tax rate}}{1  + \text {tax rate}}`.
148+       If :guilabel: `Included in Price ` is :guilabel: `Tax Included `, the computation is
149+       :math: `\text {tax amount} = \text {sales price} \times  \frac {\text {tax rate}}{1  +
150+       \text {tax rate}}`.
150151
151152      .. example ::
152153         A product has a sales price of $1000, and we apply a 10% :guilabel: `Percentage of Price `
153-          tax that is :guilabel: `Included in Price `. We then have:
154+          tax that is :guilabel: `Tax Included `. We then have:
154155
155156         +-------------+-------------+----------+----------+ 
156157         |  Product     |  Price       |  Tax      |  Total    | 
@@ -168,8 +169,8 @@ Percentage of price tax included
168169   This tax computation is rarely used and only useful in countries (e.g., Brazil, Bolivia) that
169170   quote tax rates as a percentage of the tax-included total.
170171   For the more common need to compute tax amounts from a tax-included price, use the
171-    :ref: `Percentage of Price  <taxes/computation/percentage-of-price >` tax computation with the 
172-    :ref: `Included in Price  <taxes/included-in-price >` option .
172+    :ref: `Percentage of Price  <taxes/computation/percentage-of-price >` tax computation with
173+    :ref: `Included in Price  <taxes/included-in-price >` set to  :guilabel: ` Tax Included ` .
173174
174175The tax rate is a percentage of the **tax-included ** total.
175176
@@ -178,12 +179,13 @@ which determines whether the sales price should be treated as tax-excluded or ta
178179
179180.. tabs ::
180181   .. tab :: Tax-excluded 
181-       If :guilabel: `Included in Price ` is disabled, the computation is :math: `\text {tax amount}
182-       = \text {sales price} \times  \frac {\text {tax rate}}{1  - \text {tax rate}}`.
182+       If :guilabel: `Included in Price ` is set to :guilabel: `Tax Excluded `, the computation is
183+       :math: `\text {tax amount} = \text {sales price} \times  \frac {\text {tax rate}}{1  -
184+       \text {tax rate}}`.
183185
184186      .. example ::
185187         A product has a sales price of $1000, and we apply a 10% :guilabel: `Percentage of Price 
186-          Tax Included ` tax that is not  :guilabel: `Included in Price `. We then have:
188+          Tax Included ` tax that is :guilabel: `Tax Excluded `. We then have:
187189
188190         +-------------+-------------+----------+----------+ 
189191         |  Product     |  Price       |  Tax      |  Total    | 
@@ -197,12 +199,12 @@ which determines whether the sales price should be treated as tax-excluded or ta
197199
198200   .. tab :: Tax-included 
199201
200-       If :guilabel: `Included in Price ` is enabled, the computation is  :math: ` \text {tax amount} = 
201-       \text {sales price} \times  \text {tax rate}`.
202+       If :guilabel: `Included in Price ` is set to  :guilabel: ` Tax Included `, the computation is 
203+       :math: ` \text {tax amount} =  \text {sales price} \times  \text {tax rate}`.
202204
203205      .. example ::
204206         A product has a sales price of $1000, and we apply a 10%
205-          :guilabel: `Percentage of Price Tax Included ` tax that is :guilabel: `Included in Price `.
207+          :guilabel: `Percentage of Price Tax Included ` tax that is :guilabel: `Tax Included `.
206208         We then have:
207209
208210         +-------------+-------------+----------+----------+ 
@@ -217,34 +219,45 @@ which determines whether the sales price should be treated as tax-excluded or ta
217219
218220.. _taxes/computation/python-code :
219221
220- Python code 
221- *********** 
222+ Custom formula 
223+ **************  
222224
223225.. important ::
224226   If a tax can be expressed as a multiple of the quantity of the product to which it applies, it
225227   can be defined as a :ref: `Fixed  <taxes/computation/fixed >` tax. Doing so is strongly recommended
226-    over defining a :guilabel: `Python Code ` tax.
228+    over defining a :guilabel: `Custom Formula ` tax.
227229
228- A tax defined as :guilabel: `Python Code ` consists of two snippets of Python code that are executed
229- in a local environment that can access the unit price, quantity, product, and partner.
230- :guilabel: `Python Code ` defines the amount of the tax, and :guilabel: `Applicable Code ` defines
231- whether the tax is applied. Enter a formula for each field at the bottom of the
232- :guilabel: `Definition ` tab.
230+ .. note ::
231+    To use :guilabel: `Custom Formula ` taxes, :ref: `install  <general/install >` the :guilabel: `Define 
232+    Taxes as Python Code ` (`account_python_tax `) module.
233233
234- .. example ::
235-    A product has a sales price of $1000, and we apply a :guilabel: `Python Code ` tax with the
236-    following configuration:
234+ For a :guilabel: `Custom Formula ` tax, the tax amount is computed according to a Python expression
235+ defined in the :guilabel: `Formula ` field. The Python expression may contain the following tokens:
236+ 
237+ - any of the following variables:
238+ 
239+   - `price_unit `: the unit price of the product
240+   - `base `: the taxable basis on which the tax is applied - may differ from the `price_unit ` if
241+     other taxes are applied first
242+   - `quantity `: the quantity of the product
243+   - `product `: the product record - product fields can also be accessed
244+ 
245+ - integers and floating-point numbers
237246
238-    - :guilabel: `Python Code `: `result = price_unit * 0.10 ` and
239-    - :guilabel: `Applicable Code `: `result = True `.
247+ - the following permitted tokens: `( `, `) `, `+ `, `- `, `* `, `/ `, `, `, `< `, `> `, `<= `, `>= `, `and `,
248+   `or `, `None `, `min `, and `max `
249+ 
250+ .. example ::
251+    A product has a sales price of $1000, and we apply a :guilabel: `Custom Formula ` tax with a
252+    :guilabel: `Formula ` of `min(base, 500) * 0.10 + max(base - 500, 0) * 0.20 `
240253
241254   We then have:
242255
243256   +-------------+-------------+----------+----------+ 
244257   |  Product     |  Price       |  Tax      |  Total    | 
245258   |  sales price |  without tax |           |           | 
246259   +=============+=============+==========+==========+ 
247-    |  1,000       |  1,000       |  100       |  1,100 .00 | 
260+    |  1,000       |  1,000       |  150       |  1,150 .00 | 
248261   +-------------+-------------+----------+----------+ 
249262
250263.. _taxes/active :
@@ -365,16 +378,25 @@ invoice line.
365378Included in price
366379~~~~~~~~~~~~~~~~~ 
367380
368- With this option activated, the tax will treat the sales price on which it is applied as a total
369- including the tax amount. The tax computation will split the sales price into a base amount and a
370- tax amount. This makes it suitable for B2C sales in most countries where prices are quoted
371- tax-inclusive.
381+ .. tip ::
382+    To set a company-wide default for this setting, go to :menuselection: `Accounting -->  
383+    Configuration -->  Settings `, find the :guilabel: `Taxes ` section, and set the :guilabel: `Prices `
384+    setting to :guilabel: `Tax Excluded ` or :guilabel: `Tax Included `. This setting cannot be changed
385+    once invoices have been created.
386+ 
387+ When set to :guilabel: `Default `, the company-wide default will be used.
388+ 
389+ When set to :guilabel: `Tax Excluded `, the tax will always treat the sales price on which it is
390+ applied as a price excluding the tax amount.
372391
373- `Total = Sales Price = Computed Tax-Excluded price + Tax `
392+ When set to :guilabel: `Tax Included `, the tax will always treat the sales price on which it is
393+ applied as a total including the tax amount. The tax computation will split the sales price into a
394+ base amount and a tax amount. This makes it suitable for B2C sales in most countries where prices
395+ are quoted tax-inclusive.
374396
375397.. example ::
376398   A product has a sales price of $1000, and we apply a 10% :guilabel: `Percentage of Price ` tax
377-    with :guilabel: `Included in Price `. We then have:
399+    with :guilabel: `Included in Price ` set to  :guilabel: ` Tax Included ` . We then have:
378400
379401   +-------------+-------------+----------+----------+ 
380402   |  Product     |  Price       |  Tax      |  Total    | 
@@ -387,23 +409,21 @@ tax-inclusive.
387409   For a guide on configuring tax-excluded and tax-included prices for B2B and B2C customers,
388410   see :doc: `taxes/B2B_B2C `.
389411
390-    .. image :: taxes/toggle-button.png 
391- 
392412.. _taxes/base-subsequent :
393413
394414Affect base of subsequent taxes
395415~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
396416
397417If this setting is enabled, any subsequent tax applied on the same product line that has
398418:ref: `taxes/base-affected ` will be based on a modified sales price. The exact behavior depends on
399- whether  the tax with  :guilabel: ` Affect base of subsequent  taxes` is  :ref: ` taxes /included-in-price` 
400- or not .
419+ the :ref: ` Included in Price  < taxes/included-in-price >` setting of the tax with  :guilabel: ` Affect 
420+ base of subsequent taxes ` .
401421
402422.. tabs ::
403423   .. tab :: Tax-excluded 
404-       If :guilabel: `Included in Price ` is disabled, subsequent taxes with  :guilabel: `Base affected 
405-       by preceding taxes ` will be based on a modified sales price equal to the original sales price 
406-       plus the tax amount.
424+       If :guilabel: `Included in Price ` is set to  :guilabel: `Tax Excluded `, subsequent taxes with 
425+       :guilabel: ` Base affected  by preceding taxes ` will be based on a modified sales price equal to
426+       the original sales price  plus the tax amount.
407427
408428      .. example ::
409429         A product has a sales price of $1000, and we apply a 10% :guilabel: `Percentage of Price `
@@ -412,13 +432,13 @@ or not.
412432         $1100.
413433
414434   .. tab :: Tax-included 
415-       If :guilabel: `Included in Price ` is enabled, subsequent taxes with  :guilabel: `Base affected 
416-       by preceding taxes ` will be based on a modified sales price equal to the original sales price 
417-       minus the tax amount.
435+       If :guilabel: `Included in Price ` is set to  :guilabel: `Tax Included `, subsequent taxes with 
436+       :guilabel: ` Base affected  by preceding taxes ` will be based on a modified sales price equal to
437+       the original sales price  minus the tax amount.
418438
419439      .. example ::
420440         A product has a sales price of $1100, and we apply a 10% :guilabel: `Percentage of Price `
421-          tax with  :guilabel: `Included in Price ` and :guilabel: `Affect base of subsequent taxes `.
441+          tax that has  :guilabel: `Tax Included ` and :guilabel: `Affect base of subsequent taxes `.
422442         Any subsequent tax with :guilabel: `Base affected by preceding taxes ` will be based on a
423443         modified sales price of $1000.
424444
0 commit comments