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] [16.0] l10n_es_vat_prorate: Recompute VAT prorate bills and refunds in a period #4014

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions l10n_es_vat_prorate/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Prorrata de IVA

El módulo nos divide los IVA según la prorrata de la compañía.

Permite recalcular la prórrata del IVA de todas las facturas y reembolsos de proveedores para un periodo determinado.

**Table of contents**

.. contents::
Expand Down Expand Up @@ -76,6 +78,8 @@ Contributors
* Pedro M. Baeza
* Carolina Fernandez

* Eduardo de Miguel (`Moduon <https://www.moduon.team/>`__)

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

Expand Down
55 changes: 47 additions & 8 deletions l10n_es_vat_prorate/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,32 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-10-09 05:51+0000\n"
"Last-Translator: Ivorra78 <[email protected]>\n"
"Language-Team: none\n"
"POT-Creation-Date: 2025-02-14 09:33+0000\n"
"PO-Revision-Date: 2025-02-14 10:36+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.4.4\n"

#. module: l10n_es_vat_prorate
#: model:ir.model.fields,help:l10n_es_vat_prorate.field_account_tax__prorate_account_ids
msgid "Accounts to apply the recompute"
msgstr "Cuentas para aplicar el recálculo"

#. module: l10n_es_vat_prorate
#: model_terms:ir.ui.view,arch_db:l10n_es_vat_prorate.res_company_vat_prorate_tree_view
msgid ""
"Are you sure you want to recompute prorata in all Bills and Refunds of this "
"period? This action cannot be undone."
msgstr ""
"¿Estás seguro que quieres recomputar la prórrata del IVA en todas las "
"Facturas y Reembolsos de Proveedores para este periodo? Esta acción no se "
"puede deshacer."

#. module: l10n_es_vat_prorate
#: model:ir.model,name:l10n_es_vat_prorate.model_res_company
msgid "Companies"
Expand Down Expand Up @@ -64,7 +75,7 @@ msgstr "ID (identificación)"
#. module: l10n_es_vat_prorate
#: model:ir.model,name:l10n_es_vat_prorate.model_account_move_line
msgid "Journal Item"
msgstr "Artículo Diario"
msgstr "Apunte contable"

#. module: l10n_es_vat_prorate
#: model:ir.model.fields,field_description:l10n_es_vat_prorate.field_res_company_vat_prorate____last_update
Expand Down Expand Up @@ -101,6 +112,19 @@ msgstr ""
msgid "Prorrate Investment Account"
msgstr ""

#. module: l10n_es_vat_prorate
#: model_terms:ir.ui.view,arch_db:l10n_es_vat_prorate.res_company_vat_prorate_form_view
#: model_terms:ir.ui.view,arch_db:l10n_es_vat_prorate.res_company_vat_prorate_tree_view
msgid "Recompute period"
msgstr "Recomputar periodo"

#. module: l10n_es_vat_prorate
#: model_terms:ir.ui.view,arch_db:l10n_es_vat_prorate.res_company_vat_prorate_tree_view
msgid "Recompute prorata in all Bills and Refunds of this period"
msgstr ""
"Recomputar la prórrata del IVA en estas Facturas y Reembolsos de este "
"periodo"

#. module: l10n_es_vat_prorate
#: model:ir.model,name:l10n_es_vat_prorate.model_account_tax
msgid "Tax"
Expand All @@ -114,7 +138,22 @@ msgstr "Plantilla con prorrateo del IVA"
#. module: l10n_es_vat_prorate
#: model:ir.model,name:l10n_es_vat_prorate.model_account_tax_template
msgid "Templates for Taxes"
msgstr "Plantillas para impuestos"
msgstr "Plantilla de impuestos"

#. module: l10n_es_vat_prorate
#: model_terms:ir.ui.view,arch_db:l10n_es_vat_prorate.res_company_vat_prorate_form_view
msgid "This action will recompute Prorata in all Bills of this period"
msgstr ""
"Esta acción recomputará la prórrata del IVA en todas las Facturas y "
"Reembolsos de este periodo"

