Skip to content

Commit

Permalink
Restore _intersect_days (as a model method)
Browse files Browse the repository at this point in the history
Semi supported to allow overrides.
  • Loading branch information
sbidoul committed Apr 23, 2020
1 parent 2e4e494 commit f31a56b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion mis_builder/models/mis_kpi_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def _compute_name(self):
rec.date_to,
)

@api.model
def _intersect_days(self, item_dt_from, item_dt_to, dt_from, dt_to):
return intersect_days(item_dt_from, item_dt_to, dt_from, dt_to)

@api.model
def _query_kpi_data(self, date_from, date_to, base_domain):
"""Query mis.kpi.data over a time period.
Expand All @@ -86,7 +90,9 @@ def _query_kpi_data(self, date_from, date_to, base_domain):
for item in self.search(domain):
item_dt_from = fields.Date.from_string(item.date_from)
item_dt_to = fields.Date.from_string(item.date_to)
i_days, item_days = intersect_days(item_dt_from, item_dt_to, dt_from, dt_to)
i_days, item_days = self._intersect_days(
item_dt_from, item_dt_to, dt_from, dt_to
)
if item.kpi_expression_id.kpi_id.accumulation_method == ACC_SUM:
# accumulate pro-rata overlap between item and reporting period
res[item.kpi_expression_id] += item.amount * i_days / item_days
Expand Down
6 changes: 5 additions & 1 deletion mis_builder/models/prorata_read_group_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def _search_date(self, operator, value):
_("Unsupported operator %s for searching on date") % (operator,)
)

@api.model
def _intersect_days(self, item_dt_from, item_dt_to, dt_from, dt_to):
return intersect_days(item_dt_from, item_dt_to, dt_from, dt_to)

@api.model
def read_group(
self, domain, flds, groupby, offset=0, limit=None, orderby=False, lazy=True
Expand Down Expand Up @@ -76,7 +80,7 @@ def read_group(
for sum_field in sum_fields:
item_dt_from = fields.Date.from_string(item["date_from"])
item_dt_to = fields.Date.from_string(item["date_to"])
i_days, item_days = intersect_days(
i_days, item_days = self._intersect_days(
item_dt_from, item_dt_to, dt_from, dt_to
)
res_item[sum_field] += item[sum_field] * i_days / item_days
Expand Down
3 changes: 3 additions & 0 deletions mis_builder/readme/newsfragments/280.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The ``_intersect_date`` model method has been restored on ``mis.kpi.data``,
and added on ``prorata.read_group.mixin`` as a semi-supported way to override
the pro-rata temporis budget reporting mechanism.

0 comments on commit f31a56b

Please sign in to comment.