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 11, 2024
1 parent ac1ae1a commit 083da35
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
20 changes: 20 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

SII_VALID_INVOICE_STATES = ["posted"]
_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -810,6 +811,25 @@ 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()
final_domain = domain + [

Check warning on line 818 in l10n_es_aeat_sii_oca/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_aeat_sii_oca/models/account_move.py#L816-L818

Added lines #L816 - L818 were not covered by tests
("journal_id.sii_enabled", operator, value),
("move_type", "in", invoice_types),
]
return AND(

Check warning on line 822 in l10n_es_aeat_sii_oca/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_aeat_sii_oca/models/account_move.py#L822

Added line #L822 was not covered by tests
[
final_domain,
[
"|",
("fiscal_position_id", "=", False),
("fiscal_position_id.aeat_active", operator, value),
],
]
)

def _reverse_moves(self, default_values_list=None, cancel=False):
# OVERRIDE
if not default_values_list:
Expand Down
5 changes: 5 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,10 @@ def _compute_sii_registration_key_code(self):
def _compute_sii_enabled(self):
raise NotImplementedError

@api.model
def _search_sii_enabled(self, operator, value):
return [("company_id.sii_enabled", operator, value)]

Check warning on line 157 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#L157

Added line #L157 was not covered by tests

def _compute_macrodata(self):
for document in self:
document.sii_macrodata = (
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 083da35

Please sign in to comment.