#. module: l10n_es_vat_prorate
#. odoo-python
#: code:addons/l10n_es_vat_prorate/models/res_company.py:0
#, python-format
msgid "Unable to recompute VAT prorate Bills and Refunds"
msgstr ""
"Imposible recomputar la prórrata del IVA en estas Facturas y Reembolsos"

#. module: l10n_es_vat_prorate
#: model_terms:ir.ui.view,arch_db:l10n_es_vat_prorate.res_company_form_view
Expand Down
32 changes: 32 additions & 0 deletions l10n_es_vat_prorate/i18n/l10n_es_vat_prorate.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-02-14 09:33+0000\n"
"PO-Revision-Date: 2025-02-14 09:33+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand All @@ -18,6 +20,13 @@ msgstr ""
msgid "Accounts to apply the recompute"
msgstr ""

#. module: l10n_es_vat_prorate
#: model_terms:ir.ui.view,arch_db:l10n_es_vat_prorate.res_company_vat_prorate_tree_view
msgid ""
"Are you sure you want to recompute prorata in all Bills and Refunds of this "
"period? This action cannot be undone."
msgstr ""

#. module: l10n_es_vat_prorate
#: model:ir.model,name:l10n_es_vat_prorate.model_res_company
msgid "Companies"
Expand Down Expand Up @@ -98,6 +107,17 @@ msgstr ""
msgid "Prorrate Investment Account"
msgstr ""

#. module: l10n_es_vat_prorate
#: model_terms:ir.ui.view,arch_db:l10n_es_vat_prorate.res_company_vat_prorate_form_view
#: model_terms:ir.ui.view,arch_db:l10n_es_vat_prorate.res_company_vat_prorate_tree_view
msgid "Recompute period"
msgstr ""

#. module: l10n_es_vat_prorate
#: model_terms:ir.ui.view,arch_db:l10n_es_vat_prorate.res_company_vat_prorate_tree_view
msgid "Recompute prorata in all Bills and Refunds of this period"
msgstr ""

#. module: l10n_es_vat_prorate
#: model:ir.model,name:l10n_es_vat_prorate.model_account_tax
msgid "Tax"
Expand All @@ -113,6 +133,18 @@ msgstr ""
msgid "Templates for Taxes"
msgstr ""

#. module: l10n_es_vat_prorate
#: model_terms:ir.ui.view,arch_db:l10n_es_vat_prorate.res_company_vat_prorate_form_view
msgid "This action will recompute Prorata in all Bills of this period"
msgstr ""

#. module: l10n_es_vat_prorate
#. odoo-python
#: code:addons/l10n_es_vat_prorate/models/res_company.py:0
#, python-format
msgid "Unable to recompute VAT prorate Bills and Refunds"
msgstr ""

#. module: l10n_es_vat_prorate
#: model_terms:ir.ui.view,arch_db:l10n_es_vat_prorate.res_company_form_view
msgid "VAT Prorate"
Expand Down
51 changes: 51 additions & 0 deletions l10n_es_vat_prorate/models/res_company.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Copyright 2022 Creu Blanca
# Copyright 2023 Tecnativa Carolina Fernandez
# Copyright 2025 Moduon Team
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging

from odoo import _, api, fields, models, tools
from odoo.exceptions import ValidationError

_logger = logging.getLogger(__name__)


class ResCompany(models.Model):
_inherit = "res.company"
Expand Down Expand Up @@ -85,6 +90,52 @@
date = fields.Date(required=True, default=fields.Date.today())
vat_prorate = fields.Float()

