Skip to content

Commit

Permalink
[IMP] l10n_es_aeat_sii_oca: Improve SII not sent filter to use sii_en…
Browse files Browse the repository at this point in the history
…abled field

TT52143
  • Loading branch information
victoralmau committed Dec 13, 2024
1 parent 3aec00a commit ed3281c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
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 @@ class SiiMixin(models.AbstractModel):
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_registration_key_code(self):
def _compute_sii_enabled(self):
raise NotImplementedError

@api.model
def _is_unsupported_search_operator(self, operator):
return operator not in ("=", "!=")

@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

0 comments on commit ed3281c

Please sign in to comment.