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 l10n_it_withholding_tax_financial_report: Make l10n_it_withholding_tax and account_financial_report work together #4120

Merged
Merged
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
85 changes: 85 additions & 0 deletions l10n_it_withholding_tax_financial_report/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
============================================
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/16.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-16-0/l10n-italy-16-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=16.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 <https://github.com/OCA/l10n-italy/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/l10n-italy/issues/new?body=module:%20l10n_it_withholding_tax_financial_report%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
-------

* Innovyou

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

- Lorenzo Battistini https://www.innovyou.co/

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 <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-eLBati|

This module is part of the `OCA/l10n-italy <https://github.com/OCA/l10n-italy/tree/16.0/l10n_it_withholding_tax_financial_report>`_ 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 l10n_it_withholding_tax_financial_report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import report
23 changes: 23 additions & 0 deletions l10n_it_withholding_tax_financial_report/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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": "16.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",
],
}
3 changes: 3 additions & 0 deletions l10n_it_withholding_tax_financial_report/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Lorenzo Battistini <https://www.innovyou.co/>
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions l10n_it_withholding_tax_financial_report/report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import open_items
from . import open_items_xlsx
70 changes: 70 additions & 0 deletions l10n_it_withholding_tax_financial_report/report/open_items.py
Original file line number Diff line number Diff line change
@@ -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")

Check warning on line 10 in l10n_it_withholding_tax_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items.py#L8-L10

Added lines #L8 - L10 were not covered by tests
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

Check warning on line 15 in l10n_it_withholding_tax_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items.py#L13-L15

Added lines #L13 - L15 were not covered by tests