def action_recompute_period(self):
self.ensure_one()
next_vat_prorate_period = self.search(
[
("company_id", "=", self.company_id.id),
("date", ">", self.date),
],
limit=1,
order="date ASC",
)
move_domain = [
("move_type", "in", ["in_invoice", "in_refund"]),
("state", "=", "posted"),
("date", ">=", self.date),
]
if next_vat_prorate_period:
move_domain.append(("date", "<", next_vat_prorate_period.date))

Check warning on line 109 in l10n_es_vat_prorate/models/res_company.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_vat_prorate/models/res_company.py#L109

Added line #L109 was not covered by tests

unable_to_recompute_moves = self.env["account.move"].browse()
for move in self.env["account.move"].search(move_domain):
all_reconciled_lines = move.line_ids._all_reconciled_lines()
# Reset to draft
try:
move.button_draft()
except Exception as ex:
_logger.warning("Unable to re-prorate %s", move, exc_info=ex)
unable_to_recompute_moves |= move
continue

Check warning on line 120 in l10n_es_vat_prorate/models/res_company.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_vat_prorate/models/res_company.py#L117-L120

Added lines #L117 - L120 were not covered by tests
# Clear and Set taxes
inv_line_map = {
inv_line: inv_line.tax_ids.ids for inv_line in move.invoice_line_ids
}
move.invoice_line_ids.write({"tax_ids": [(6, 0, [])]})
for inv_line, tax_ids in inv_line_map.items():
inv_line.write({"tax_ids": [(6, 0, tax_ids)]})
move.action_post()
all_reconciled_lines.reconcile()

if not unable_to_recompute_moves:
return True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quizás no venga mal un mensaje que informe que no hay nada que recomputar, para no darle al botón por y pensar que ha hecho algo


action = self.env.ref("account.action_move_in_invoice_type").read()[0]
action["display_name"] = _("Unable to recompute VAT prorate Bills and Refunds")
action["domain"] = [("id", "in", unable_to_recompute_moves.ids)]
return action

Check warning on line 137 in l10n_es_vat_prorate/models/res_company.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_vat_prorate/models/res_company.py#L134-L137

Added lines #L134 - L137 were not covered by tests

