Skip to content

Commit

Permalink
quarterly period
Browse files Browse the repository at this point in the history
  • Loading branch information
collinskipkorir committed Nov 4, 2024
1 parent be2d7e5 commit a54c2df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 17 additions & 2 deletions mis_builder/models/mis_report_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ def _compute_dates(self):
record.date_from = fields.Date.to_string(date_from)
record.date_to = fields.Date.to_string(date_to)
record.valid = True

elif record.mode == MODE_REL and record.type == "q": # Quarterly period logic
date_from = d.replace(day=1)
date_from = date_from + relativedelta(months=record.offset * 3)
date_to = (
date_from
+ relativedelta(months=(record.duration * 3) - 1)
+ relativedelta(day=31)
)
record.date_from = fields.Date.to_string(date_from)
record.date_to = fields.Date.to_string(date_to)
record.valid = True

elif record.mode == MODE_REL and record.type == "date_range":
date_range_obj = record.env["date.range"]
current_periods = date_range_obj.search(
Expand Down Expand Up @@ -190,16 +203,18 @@ def _compute_dates(self):
("d", _("Day")),
("w", _("Week")),
("m", _("Month")),
("q", _("quarterly")),
("y", _("Year")),
("date_range", _("Date Range")),
],
string="Period type",
)
is_ytd = fields.Boolean(
is_ytd = (
fields.Boolean(
default=False,
string="Year to date",
help="Forces the start date to Jan 1st of the relevant year",
)
))
date_range_type_id = fields.Many2one(
comodel_name="date.range.type",
string="Date Range Type",
Expand Down
4 changes: 2 additions & 2 deletions mis_builder/views/mis_report_instance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@
invisible="type != 'date_range'"
required="type == 'date_range' and mode == 'relative'"
/>
<field name="offset" />
<field name="duration" />
<field name="offset" string="Offset (Quarters)" attrs="{'invisible': [('type', '!=', 'q')]}"/>
<field name="duration" string="Duration (Quarters)" attrs="{'invisible': [('type', '!=', 'q')]}"/>
</group>
<group>
<field name="date_from" />
Expand Down

0 comments on commit a54c2df

Please sign in to comment.