Skip to content

Commit

Permalink
[4986][ADD] account_tax_round_down
Browse files Browse the repository at this point in the history
  • Loading branch information
yostashiro authored and kanda999 committed Jan 8, 2025
1 parent 91f3290 commit 8a2041d
Show file tree
Hide file tree
Showing 15 changed files with 350 additions and 228 deletions.
96 changes: 65 additions & 31 deletions account_tax_round_down/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,68 @@ Account Tax Round Down
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-qrtl%2Fmi7--custom-lightgray.png?logo=github
:target: https://github.com/qrtl/mi7-custom/tree/15.0/account_tax_round_down
:alt: qrtl/mi7-custom
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github
:target: https://github.com/OCA/account-financial-tools/tree/16.0/account_tax_round_down
:alt: OCA/account-financial-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-financial-tools-16-0/account-financial-tools-16-0-account_tax_round_down
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module provides the function of rounding down the tax amount in
invoices (and also other business documents such as sales orders and
purchase orders).

|badge1| |badge2| |badge3|
**Table of contents**

This module does the following:
.. contents::
:local:

- Provides the function of rounding down the tax amount in the invoice,
covering:
Use Cases / Context
===================

- the total presentation in invoice form/print
- the tax amount calculation of account move line
By default, Odoo uses the "HALF-UP" method to round tax amounts.
However, in some regions, such as Japan, some industries have a common
practice of rounding down instead. This module accommodates such local
conventions by offering an alternate rounding method.

Note that, due to the structure of compute_all() method, the round-down
does not work perfectly in case the document involves multiple taxes
with different price_include settings (which is not expected to happen
under normal circumstances in the Japanese business environment).
Configuration
=============

Background:
-----------
Go to *Accounting (or Invoicing) > Configuration > Settings*, and select
"Round-down Tax Amounts" for companies whose tax amounts should be
rounded down.

In Japan there is sometimes a tacit industry-wide convention of rounding
down the tax amount instead of applying the default rounding
("HALF-UP").
Usage
=====

**Table of contents**
With the round-down setting enabled, if you create an invoice in JPY
with the following line:

.. contents::
:local:
- Quantity: 1
- Unit Price: 15
- Tax: 10% (excluded)

Configuration
=============
the calculated tax amount will be 1 instead of 2.

Known issues / Roadmap
======================

Go to Accounting (or Invoicing) > Configuration > Settings, and select
"Round-down Tax Amounts" for companies where tax amounts should be
rownded down (selection is done by default).
Due to the structure of the compute_all() method in the tax model,
rounding down may not yield the expected results in cases where
tax-inclusive pricing is used.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/qrtl/mi7-custom/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-financial-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/qrtl/mi7-custom/issues/new?body=module:%20account_tax_round_down%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_tax_round_down%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -70,11 +87,28 @@ Credits
Authors
-------

* Quartile Limited
* Quartile

Contributors
------------

- Quartile <https://www.quartile.co>

- Yoshi Tashiro

Maintainers
-----------

