Skip to content

Commit

Permalink
[ADD] l10n_es_facturae_tax_rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC013 authored and eantones committed Oct 8, 2024
1 parent d66b2ed commit f9ce95e
Show file tree
Hide file tree
Showing 13 changed files with 612 additions and 0 deletions.
63 changes: 63 additions & 0 deletions l10n_es_facturae_tax_rounding/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
=============================
L10n ES Facturae Tax Rounding
=============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:630f1e31474701aac5e3e7b94cfc7ec25c886b867d082e7abf7e4c25de29d893
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-NuoBiT%2Fodoo--addons-lightgray.png?logo=github
:target: https://github.com/NuoBiT/odoo-addons/tree/14.0/l10n_es_facturae_tax_rounding
:alt: NuoBiT/odoo-addons

|badge1| |badge2| |badge3|

This module generates the Facturae with the tax amounts rounded according to the total tax amount by group.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/NuoBiT/odoo-addons/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/NuoBiT/odoo-addons/issues/new?body=module:%20l10n_es_facturae_tax_rounding%0Aversion:%2014.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
~~~~~~~

* NuoBiT Solutions
* S.L.

Contributors
~~~~~~~~~~~~

* `NuoBiT <https://www.nuobit.com>`_:

* Frank Cespedes <[email protected]>

Maintainers
~~~~~~~~~~~

This module is part of the `NuoBiT/odoo-addons <https://github.com/NuoBiT/odoo-addons/tree/14.0/l10n_es_facturae_tax_rounding>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions l10n_es_facturae_tax_rounding/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions l10n_es_facturae_tax_rounding/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright NuoBiT Solutions, S.L. (<https://www.nuobit.com>)
# Frank Cespedes <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

{
"name": "L10n ES Facturae Tax Rounding",
"summary": "This module generates the Facturae with the tax amounts rounded "
"according to the total tax amount by group.",
"version": "14.0.0.0.0",
"category": "Accounting & Finance",
"author": "NuoBiT Solutions, S.L.",
"website": "https://github.com/nuobit/odoo-addons",
"license": "AGPL-3",
"depends": ["l10n_es_facturae"],
"data": [
"views/report_facturae.xml",
],
}
2 changes: 2 additions & 0 deletions l10n_es_facturae_tax_rounding/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_move
from . import account_tax
58 changes: 58 additions & 0 deletions l10n_es_facturae_tax_rounding/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo import models


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

def _get_facturae_tax_info(self):
self.ensure_one()
output_taxes, withheld_taxes = super()._get_facturae_tax_info()
if self.company_id.tax_calculation_rounding_method == "round_globally":
for taxes in (output_taxes, withheld_taxes):
for tax, values in taxes.items():
values["amount"] = tax.get_tax_amount(
values["base"], self.currency_id, self.company_id
)
return output_taxes, withheld_taxes


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

def _get_facturae_tax_line_info(self, tax):
self.ensure_one()
tax_line_info = {}
sum_tax_amount = 0.0

for line in self.move_id.line_ids.filtered(
lambda x: not x.display_type and not x.exclude_from_invoice_tab
):
for line_tax in line.tax_ids.filtered(lambda t: t == tax and t.amount >= 0):
tax_amount = tax.get_tax_amount(
line.price_subtotal, self.currency_id, self.company_id
)
tax_line_info.setdefault((line, line_tax), tax_amount)
sum_tax_amount += tax_amount

move_tax_line = self.move_id.line_ids.filtered(lambda x: x.tax_line_id == tax)
total_tax_line_tax_amount = self.currency_id.round(
sum(move_tax_line.mapped("balance"))
)
diff_tax_amount = self.currency_id.round(sum_tax_amount) - (
-total_tax_line_tax_amount
)

if diff_tax_amount != 0:
sorted_lines = sorted(tax_line_info.keys(), key=lambda k: k[0].id)
num_lines_to_adjust = min(
len(sorted_lines), int(abs(diff_tax_amount * 100))
)
adjustment_value = 0.01 if diff_tax_amount > 0 else -0.01
for i in range(num_lines_to_adjust):
line, line_tax = sorted_lines[i]
tax_line_info[(line, line_tax)] += adjustment_value

return tax_line_info[(self, tax)]
18 changes: 18 additions & 0 deletions l10n_es_facturae_tax_rounding/models/account_tax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo import models
from odoo.tools.float_utils import float_round


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

def get_tax_amount(self, amount, currency, company):
self.ensure_one()
tax_amount = amount * self.amount / 100
prec = currency.rounding
if company.tax_calculation_rounding_method == "round_globally":
prec *= 1e-5
tax_amount = float_round(tax_amount, precision_rounding=prec)
return tax_amount
3 changes: 3 additions & 0 deletions l10n_es_facturae_tax_rounding/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `NuoBiT <https://www.nuobit.com>`_:

* Frank Cespedes <[email protected]>
1 change: 1 addition & 0 deletions l10n_es_facturae_tax_rounding/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module generates the Facturae with the tax amounts rounded according to the total tax amount by group.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f9ce95e

Please sign in to comment.