From 6fa78b84128ef97099ff2a881425409b1cb914fb Mon Sep 17 00:00:00 2001 From: Marco Colombo Date: Fri, 31 May 2024 11:06:41 +0200 Subject: [PATCH] [FIX] l10n_it_declaration_of_intent: remove line on move.unlink() --- .../models/declaration.py | 17 +- .../tests/test_declaration_of_intent.py | 20 + .../README.rst | 89 ++++ .../__init__.py | 1 + .../__manifest__.py | 23 + .../pyproject.toml | 3 + .../readme/CONTRIBUTORS.md | 4 + .../readme/DESCRIPTION.md | 2 + .../report/__init__.py | 2 + .../report/open_items.py | 70 +++ .../report/open_items_xlsx.py | 54 +++ .../report/templates/open_items.xml | 67 +++ .../static/description/index.html | 430 ++++++++++++++++++ .../l10n_it_withholding_tax_financial_report | 1 + .../setup.py | 6 + 15 files changed, 786 insertions(+), 3 deletions(-) create mode 100644 l10n_it_withholding_tax_financial_report/README.rst create mode 100644 l10n_it_withholding_tax_financial_report/__init__.py create mode 100644 l10n_it_withholding_tax_financial_report/__manifest__.py create mode 100644 l10n_it_withholding_tax_financial_report/pyproject.toml create mode 100644 l10n_it_withholding_tax_financial_report/readme/CONTRIBUTORS.md create mode 100644 l10n_it_withholding_tax_financial_report/readme/DESCRIPTION.md create mode 100644 l10n_it_withholding_tax_financial_report/report/__init__.py create mode 100644 l10n_it_withholding_tax_financial_report/report/open_items.py create mode 100644 l10n_it_withholding_tax_financial_report/report/open_items_xlsx.py create mode 100644 l10n_it_withholding_tax_financial_report/report/templates/open_items.xml create mode 100644 l10n_it_withholding_tax_financial_report/static/description/index.html create mode 120000 setup/l10n_it_withholding_tax_financial_report/odoo/addons/l10n_it_withholding_tax_financial_report create mode 100644 setup/l10n_it_withholding_tax_financial_report/setup.py diff --git a/l10n_it_declaration_of_intent/models/declaration.py b/l10n_it_declaration_of_intent/models/declaration.py index 7bdb3d28e4d0..e95ee2bab79c 100644 --- a/l10n_it_declaration_of_intent/models/declaration.py +++ b/l10n_it_declaration_of_intent/models/declaration.py @@ -192,10 +192,21 @@ def name_get(self): ) return res - @api.depends("line_ids", "line_ids.amount", "limit_amount") + @api.depends( + "line_ids", + "line_ids.amount", + "limit_amount", + "line_ids.invoice_id", + "line_ids.invoice_id.state", + ) def _compute_amounts(self): for record in self: - amount = sum(line.amount for line in record.line_ids) + amount = sum( + line.amount + for line in record.line_ids.filtered( + lambda li: li.invoice_id and li.invoice_id.state == "posted" + ) + ) # ----- Force value to 0 if amount < 0.0: amount = 0.0 @@ -277,7 +288,7 @@ class DeclarationOfIntentLine(models.Model): ) amount = fields.Monetary() base_amount = fields.Monetary(string="Base Amount") - invoice_id = fields.Many2one("account.move", string="Invoice") + invoice_id = fields.Many2one("account.move", string="Invoice", ondelete="cascade") date_invoice = fields.Date(related="invoice_id.invoice_date", string="Date Invoice") company_id = fields.Many2one( "res.company", string="Company", related="declaration_id.company_id" diff --git a/l10n_it_declaration_of_intent/tests/test_declaration_of_intent.py b/l10n_it_declaration_of_intent/tests/test_declaration_of_intent.py index bfcbdb5b20eb..0c0c432964c4 100644 --- a/l10n_it_declaration_of_intent/tests/test_declaration_of_intent.py +++ b/l10n_it_declaration_of_intent/tests/test_declaration_of_intent.py @@ -425,6 +425,26 @@ def test_invoice_repost(self): 1, ) + def test_invoice_delete(self): + invoice = self._create_invoice( + "test_invoice_repost", self.partner1, tax=self.tax1 + ) + invoice_form = Form(invoice) + for tax in (self.tax2, self.tax22): + self._add_invoice_line_id(invoice_form, tax=tax) + invoice = invoice_form.save() + invoice.action_post() + invoice.button_draft() + invoice.with_context(force_delete=True).unlink() + self.assertEqual( + len( + self.declaration1.line_ids.filtered( + lambda line: line.invoice_id == invoice + ) + ), + 0, + ) + def test_multi_company(self): """Check that a user can only see and create declarations in his company.""" self.env = self.env(user=self.other_user) diff --git a/l10n_it_withholding_tax_financial_report/README.rst b/l10n_it_withholding_tax_financial_report/README.rst new file mode 100644 index 000000000000..a3ca02804839 --- /dev/null +++ b/l10n_it_withholding_tax_financial_report/README.rst @@ -0,0 +1,89 @@ +============================================ +ITA - Ritenute d'acconto - Financial Reports +============================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:b9ade84407d018ed04f5877cc036c0256d31d37c6e4e5d77ee66347ab4e23bf4 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fl10n--italy-lightgray.png?logo=github + :target: https://github.com/OCA/l10n-italy/tree/14.0/l10n_it_withholding_tax_financial_report + :alt: OCA/l10n-italy +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/l10n-italy-14-0/l10n-italy-14-0-l10n_it_withholding_tax_financial_report + :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/l10n-italy&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Make l10n_it_withholding_tax and account_financial_report work together, +showing the correct amount (Net To Pay) in financial reports. + +**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 +------- + +* Innovyou + +Contributors +------------ + +- Lorenzo Battistini https://www.innovyou.co/ + +- Ooops404 https://www.ooops404.com/: + + - Eduard Brahas eduardbrhas@outlook.it + +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. + +.. |maintainer-eLBati| image:: https://github.com/eLBati.png?size=40px + :target: https://github.com/eLBati + :alt: eLBati + +Current `maintainer `__: + +|maintainer-eLBati| + +This module is part of the `OCA/l10n-italy `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/l10n_it_withholding_tax_financial_report/__init__.py b/l10n_it_withholding_tax_financial_report/__init__.py new file mode 100644 index 000000000000..4c4f242fa03b --- /dev/null +++ b/l10n_it_withholding_tax_financial_report/__init__.py @@ -0,0 +1 @@ +from . import report diff --git a/l10n_it_withholding_tax_financial_report/__manifest__.py b/l10n_it_withholding_tax_financial_report/__manifest__.py new file mode 100644 index 000000000000..a7b4dfd31ff6 --- /dev/null +++ b/l10n_it_withholding_tax_financial_report/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2024 Lorenzo Battistini +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "ITA - Ritenute d'acconto - Financial Reports", + "summary": "Integrazione Ritenute d'acconto e Rendiconti contabili", + "version": "14.0.1.0.0", + "development_status": "Beta", + "category": "Hidden", + "website": "https://github.com/OCA/l10n-italy", + "author": "Innovyou, Odoo Community Association (OCA)", + "maintainers": ["eLBati"], + "license": "AGPL-3", + "application": False, + "installable": True, + "auto_install": True, + "depends": [ + "l10n_it_withholding_tax", + "account_financial_report", + ], + "data": [ + "report/templates/open_items.xml", + ], +} diff --git a/l10n_it_withholding_tax_financial_report/pyproject.toml b/l10n_it_withholding_tax_financial_report/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/l10n_it_withholding_tax_financial_report/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/l10n_it_withholding_tax_financial_report/readme/CONTRIBUTORS.md b/l10n_it_withholding_tax_financial_report/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..fd2152651b73 --- /dev/null +++ b/l10n_it_withholding_tax_financial_report/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Lorenzo Battistini + +- Ooops404 : + - Eduard Brahas diff --git a/l10n_it_withholding_tax_financial_report/readme/DESCRIPTION.md b/l10n_it_withholding_tax_financial_report/readme/DESCRIPTION.md new file mode 100644 index 000000000000..77eec9886747 --- /dev/null +++ b/l10n_it_withholding_tax_financial_report/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +Make l10n_it_withholding_tax and account_financial_report work together, +showing the correct amount (Net To Pay) in financial reports. diff --git a/l10n_it_withholding_tax_financial_report/report/__init__.py b/l10n_it_withholding_tax_financial_report/report/__init__.py new file mode 100644 index 000000000000..594ba6153132 --- /dev/null +++ b/l10n_it_withholding_tax_financial_report/report/__init__.py @@ -0,0 +1,2 @@ +from . import open_items +from . import open_items_xlsx diff --git a/l10n_it_withholding_tax_financial_report/report/open_items.py b/l10n_it_withholding_tax_financial_report/report/open_items.py new file mode 100644 index 000000000000..bf9dcd96b33a --- /dev/null +++ b/l10n_it_withholding_tax_financial_report/report/open_items.py @@ -0,0 +1,70 @@ +from odoo import models + + +class OpenItemsReport(models.AbstractModel): + _inherit = "report.account_financial_report.open_items" + + def _get_net_pay_amounts(self, move_line, original): + amount_net_pay = original + move_line.withholding_tax_amount + amount_net_pay_residual = amount_net_pay + reconciled_amls = move_line.mapped("matched_debit_ids.debit_move_id") + for line in reconciled_amls: + if not line.withholding_tax_generated_by_move_id: + amount_net_pay_residual += line.debit or line.credit + amount_net_pay_residual = amount_net_pay_residual + return amount_net_pay, amount_net_pay_residual + + def _get_data( + self, + account_ids, + partner_ids, + date_at_object, + only_posted_moves, + company_id, + date_from, + ): + res = super()._get_data( + account_ids, + partner_ids, + date_at_object, + only_posted_moves, + company_id, + date_from, + ) + for move_line_vals in res[0]: + move_line = self.env["account.move.line"].browse(move_line_vals["id"]) + if move_line.move_id.withholding_tax: + amount_net_pay, amount_net_pay_residual = self._get_net_pay_amounts( + move_line, move_line_vals["original"] + ) + move_line_vals["amount_net_pay"] = amount_net_pay + move_line_vals["amount_net_pay_residual"] = amount_net_pay_residual + else: + move_line_vals["amount_net_pay"] = move_line_vals.get("original") + move_line_vals["amount_net_pay_residual"] = move_line_vals.get( + "amount_residual" + ) + return res + + def _calculate_amounts(self, open_items_move_lines_data): + total_amount = super()._calculate_amounts(open_items_move_lines_data) + for account_id in total_amount: + total_amount[account_id]["amount_net_pay_residual"] = 0.0 + for partner_id in open_items_move_lines_data[account_id].keys(): + total_amount[account_id][partner_id]["amount_net_pay_residual"] = 0.0 + for move_line_vals in open_items_move_lines_data[account_id][ + partner_id + ]: + move_line = self.env["account.move.line"].browse( + move_line_vals["id"] + ) + _, amount_net_pay_residual = self._get_net_pay_amounts( + move_line, move_line_vals["original"] + ) + total_amount[account_id][partner_id][ + "amount_net_pay_residual" + ] += amount_net_pay_residual + total_amount[account_id][ + "amount_net_pay_residual" + ] += amount_net_pay_residual + return total_amount diff --git a/l10n_it_withholding_tax_financial_report/report/open_items_xlsx.py b/l10n_it_withholding_tax_financial_report/report/open_items_xlsx.py new file mode 100644 index 000000000000..4645803f8125 --- /dev/null +++ b/l10n_it_withholding_tax_financial_report/report/open_items_xlsx.py @@ -0,0 +1,54 @@ +from odoo import _, models + + +class OpenItemsXslx(models.AbstractModel): + _inherit = "report.a_f_r.report_open_items_xlsx" + + def _get_report_columns(self, report): + res = super()._get_report_columns(report) + last_index = list(res.keys())[-1] + net_pay_index = last_index + 1 + residual_net_pay_index = net_pay_index + 1 + net_to_pay = { + net_pay_index: { + "header": _("Net to pay"), + "field": "amount_net_pay", + "type": "amount", + "width": 14, + }, + residual_net_pay_index: { + "header": _("Residual net to pay"), + "field": "amount_net_pay_residual", + "field_final_balance": "amount_net_pay_residual", + "type": "amount", + "width": 14, + }, + } + res.update(net_to_pay) + return res + + def write_ending_balance_from_dict( + self, + my_object, + type_object, + total_amount, + report_data, + account_id=False, + partner_id=False, + ): + if type_object == "partner": + my_object["amount_net_pay_residual"] = total_amount[account_id][partner_id][ + "amount_net_pay_residual" + ] + elif type_object == "account": + my_object["amount_net_pay_residual"] = total_amount[account_id][ + "amount_net_pay_residual" + ] + return super().write_ending_balance_from_dict( + my_object, + type_object, + total_amount, + report_data, + account_id=account_id, + partner_id=partner_id, + ) diff --git a/l10n_it_withholding_tax_financial_report/report/templates/open_items.xml b/l10n_it_withholding_tax_financial_report/report/templates/open_items.xml new file mode 100644 index 000000000000..89fa8e35f57a --- /dev/null +++ b/l10n_it_withholding_tax_financial_report/report/templates/open_items.xml @@ -0,0 +1,67 @@ + + + + + + diff --git a/l10n_it_withholding_tax_financial_report/static/description/index.html b/l10n_it_withholding_tax_financial_report/static/description/index.html new file mode 100644 index 000000000000..824416896c68 --- /dev/null +++ b/l10n_it_withholding_tax_financial_report/static/description/index.html @@ -0,0 +1,430 @@ + + + + + +ITA - Ritenute d'acconto - Financial Reports + + + +
+

ITA - Ritenute d’acconto - Financial Reports

+ + +

Beta License: AGPL-3 OCA/l10n-italy Translate me on Weblate Try me on Runboat

+

Make l10n_it_withholding_tax and account_financial_report work together, +showing the correct amount (Net To Pay) in financial reports.

+

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

+
    +
  • Innovyou
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

Current maintainer:

+

eLBati

+

This module is part of the OCA/l10n-italy project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/setup/l10n_it_withholding_tax_financial_report/odoo/addons/l10n_it_withholding_tax_financial_report b/setup/l10n_it_withholding_tax_financial_report/odoo/addons/l10n_it_withholding_tax_financial_report new file mode 120000 index 000000000000..fda6c0caa527 --- /dev/null +++ b/setup/l10n_it_withholding_tax_financial_report/odoo/addons/l10n_it_withholding_tax_financial_report @@ -0,0 +1 @@ +../../../../l10n_it_withholding_tax_financial_report \ No newline at end of file diff --git a/setup/l10n_it_withholding_tax_financial_report/setup.py b/setup/l10n_it_withholding_tax_financial_report/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/l10n_it_withholding_tax_financial_report/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)