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

[FIX] Nelle fatture con ritenuta, resettare l'importo da pagare al netto da pagare residuo #3986

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
6 changes: 6 additions & 0 deletions l10n_it_withholding_tax/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ stata versata all’erario
.. |image4| image:: https://raw.githubusercontent.com/OCA/l10n-italy/16.0/l10n_it_withholding_tax/static/img/pagamento-ritenuta.png
.. |image5| image:: https://raw.githubusercontent.com/OCA/l10n-italy/16.0/l10n_it_withholding_tax/static/img/foto-3-1-1024x505.png

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

The Residual Net To Pay set in the Payment wizard should be converted in
the wizard's currency when it changes

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

Expand Down
1 change: 1 addition & 0 deletions l10n_it_withholding_tax/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
from . import wizards
21 changes: 1 addition & 20 deletions l10n_it_withholding_tax/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.exceptions import ValidationError
from odoo.tools.float_utils import float_compare, float_round


Expand Down Expand Up @@ -482,25 +482,6 @@ def _compute_payments_widget_reconciled_info(self):
payment_val["wt_move_line"] = False
return

def action_register_payment(self):
"""
Set net to pay how default amount to pay
"""
res = super().action_register_payment()
amount_net_pay_residual = 0
currency_id = self.currency_id
if len(currency_id) > 1:
raise UserError(_("Invoices must have the same currency"))
for am in self:
if am.withholding_tax_amount:
amount_net_pay_residual += am.amount_net_pay_residual
if not currency_id.is_zero(amount_net_pay_residual):
ctx = res.get("context", {})
if ctx:
ctx.update({"default_amount": amount_net_pay_residual})
res.update({"context": ctx})
return res


class AccountMoveLine(models.Model):
_inherit = "account.move.line"
Expand Down
2 changes: 2 additions & 0 deletions l10n_it_withholding_tax/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The Residual Net To Pay set in the Payment wizard should be converted in
the wizard's currency when it changes
26 changes: 16 additions & 10 deletions l10n_it_withholding_tax/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,12 @@ <h1 class="title">ITA - Ritenute d’acconto</h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="toc-entry-1">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-2">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -433,25 +434,30 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
stata versata all’erario</p>
<p><img alt="image5" src="https://raw.githubusercontent.com/OCA/l10n-italy/16.0/l10n_it_withholding_tax/static/img/foto-3-1-1024x505.png" /></p>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h1>
<p>The Residual Net To Pay set in the Payment wizard should be converted in
the wizard’s currency when it changes</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/l10n-italy/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_withholding_tax%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>Openforce</li>
<li>Odoo Italia Network</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li>Alessandro Camilli &lt;<a class="reference external" href="mailto:alessandrocamilli&#64;openforce.it">alessandrocamilli&#64;openforce.it</a>&gt;</li>
<li>Lorenzo Battistini &lt;<a class="reference external" href="mailto:lorenzo.battistini&#64;agilebg.com">lorenzo.battistini&#64;agilebg.com</a>&gt;</li>
Expand All @@ -460,7 +466,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand Down
41 changes: 41 additions & 0 deletions l10n_it_withholding_tax/tests/test_withholding_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,44 @@ def test_wt_after_repost(self):
self.assertEqual(self.invoice.amount_net_pay_residual, 200)
self.assertEqual(self.invoice.amount_residual, 250)
self.assertEqual(self.invoice.state, "posted")

def _get_payment_wizard(self, invoice):
wizard_action = invoice.action_register_payment()
wizard_model = wizard_action["res_model"]
wizard_context = wizard_action["context"]
wizard = self.env[wizard_model].with_context(**wizard_context).create({})
return wizard

def test_payment_reset_net_pay_residual(self):
"""The amount to pay is reset to the Residual Net To Pay
when amount and Journal are changed."""
# Arrange: Pay an invoice
invoice = self.invoice
wizard = self._get_payment_wizard(invoice)
user_set_amount = 20
# pre-condition
self.assertEqual(
wizard.amount,
invoice.amount_net_pay_residual,
)
self.assertTrue(
invoice.withholding_tax_amount,
)

# Act: Change amount
wizard.amount = user_set_amount

# Assert: User's change is kept
self.assertEqual(
wizard.amount,
user_set_amount,
)

# Act: Change Journal
wizard.journal_id = self.journal_bank

# Assert: Amount is reset to the Residual Net To Pay
self.assertEqual(
wizard.amount,
invoice.amount_net_pay_residual,
)
3 changes: 3 additions & 0 deletions l10n_it_withholding_tax/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import account_payment_register
57 changes: 57 additions & 0 deletions l10n_it_withholding_tax/wizards/account_payment_register.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2023 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, models
from odoo.exceptions import UserError


class AccountPaymentRegister(models.TransientModel):
_inherit = "account.payment.register"

@api.model
def _get_wizard_values_from_batch(self, batch_result):
wizard_values_from_batch = super()._get_wizard_values_from_batch(batch_result)
self._inject_withholding_net_pay_residual(wizard_values_from_batch)
return wizard_values_from_batch

def _inject_withholding_net_pay_residual(self, wizard_values_from_batch):
"""If the payment is for Invoices having Withholding Taxes,
set the Residual Net To Pay as the amount to be paid.
"""
if self.env.context.get("active_model") == "account.move":
moves_ids = self.env.context.get("active_ids", [])
moves = self.env["account.move"].browse(moves_ids)
withholding_moves = moves.filtered("withholding_tax")
if withholding_moves:
currency = withholding_moves.currency_id
if len(currency) > 1:
raise UserError(_("Invoices must have the same currency"))

Check warning on line 28 in l10n_it_withholding_tax/wizards/account_payment_register.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_withholding_tax/wizards/account_payment_register.py#L28

Added line #L28 was not covered by tests
net_pay_residual_amount = sum(
withholding_moves.mapped("amount_net_pay_residual")
)
if not currency.is_zero(
net_pay_residual_amount,
):
wizard_values_from_batch["source_amount"] = net_pay_residual_amount
# Withholding tax amount is a simple float
# and does not change for different currencies
wizard_values_from_batch[
"source_amount_currency"
] = net_pay_residual_amount
return wizard_values_from_batch

def _get_total_amount_in_wizard_currency_to_full_reconcile(
self, batch_result, early_payment_discount=True
):
amount, mode = super()._get_total_amount_in_wizard_currency_to_full_reconcile(
batch_result, early_payment_discount=early_payment_discount
)
withholding_net_pay_residual_values = self._inject_withholding_net_pay_residual(
dict()
)
withholding_net_pay_residual = withholding_net_pay_residual_values.get(
"source_amount"
)
if withholding_net_pay_residual is not None:
amount = withholding_net_pay_residual
return amount, mode
Loading