def _get_data(
self,
account_ids,
partner_ids,
date_at_object,
only_posted_moves,
company_id,
date_from,
):
res = super()._get_data(

Check warning on line 26 in l10n_it_withholding_tax_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items.py#L26

Added line #L26 was not covered by tests
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"])

Check warning on line 35 in l10n_it_withholding_tax_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items.py#L35

Added line #L35 was not covered by tests
if move_line.move_id.withholding_tax:
amount_net_pay, amount_net_pay_residual = self._get_net_pay_amounts(

Check warning on line 37 in l10n_it_withholding_tax_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items.py#L37

Added line #L37 was not covered by tests
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

Check warning on line 41 in l10n_it_withholding_tax_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items.py#L40-L41

Added lines #L40 - L41 were not covered by tests
else:
move_line_vals["amount_net_pay"] = move_line_vals.get("original")
move_line_vals["amount_net_pay_residual"] = move_line_vals.get(

Check warning on line 44 in l10n_it_withholding_tax_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items.py#L43-L44

Added lines #L43 - L44 were not covered by tests
"amount_residual"
)
return res

Check warning on line 47 in l10n_it_withholding_tax_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items.py#L47

Added line #L47 was not covered by tests

def _calculate_amounts(self, open_items_move_lines_data):
total_amount = super()._calculate_amounts(open_items_move_lines_data)

Check warning on line 50 in l10n_it_withholding_tax_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items.py#L50

Added line #L50 was not covered by tests
for account_id in total_amount:
total_amount[account_id]["amount_net_pay_residual"] = 0.0

Check warning on line 52 in l10n_it_withholding_tax_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items.py#L52

Added line #L52 was not covered by tests
for partner_id in open_items_move_lines_data[account_id].keys():
total_amount[account_id][partner_id]["amount_net_pay_residual"] = 0.0

Check warning on line 54 in l10n_it_withholding_tax_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items.py#L54

Added line #L54 was not covered by tests
for move_line_vals in open_items_move_lines_data[account_id][
partner_id
]:
move_line = self.env["account.move.line"].browse(

Check warning on line 58 in l10n_it_withholding_tax_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items.py#L58

Added line #L58 was not covered by tests
move_line_vals["id"]
)
_, amount_net_pay_residual = self._get_net_pay_amounts(

Check warning on line 61 in l10n_it_withholding_tax_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items.py#L61

Added line #L61 was not covered by tests
move_line, move_line_vals["original"]
)
total_amount[account_id][partner_id][

Check warning on line 64 in l10n_it_withholding_tax_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items.py#L64

Added line #L64 was not covered by tests
"amount_net_pay_residual"
] += amount_net_pay_residual
total_amount[account_id][

Check warning on line 67 in l10n_it_withholding_tax_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items.py#L67

Added line #L67 was not covered by tests
"amount_net_pay_residual"
] += amount_net_pay_residual
return total_amount

Check warning on line 70 in l10n_it_withholding_tax_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items.py#L70

Added line #L70 was not covered by tests
54 changes: 54 additions & 0 deletions l10n_it_withholding_tax_financial_report/report/open_items_xlsx.py
Original file line number Diff line number Diff line change
@@ -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 = {

Check warning on line 12 in l10n_it_withholding_tax_financial_report/report/open_items_xlsx.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items_xlsx.py#L8-L12

Added lines #L8 - L12 were not covered by tests
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

Check warning on line 28 in l10n_it_withholding_tax_financial_report/report/open_items_xlsx.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items_xlsx.py#L27-L28

Added lines #L27 - L28 were not covered by tests

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][

Check warning on line 40 in l10n_it_withholding_tax_financial_report/report/open_items_xlsx.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items_xlsx.py#L40

Added line #L40 was not covered by tests
"amount_net_pay_residual"
]
elif type_object == "account":
my_object["amount_net_pay_residual"] = total_amount[account_id][

Check warning on line 44 in l10n_it_withholding_tax_financial_report/report/open_items_xlsx.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items_xlsx.py#L44

Added line #L44 was not covered by tests
"amount_net_pay_residual"
]
return super().write_ending_balance_from_dict(

Check warning on line 47 in l10n_it_withholding_tax_financial_report/report/open_items_xlsx.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax_financial_report/report/open_items_xlsx.py#L47

Added line #L47 was not covered by tests
my_object,
type_object,
total_amount,
report_data,
account_id=account_id,
partner_id=partner_id,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template
id="report_open_items_lines_header_wt"
inherit_id="account_financial_report.report_open_items_lines_header"
>
<xpath expr="//div[@style='width: 15.07%;']" position="attributes">
<attribute name="style">width:11.93%</attribute>
</xpath>
<xpath expr="//div[@style='width: 24.5%;']" position="attributes">
<attribute name="style">width:14.5%</attribute>
</xpath>
<xpath expr="//t[@t-if='foreign_currency']" position="after">
<div class="act_as_cell" style="width: 6.57%;">Net to pay</div>
<div class="act_as_cell" style="width: 6.57%;">Residual net to pay</div>
</xpath>
</template>
<template
id="report_open_items_lines_wt"
inherit_id="account_financial_report.report_open_items_lines"
>
<xpath expr="//t[@t-if='foreign_currency']" position="after">
<div class="act_as_cell amount">
<span
t-if="line.get('amount_net_pay', False)"
t-esc="line['amount_net_pay']"
t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"
/>
</div>
<div class="act_as_cell amount">
<span
t-if="line.get('amount_net_pay_residual', False)"
t-esc="line['amount_net_pay_residual']"
t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"
/>
</div>
</xpath>
</template>
<template
id="report_open_items_ending_cumul_wt"
inherit_id="account_financial_report.report_open_items_ending_cumul"
>
<xpath expr="//div[hasclass('act_as_row')]/t[1]/div[1]" position="attributes">
<attribute name="style">width:23.2%</attribute>
</xpath>
<xpath expr="//div[hasclass('act_as_row')]/t[2]/div[1]" position="attributes">
<attribute name="style">width:23.2%</attribute>
</xpath>
<xpath expr="//t[@t-if='foreign_currency']" position="after">
<div class="act_as_cell amount" style="width: 6.57%;" />
<div class="act_as_cell amount" style="width: 6.57%;">
<t t-if='type == "account_type"'>
<span
t-esc="total_amount[account_id]['amount_net_pay_residual']"
t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"
/>
</t>
<t t-if='type == "partner_type"'>
<span
t-esc="total_amount[account_id][partner_id]['amount_net_pay_residual']"
t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"
/>
</t>
</div>
</xpath>
</template>
</odoo>
Loading
Loading