diff --git a/l10n_es_facturae_tax_rounding/README.rst b/l10n_es_facturae_tax_rounding/README.rst new file mode 100644 index 000000000..ded5c4cae --- /dev/null +++ b/l10n_es_facturae_tax_rounding/README.rst @@ -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 `_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* NuoBiT Solutions +* S.L. + +Contributors +~~~~~~~~~~~~ + +* `NuoBiT `_: + + * Frank Cespedes + +Maintainers +~~~~~~~~~~~ + +This module is part of the `NuoBiT/odoo-addons `_ project on GitHub. + +You are welcome to contribute. diff --git a/l10n_es_facturae_tax_rounding/__init__.py b/l10n_es_facturae_tax_rounding/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/l10n_es_facturae_tax_rounding/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/l10n_es_facturae_tax_rounding/__manifest__.py b/l10n_es_facturae_tax_rounding/__manifest__.py new file mode 100644 index 000000000..76a5cb417 --- /dev/null +++ b/l10n_es_facturae_tax_rounding/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright NuoBiT Solutions, S.L. () +# Frank Cespedes +# 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", + ], +} diff --git a/l10n_es_facturae_tax_rounding/models/__init__.py b/l10n_es_facturae_tax_rounding/models/__init__.py new file mode 100644 index 000000000..1680d7280 --- /dev/null +++ b/l10n_es_facturae_tax_rounding/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_move +from . import account_tax diff --git a/l10n_es_facturae_tax_rounding/models/account_move.py b/l10n_es_facturae_tax_rounding/models/account_move.py new file mode 100644 index 000000000..c6a3fec05 --- /dev/null +++ b/l10n_es_facturae_tax_rounding/models/account_move.py @@ -0,0 +1,58 @@ +# Copyright NuoBiT Solutions - Frank Cespedes +# 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)] diff --git a/l10n_es_facturae_tax_rounding/models/account_tax.py b/l10n_es_facturae_tax_rounding/models/account_tax.py new file mode 100644 index 000000000..651802f33 --- /dev/null +++ b/l10n_es_facturae_tax_rounding/models/account_tax.py @@ -0,0 +1,18 @@ +# Copyright NuoBiT Solutions - Frank Cespedes +# 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 diff --git a/l10n_es_facturae_tax_rounding/readme/CONTRIBUTORS.rst b/l10n_es_facturae_tax_rounding/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..708936c8d --- /dev/null +++ b/l10n_es_facturae_tax_rounding/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `NuoBiT `_: + + * Frank Cespedes diff --git a/l10n_es_facturae_tax_rounding/readme/DESCRIPTION.rst b/l10n_es_facturae_tax_rounding/readme/DESCRIPTION.rst new file mode 100644 index 000000000..12b6e2a49 --- /dev/null +++ b/l10n_es_facturae_tax_rounding/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module generates the Facturae with the tax amounts rounded according to the total tax amount by group. diff --git a/l10n_es_facturae_tax_rounding/static/description/icon.png b/l10n_es_facturae_tax_rounding/static/description/icon.png new file mode 100644 index 000000000..1cd641e79 Binary files /dev/null and b/l10n_es_facturae_tax_rounding/static/description/icon.png differ diff --git a/l10n_es_facturae_tax_rounding/static/description/index.html b/l10n_es_facturae_tax_rounding/static/description/index.html new file mode 100644 index 000000000..6e0d92862 --- /dev/null +++ b/l10n_es_facturae_tax_rounding/static/description/index.html @@ -0,0 +1,420 @@ + + + + + + +L10n ES Facturae Tax Rounding + + + +
+

L10n ES Facturae Tax Rounding

+ + +

Beta License: AGPL-3 NuoBiT/odoo-addons

+

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

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • NuoBiT Solutions
  • +
  • S.L.
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is part of the NuoBiT/odoo-addons project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/l10n_es_facturae_tax_rounding/views/report_facturae.xml b/l10n_es_facturae_tax_rounding/views/report_facturae.xml new file mode 100644 index 000000000..ac235851b --- /dev/null +++ b/l10n_es_facturae_tax_rounding/views/report_facturae.xml @@ -0,0 +1,21 @@ + + + + + diff --git a/setup/l10n_es_facturae_tax_rounding/odoo/addons/l10n_es_facturae_tax_rounding b/setup/l10n_es_facturae_tax_rounding/odoo/addons/l10n_es_facturae_tax_rounding new file mode 120000 index 000000000..936e722b5 --- /dev/null +++ b/setup/l10n_es_facturae_tax_rounding/odoo/addons/l10n_es_facturae_tax_rounding @@ -0,0 +1 @@ +../../../../l10n_es_facturae_tax_rounding \ No newline at end of file diff --git a/setup/l10n_es_facturae_tax_rounding/setup.py b/setup/l10n_es_facturae_tax_rounding/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/l10n_es_facturae_tax_rounding/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)