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][IMP] l10n_es_aeat_sii_oca: Improve SII not sent filter to use sii_enabled field #3836

Open
wants to merge 1 commit 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
19 changes: 19 additions & 0 deletions l10n_es_aeat_sii_oca/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from odoo import _, api, exceptions, fields, models
from odoo.modules.registry import Registry
from odoo.osv.expression import AND, OR

SII_VALID_INVOICE_STATES = ["posted"]
_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -810,6 +811,24 @@ def _compute_sii_enabled(self):
else:
invoice.sii_enabled = False

@api.model
def _search_sii_enabled(self, operator, value):
domain = super()._search_sii_enabled(operator, value)
invoice_types = self.get_sale_types() + self.get_purchase_types()
condition_1 = [("journal_id.sii_enabled", operator, value)]
condition_2 = [("fiscal_position_id.aeat_active", operator, value)]
search_ko = (operator == "=" and not value) or (operator == "!=" and value)
exp_condition = OR if search_ko else AND
if not search_ko:
condition_2 = OR([condition_2, [("fiscal_position_id", "=", False)]])
move_type_exp = "not in" if search_ko else "in"
return exp_condition(
[
[("move_type", move_type_exp, invoice_types)],
exp_condition([domain, exp_condition([condition_1, condition_2])]),
]
)

def _reverse_moves(self, default_values_list=None, cancel=False):
# OVERRIDE
if not default_values_list:
Expand Down
11 changes: 11 additions & 0 deletions l10n_es_aeat_sii_oca/models/sii_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
sii_enabled = fields.Boolean(
string="Enable SII",
compute="_compute_sii_enabled",
search="_search_sii_enabled",
)
sii_macrodata = fields.Boolean(
string="MacroData",
Expand Down Expand Up @@ -151,6 +152,16 @@
def _compute_sii_enabled(self):
raise NotImplementedError

@api.model
def _is_unsupported_search_operator(self, operator):
return operator not in ("=", "!=")
victoralmau marked this conversation as resolved.
Show resolved Hide resolved

@api.model
def _search_sii_enabled(self, operator, value):
if self._is_unsupported_search_operator(operator):
raise ValueError(_("Unsupported search operator"))

Check warning on line 162 in l10n_es_aeat_sii_oca/models/sii_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_aeat_sii_oca/models/sii_mixin.py#L162

Added line #L162 was not covered by tests
return [("company_id.sii_enabled", operator, value)]

def _compute_macrodata(self):
for document in self:
document.sii_macrodata = (
Expand Down
19 changes: 19 additions & 0 deletions l10n_es_aeat_sii_oca/tests/test_l10n_es_aeat_sii.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,25 @@ def setUpClass(cls):
[("sii_wsdl_out", "!=", False)]
)

def test_invoice_search_sii_enabled(self):
domain_base = [("id", "=", self.invoice.id)]
domain_ok = domain_base + [("sii_enabled", "=", True)]
items = self.env["account.move"].search(domain_ok)
self.assertIn(self.invoice, items)
domain_ko_1 = domain_base + [("sii_enabled", "=", False)]
items = self.env["account.move"].search(domain_ko_1)
self.assertNotIn(self.invoice, items)
domain_ko_2 = domain_base + [("sii_enabled", "!=", True)]
items = self.env["account.move"].search(domain_ko_2)
self.assertNotIn(self.invoice, items)
self.invoice.journal_id.sii_enabled = False
items = self.env["account.move"].search(domain_ok)
self.assertNotIn(self.invoice, items)
items = self.env["account.move"].search(domain_ko_1)
self.assertIn(self.invoice, items)
items = self.env["account.move"].search(domain_ko_2)
self.assertIn(self.invoice, items)

def test_intracomunitary_customer_extracomunitary_delivery(self):
"""Comprobar venta a un cliente intracomunitario enviada al extranjero.
Expand Down
2 changes: 1 addition & 1 deletion l10n_es_aeat_sii_oca/views/account_move_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
<filter
name="sii_not_sent"
string="SII not sent"
domain="[('aeat_state', '=', 'not_sent'), ('date', '>=', '2017-01-01')]"
domain="[('aeat_state', '=', 'not_sent'), ('sii_enabled', '=', True), ('date', '>=', '2017-01-01')]"
help="Never sent to SII"
/>
<filter
Expand Down
Loading