_sql_constraints = [
(
"vat_prorate_percent_amount",
Expand Down
2 changes: 2 additions & 0 deletions l10n_es_vat_prorate/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

* Pedro M. Baeza
* Carolina Fernandez

* Eduardo de Miguel (`Moduon <https://www.moduon.team/>`__)
2 changes: 2 additions & 0 deletions l10n_es_vat_prorate/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
El módulo nos divide los IVA según la prorrata de la compañía.

Permite recalcular la prórrata del IVA de todas las facturas y reembolsos de proveedores para un periodo determinado.
2 changes: 2 additions & 0 deletions l10n_es_vat_prorate/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ <h1 class="title">Prorrata de IVA</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/l10n-spain/tree/16.0/l10n_es_vat_prorate"><img alt="OCA/l10n-spain" src="https://img.shields.io/badge/github-OCA%2Fl10n--spain-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-spain-16-0/l10n-spain-16-0-l10n_es_vat_prorate"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/l10n-spain&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>El módulo nos divide los IVA según la prorrata de la compañía.</p>
<p>Permite recalcular la prórrata del IVA de todas las facturas y reembolsos de proveedores para un periodo determinado.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand Down Expand Up @@ -425,6 +426,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Carolina Fernandez</li>
</ul>
</li>
<li>Eduardo de Miguel (<a class="reference external" href="https://www.moduon.team/">Moduon</a>)</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
20 changes: 13 additions & 7 deletions l10n_es_vat_prorate/tests/test_prorate_sii.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
from datetime import date
from unittest import skipIf

from odoo.tests.common import tagged
from odoo.tests.common import TransactionCase, tagged

from odoo.addons.l10n_es_aeat_sii_oca.tests import test_l10n_es_aeat_sii
try:
from odoo.addons.l10n_es_aeat_sii_oca.tests.test_l10n_es_aeat_sii import (
TestL10nEsAeatSiiBase,
)
except ModuleNotFoundError:
TestL10nEsAeatSiiBase = TransactionCase

Check warning on line 11 in l10n_es_vat_prorate/tests/test_prorate_sii.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_vat_prorate/tests/test_prorate_sii.py#L10-L11

Added lines #L10 - L11 were not covered by tests


@tagged("-at_install", "post_install")
class TestSIIVatProrate(test_l10n_es_aeat_sii.TestL10nEsAeatSiiBase):
@skipIf(
TestL10nEsAeatSiiBase is TransactionCase, "l10n_es_aeat_sii_oca seems not installed"
)
class TestSIIVatProrate(TestL10nEsAeatSiiBase):
@classmethod
def setUpClass(cls):
try:
super().setUpClass()
except Exception:
cls.skipTest(cls, "l10n_es_aeat_sii_oca seems not installed")
super().setUpClass()
cls.company.write(
{
"with_vat_prorate": True,
Expand Down
32 changes: 31 additions & 1 deletion l10n_es_vat_prorate/tests/test_vat_prorate.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Copyright 2022 Creu Blanca
# Copyright 2023 Tecnativa - Pedro M. Baeza
# Copyright 2023 Tecnativa - Carolina Fernandez
# Copyright 2025 Moduon Team
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from datetime import date

from psycopg2 import IntegrityError

from odoo import exceptions
from odoo.tests.common import tagged
from odoo.tests.common import Form, tagged
from odoo.tools import mute_logger

from odoo.addons.account.tests.common import AccountTestInvoicingCommon
Expand Down Expand Up @@ -215,3 +216,32 @@ def test_prorate_make_refund(self):
self.assertEqual(len(tax_lines), 2)
# One of the tax lines should have expense account and the other the tax account
self.assertNotEqual(tax_lines[0].account_id, tax_lines[1].account_id)

def test_prorate_recompute_period(self):
self.product_b.property_account_expense_id = self.company_data[
"default_account_assets"
]
invoice = self.init_invoice("in_invoice", products=[self.product_b], post=True)
initial_prorate_amount = sum(
invoice.line_ids.filtered_domain([("vat_prorate", "=", True)]).mapped(
"balance"
)
)
action_data = invoice.action_register_payment()
wizard = Form(
self.env["account.payment.register"].with_context(**action_data["context"])
).save()
wizard.action_create_payments()
self.assertIn(invoice.payment_state, ["in_payment", "paid"])
company_prorate = self.env.company.vat_prorate_ids[0]
company_prorate.vat_prorate += 10
company_prorate.action_recompute_period()
invoice.invalidate_recordset()
final_prorate_amount = sum(
invoice.line_ids.filtered_domain([("vat_prorate", "=", True)]).mapped(
"balance"
)
)
self.assertNotEqual(initial_prorate_amount, final_prorate_amount)
self.assertEqual(invoice.state, "posted")
self.assertIn(invoice.payment_state, ["in_payment", "paid"])
20 changes: 19 additions & 1 deletion l10n_es_vat_prorate/views/res_company_prorate_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
<field name="model">res.company.vat.prorate</field>
<field name="arch" type="xml">
<form>
<header />
<header>
<button
name="action_recompute_period"
string="Recompute period"
type="object"
class="oe_highlight"
confirm="This action will recompute Prorata in all Bills of this period"
/>
</header>
<sheet>
<group>
<field name="company_id" />
Expand All @@ -25,6 +33,16 @@
<tree editable="bottom">
<field name="date" />
<field name="vat_prorate" />
<button
name="action_recompute_period"
string=""
title="Recompute period"
help="Recompute prorata in all Bills and Refunds of this period"
icon="fa-history"
type="object"
class="btn-secondary"
confirm="Are you sure you want to recompute prorata in all Bills and Refunds of this period? This action cannot be undone."
/>
</tree>
</field>
</record>
Expand Down