This module is part of the `qrtl/mi7-custom <https://github.com/qrtl/mi7-custom/tree/15.0/account_tax_round_down>`_ project on GitHub.
This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/16.0/account_tax_round_down>`_ project on GitHub.

You are welcome to contribute.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
8 changes: 4 additions & 4 deletions account_tax_round_down/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Copyright 2022 Quartile Limited
# Copyright 2022-2024 Quartile
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Account Tax Round Down",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Tools",
"license": "AGPL-3",
"author": "Quartile Limited",
"website": "https://www.quartile.co",
"website": "https://github.com/OCA/account-financial-tools",
"author": "Quartile, Odoo Community Association (OCA)",
"depends": ["account"],
"data": [
"views/res_config_settings_views.xml",
Expand Down
38 changes: 20 additions & 18 deletions account_tax_round_down/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
# Copyright 2022 Quartile Limited
# Copyright 2022-2024 Quartile Limited
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from contextlib import contextmanager

from odoo import models


class AccountMove(models.Model):
_inherit = "account.move"

# For journal entries
def _recompute_tax_lines(
self, recompute_tax_base_amount=False, tax_rep_lines_to_recompute=None
@contextmanager
def _sync_dynamic_line(
self,
existing_key_fname,
needed_vals_fname,
needed_dirty_fname,
line_type,
container,
):
self.ensure_one()
if self.company_id.need_tax_round_down:
self = self.with_context(rounding_method="DOWN")
return super()._recompute_tax_lines(
recompute_tax_base_amount=recompute_tax_base_amount,
tax_rep_lines_to_recompute=tax_rep_lines_to_recompute,
)

# For invoice form and print total presentation.
# Extending _get_tax_totals() would also work for invoices, however not for sales
# orders. Therefore _compute_tax_totals_json() is extended for consistency reason.
def _compute_tax_totals_json(self):
if self.env.company.need_tax_round_down:
if line_type == "tax" and self.env.company.need_tax_round_down:
self = self.with_context(rounding_method="DOWN")
return super()._compute_tax_totals_json()
with super()._sync_dynamic_line(
existing_key_fname,
needed_vals_fname,
needed_dirty_fname,
line_type,
container,
) as ret:
yield ret
83 changes: 48 additions & 35 deletions account_tax_round_down/models/account_tax.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,47 @@
# Copyright 2022 Quartile Limited
# Copyright 2022-2024 Quartile Limited
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models
from odoo import api, models


class AccountTax(models.Model):
_inherit = "account.tax"

# This adjustment also affects the tax-inclusive price presentation in the eCommerce
# shop.
@api.model
def _prepare_tax_totals(self, base_lines, currency, tax_lines=None):
if self.env.company.need_tax_round_down:
self = self.with_context(rounding_method="DOWN")
return super()._prepare_tax_totals(base_lines, currency, tax_lines)

def _compute_amount(
self,
base_amount,
price_unit,
quantity=1.0,
product=None,
partner=None,
fixed_multiplicator=1,
):
"""Handle the case where round-down is required with the round_per_line setting.
Due to how tax amount rounding is done inside the compute_all() method under the
round_per_line setting (i.e. float_round() helper function is used instead of
the round() method of the currency model), we want to apply the desired rounding
using the model method beforehand.
"""
amount = super()._compute_amount(
base_amount, price_unit, quantity, product, partner, fixed_multiplicator
)
company = self.company_id
if (
company.need_tax_round_down
and company.tax_calculation_rounding_method == "round_per_line"
and self.amount_type == "percent"
):
currency = self.env.context.get("currency") or company.currency
amount = currency.with_context(rounding_method="DOWN").round(amount)
return amount

def compute_all(
self,
price_unit,
Expand All @@ -19,38 +52,18 @@ def compute_all(
is_refund=False,
handle_price_include=True,
include_caba_tags=False,
fixed_multiplicator=1,
):
if not self:
company = self.env.company
else:
company = self[0].company_id
if company.need_tax_round_down:
rounding_method = "DOWN"
if self.mapped("price_include") == [True]:
# In case all taxes have 'Included in Price' selected, then we reverse
# the rounding method, since the excluded amount is calculated first,
# and then the tax amount is calculated by subtracting the excluded
# amount from the total.
# We cannot cover the pattern where multiple taxes with different
# price_include settings are involved due to the structure of
# compute_all() method.
rounding_method = "UP"
# This matters when currency is NOT given
self = self.with_context(rounding_method=rounding_method)
if currency:
# To avoid unwanted rounding down on price_unit.
currency = currency.with_context(rounding_method="HALF-UP")
price_unit = currency.round(price_unit)
# If currency is given, the context is not passed down via self,
# and it should be assigned here.
currency = currency.with_context(rounding_method=rounding_method)
# Just to pass the currency context used in _compute_amount()
self = self.with_context(currency=currency)
return super().compute_all(
price_unit,
currency=currency,
quantity=quantity,
product=product,
partner=partner,
is_refund=is_refund,
handle_price_include=handle_price_include,
include_caba_tags=include_caba_tags,
currency,
quantity,
product,
partner,
is_refund,
handle_price_include,
include_caba_tags,
fixed_multiplicator,
)
4 changes: 2 additions & 2 deletions account_tax_round_down/models/res_company.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Quartile Limited
# Copyright 2022 Quartile
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models
Expand All @@ -8,6 +8,6 @@ class ResCompany(models.Model):
_inherit = "res.company"

need_tax_round_down = fields.Boolean(
default=True,
default=False,
help="If selected, rounding method 'DOWN' will be applied to tax amounts.",
)
2 changes: 1 addition & 1 deletion account_tax_round_down/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Quartile Limited
# Copyright 2022 Quartile
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models
Expand Down
7 changes: 4 additions & 3 deletions account_tax_round_down/models/res_currency.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Quartile Limited
# Copyright 2022 Quartile
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models, tools
Expand All @@ -9,10 +9,11 @@ class Currency(models.Model):

def round(self, amount):
self.ensure_one()
if "rounding_method" in self._context:
rounding_method = self.env.context.get("rounding_method")
if rounding_method:
return tools.float_round(
amount,
precision_rounding=self.rounding,
rounding_method=self._context.get("rounding_method"),
rounding_method=rounding_method,
)
return super().round(amount)
5 changes: 2 additions & 3 deletions account_tax_round_down/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
Go to Accounting (or Invoicing) \> Configuration \> Settings, and select
"Round-down Tax Amounts" for companies where tax amounts should be
rownded down (selection is done by default).
Go to *Accounting (or Invoicing) \> Configuration \> Settings*, and select "Round-down
Tax Amounts" for companies whose tax amounts should be rounded down.
3 changes: 3 additions & 0 deletions account_tax_round_down/readme/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
By default, Odoo uses the "HALF-UP" method to round tax amounts. However, in some
regions, such as Japan, some industries have a common practice of rounding down instead.
This module accommodates such local conventions by offering an alternate rounding method.
2 changes: 2 additions & 0 deletions account_tax_round_down/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Quartile \<<https://www.quartile.co>\>
- Yoshi Tashiro
19 changes: 2 additions & 17 deletions account_tax_round_down/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,2 @@
This module does the following:

- Provides the function of rounding down the tax amount in the invoice,
covering:
- the total presentation in invoice form/print
- the tax amount calculation of account move line

Note that, due to the structure of compute_all() method, the round-down
does not work perfectly in case the document involves multiple taxes
with different price_include settings (which is not expected to happen
under normal circumstances in the Japanese business environment).

## Background:

In Japan there is sometimes a tacit industry-wide convention of rounding
down the tax amount instead of applying the default rounding
("HALF-UP").
This module provides the function of rounding down the tax amount in invoices (and also
other business documents such as sales orders and purchase orders).
2 changes: 2 additions & 0 deletions account_tax_round_down/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Due to the structure of the compute_all() method in the tax model, rounding down may
not yield the expected results in cases where tax-inclusive pricing is used.
7 changes: 7 additions & 0 deletions account_tax_round_down/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
With the round-down setting enabled, if you create an invoice in JPY with the following line:

- Quantity: 1
- Unit Price: 15
- Tax: 10% (excluded)

the calculated tax amount will be 1 instead of 2.
Loading

0 comments on commit 8a2041d

Please sign in to comment.