Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][ADD] account_tax_round_down #2005

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions account_tax_round_down/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
======================
Account Tax Round Down
======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:292bfb7523858a769a7b92123ccea8654a6d66bb6debe0566d10194e8bba2f56
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |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-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).

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

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.

Configuration
=============

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

Usage
=====

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.

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

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/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/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.

Credits
=======

Authors
-------

* Quartile

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

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

- Yoshi Tashiro

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

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. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions account_tax_round_down/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions account_tax_round_down/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2022-2024 Quartile
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Account Tax Round Down",
"version": "16.0.1.0.0",
"category": "Tools",
"license": "AGPL-3",
"website": "https://github.com/OCA/account-financial-tools",
"author": "Quartile, Odoo Community Association (OCA)",
"depends": ["account"],
"data": [
"views/res_config_settings_views.xml",
],
"installable": True,
}
5 changes: 5 additions & 0 deletions account_tax_round_down/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import account_move
from . import account_tax
from . import res_company
from . import res_config_settings
from . import res_currency
30 changes: 30 additions & 0 deletions account_tax_round_down/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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"

@contextmanager
def _sync_dynamic_line(
self,
existing_key_fname,
needed_vals_fname,
needed_dirty_fname,
line_type,
container,
):
if line_type == "tax" and self.env.company.need_tax_round_down:
self = self.with_context(rounding_method="DOWN")
with super()._sync_dynamic_line(
existing_key_fname,
needed_vals_fname,
needed_dirty_fname,
line_type,
container,
) as ret:
yield ret
69 changes: 69 additions & 0 deletions account_tax_round_down/models/account_tax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2022-2024 Quartile Limited
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models


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

@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")

Check warning on line 13 in account_tax_round_down/models/account_tax.py

View check run for this annotation

Codecov / codecov/patch

account_tax_round_down/models/account_tax.py#L13

Added line #L13 was not covered by tests
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,
currency=None,
quantity=1.0,
product=None,
partner=None,
is_refund=False,
handle_price_include=True,
include_caba_tags=False,
fixed_multiplicator=1,
):
# Just to pass the currency context used in _compute_amount()
self = self.with_context(currency=currency)
return super().compute_all(
price_unit,
currency,
quantity,
product,
partner,
is_refund,
handle_price_include,
include_caba_tags,
fixed_multiplicator,
)
13 changes: 13 additions & 0 deletions account_tax_round_down/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2022 Quartile
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

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

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

need_tax_round_down = fields.Boolean(
related="company_id.need_tax_round_down",
readonly=False,
)
19 changes: 19 additions & 0 deletions account_tax_round_down/models/res_currency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2022 Quartile
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models, tools


class Currency(models.Model):
_inherit = "res.currency"

def round(self, amount):
self.ensure_one()
rounding_method = self.env.context.get("rounding_method")
if rounding_method:
return tools.float_round(
amount,
precision_rounding=self.rounding,
rounding_method=rounding_method,
)
return super().round(amount)
2 changes: 2 additions & 0 deletions account_tax_round_down/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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
2 changes: 2 additions & 0 deletions account_tax_round_down/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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
Loading