Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Month and Year in Relative to report base date #20

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ before_install:
- "sh -e /etc/init.d/xvfb start"

install:
- git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- git clone -b pip-install-sbi https://github.com/acsone/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- export WKHTMLTOPDF_VERSION=0.12.4
- travis_install_nightly
Expand Down
23 changes: 23 additions & 0 deletions mis_builder/models/mis_report_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

import datetime
from dateutil.relativedelta import relativedelta
import logging

from odoo import api, fields, models, _
Expand Down Expand Up @@ -111,6 +112,26 @@ 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 == 'm':
date_from = d.replace(day=1)
date_from = date_from + \
relativedelta(months=record.offset)
date_to = date_from + \
relativedelta(months=record.duration-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 == 'y':
date_from = d.replace(month=1, day=1)
date_from = date_from + \
relativedelta(years=record.offset)
date_to = date_from + \
relativedelta(years=record.duration-1)
date_to = date_to.replace(month=12, 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 @@ -148,6 +169,8 @@ def _compute_dates(self):
type = fields.Selection(
[('d', _('Day')),
('w', _('Week')),
('m', _('Month')),
('y', _('Year')),
('date_range', _('Date Range'))],
string='Period type'
)
Expand Down
28 changes: 28 additions & 0 deletions mis_builder/tests/test_period_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,34 @@ def test_rel_week(self):
self.assertEqual(self.period.date_to, '2017-01-15')
self.assertTrue(self.period.valid)

def test_rel_month(self):
self.instance.write(dict(
comparison_mode=True,
date='2017-01-01'
))
self.period.write(dict(
mode=MODE_REL,
type='m',
offset='1',
))
self.assertEqual(self.period.date_from, '2017-02-01')
self.assertEqual(self.period.date_to, '2017-02-28')
self.assertTrue(self.period.valid)

def test_rel_year(self):
self.instance.write(dict(
comparison_mode=True,
date='2017-01-01'
))
self.period.write(dict(
mode=MODE_REL,
type='y',
offset='1',
))
self.assertEqual(self.period.date_from, '2018-01-01')
self.assertEqual(self.period.date_to, '2018-12-31')
self.assertTrue(self.period.valid)

def test_rel_date_range(self):
# create a few date ranges
date_range_type = self.env['date.range.type'].create(dict(
Expand Down
6 changes: 0 additions & 6 deletions oca_dependencies.txt

This file was deleted.