Skip to content

Commit

Permalink
[FIX] query carry forward
Browse files Browse the repository at this point in the history
  • Loading branch information
Saran440 committed Jul 30, 2024
1 parent f0eeea9 commit 4f1d149
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions budget_control/models/budget_commit_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,43 @@ def _compute_missing_analytic(self):
)
)

def _get_base_domain(self):
def _get_base_from_extension(self, res_model):
"""For module extension"""
self.ensure_one()
# TODO: Change domain to support amount_commit with json
domain = [
# ("amount_commit", ">", 0.0),
("date_commit", "<", self.to_date_commit),
("fwd_date_commit", "!=", self.to_date_commit),
]
return domain
return ""

Check warning on line 75 in budget_control/models/budget_commit_forward.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/budget_commit_forward.py#L75

Added line #L75 was not covered by tests

def _get_commit_docline(self, res_model):
def _get_base_domain_extension(self, res_model):
"""For module extension"""
return []
return ""

Check warning on line 79 in budget_control/models/budget_commit_forward.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/budget_commit_forward.py#L79

Added line #L79 was not covered by tests

def _get_name_model(self, res_model, need_replace=False):
return res_model.replace(".", "_") if need_replace else res_model

Check warning on line 82 in budget_control/models/budget_commit_forward.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/budget_commit_forward.py#L82

Added line #L82 was not covered by tests

def _get_commit_docline(self, res_model):
"""Base domain for query"""
self.ensure_one()
model_name_db = self._get_name_model(res_model, need_replace=True)
query = """

Check warning on line 88 in budget_control/models/budget_commit_forward.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/budget_commit_forward.py#L86-L88

Added lines #L86 - L88 were not covered by tests
SELECT a.id
FROM %s a
%s
, jsonb_each_text(a.amount_commit) AS kv(key, value)
WHERE value::numeric != 0 AND a.date_commit < '%s'
AND (a.fwd_date_commit != '%s' OR a.fwd_date_commit is null) %s;
"""
query_string = query % (

Check warning on line 96 in budget_control/models/budget_commit_forward.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/budget_commit_forward.py#L96

Added line #L96 was not covered by tests
model_name_db,
self._get_base_from_extension(res_model),
self.to_date_commit,
self.to_date_commit,
self._get_base_domain_extension(res_model),
)
# pylint: disable=sql-injection
self.env.cr.execute(query_string)

Check warning on line 104 in budget_control/models/budget_commit_forward.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/budget_commit_forward.py#L104

Added line #L104 was not covered by tests
# Get all domain ids, remove duplicate from many analytics in 1 line
domain_ids = list({row["id"] for row in self.env.cr.dictfetchall()})
model_name = self._get_name_model(res_model)
obj_ids = self.env[model_name].browse(domain_ids)
return obj_ids

Check warning on line 109 in budget_control/models/budget_commit_forward.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/budget_commit_forward.py#L107-L109

Added lines #L107 - L109 were not covered by tests

def _get_document_number(self, doc):
"""For module extension"""
Expand Down

0 comments on commit 4f1d149

Please sign in to comment.