You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.6 KiB

9.0 add date range Sorrento Delivery * [ADD] Basic structure for the new date range module * [IMP] Add a basic description into the README * [IMP] Basic implementation * [IMP] First working implementation * [IMP] Improve datamodel * [ADD] Add basic tests for date.range * [PEP8] * [PYLINT] * [DEL] Remove unused code * [IMP] Remove unsused dependencies into the JS * [IMP] Better operator label for date range * [DEL] Remove unused file * [IMP] Better user experience by showing the select input only once empty * [FIX]Try to fix tests that fails only on travis by adding an explicit cast on the daterange methods parameters * [FIX]Try to fix tests that fails only on travis by adding an explicit cast on the daterange methods parameters * [FIX]Try to fix tests that fails only on travis by using postgresql 9.4 * [FIX]Try with postgresql 9.2 since the daterange method has appeared in 9.2 * [IMP] Add a limitation into the module description to warm about the minimal version of postgresql to use * [IMP]Add multi-company rules * [IMP]Remove unused files * [FIX] Add missing brackets into JS * [FIX] Overlap detection when company_id is False * [IMP] Add default order for date.range * [IMP] Add date range generator * [FIX] OE compatibility * [FIX] Travis * [IMP] Code cleanup and improves test coverage * [FIX] Add missing dependency on 'web' * [PYLINT] remove unused import * [FIX] Add missing copyright * [FIX] Limits are included into the range * [IMP][date_range] Security * [IMP] Improve module description * [IMP] Spelling
9 years ago
9.0 add date range Sorrento Delivery * [ADD] Basic structure for the new date range module * [IMP] Add a basic description into the README * [IMP] Basic implementation * [IMP] First working implementation * [IMP] Improve datamodel * [ADD] Add basic tests for date.range * [PEP8] * [PYLINT] * [DEL] Remove unused code * [IMP] Remove unsused dependencies into the JS * [IMP] Better operator label for date range * [DEL] Remove unused file * [IMP] Better user experience by showing the select input only once empty * [FIX]Try to fix tests that fails only on travis by adding an explicit cast on the daterange methods parameters * [FIX]Try to fix tests that fails only on travis by adding an explicit cast on the daterange methods parameters * [FIX]Try to fix tests that fails only on travis by using postgresql 9.4 * [FIX]Try with postgresql 9.2 since the daterange method has appeared in 9.2 * [IMP] Add a limitation into the module description to warm about the minimal version of postgresql to use * [IMP]Add multi-company rules * [IMP]Remove unused files * [FIX] Add missing brackets into JS * [FIX] Overlap detection when company_id is False * [IMP] Add default order for date.range * [IMP] Add date range generator * [FIX] OE compatibility * [FIX] Travis * [IMP] Code cleanup and improves test coverage * [FIX] Add missing dependency on 'web' * [PYLINT] remove unused import * [FIX] Add missing copyright * [FIX] Limits are included into the range * [IMP][date_range] Security * [IMP] Improve module description * [IMP] Spelling
9 years ago
9.0 add date range Sorrento Delivery * [ADD] Basic structure for the new date range module * [IMP] Add a basic description into the README * [IMP] Basic implementation * [IMP] First working implementation * [IMP] Improve datamodel * [ADD] Add basic tests for date.range * [PEP8] * [PYLINT] * [DEL] Remove unused code * [IMP] Remove unsused dependencies into the JS * [IMP] Better operator label for date range * [DEL] Remove unused file * [IMP] Better user experience by showing the select input only once empty * [FIX]Try to fix tests that fails only on travis by adding an explicit cast on the daterange methods parameters * [FIX]Try to fix tests that fails only on travis by adding an explicit cast on the daterange methods parameters * [FIX]Try to fix tests that fails only on travis by using postgresql 9.4 * [FIX]Try with postgresql 9.2 since the daterange method has appeared in 9.2 * [IMP] Add a limitation into the module description to warm about the minimal version of postgresql to use * [IMP]Add multi-company rules * [IMP]Remove unused files * [FIX] Add missing brackets into JS * [FIX] Overlap detection when company_id is False * [IMP] Add default order for date.range * [IMP] Add date range generator * [FIX] OE compatibility * [FIX] Travis * [IMP] Code cleanup and improves test coverage * [FIX] Add missing dependency on 'web' * [PYLINT] remove unused import * [FIX] Add missing copyright * [FIX] Limits are included into the range * [IMP][date_range] Security * [IMP] Improve module description * [IMP] Spelling
9 years ago
9.0 add date range Sorrento Delivery * [ADD] Basic structure for the new date range module * [IMP] Add a basic description into the README * [IMP] Basic implementation * [IMP] First working implementation * [IMP] Improve datamodel * [ADD] Add basic tests for date.range * [PEP8] * [PYLINT] * [DEL] Remove unused code * [IMP] Remove unsused dependencies into the JS * [IMP] Better operator label for date range * [DEL] Remove unused file * [IMP] Better user experience by showing the select input only once empty * [FIX]Try to fix tests that fails only on travis by adding an explicit cast on the daterange methods parameters * [FIX]Try to fix tests that fails only on travis by adding an explicit cast on the daterange methods parameters * [FIX]Try to fix tests that fails only on travis by using postgresql 9.4 * [FIX]Try with postgresql 9.2 since the daterange method has appeared in 9.2 * [IMP] Add a limitation into the module description to warm about the minimal version of postgresql to use * [IMP]Add multi-company rules * [IMP]Remove unused files * [FIX] Add missing brackets into JS * [FIX] Overlap detection when company_id is False * [IMP] Add default order for date.range * [IMP] Add date range generator * [FIX] OE compatibility * [FIX] Travis * [IMP] Code cleanup and improves test coverage * [FIX] Add missing dependency on 'web' * [PYLINT] remove unused import * [FIX] Add missing copyright * [FIX] Limits are included into the range * [IMP][date_range] Security * [IMP] Improve module description * [IMP] Spelling
9 years ago
  1. # -*- coding: utf-8 -*-
  2. # © 2016 ACSONE SA/NV (<http://acsone.eu>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import api, fields, models
  5. from dateutil.rrule import (rrule,
  6. YEARLY,
  7. MONTHLY,
  8. WEEKLY,
  9. DAILY)
  10. from dateutil.relativedelta import relativedelta
  11. class DateRangeGenerator(models.TransientModel):
  12. _name = 'date.range.generator'
  13. @api.model
  14. def _default_company(self):
  15. return self.env['res.company']._company_default_get('date.range')
  16. name_prefix = fields.Char('Range name prefix', required=True)
  17. date_start = fields.Date(strint='Start date', required=True)
  18. type_id = fields.Many2one(
  19. comodel_name='date.range.type', string='Type', required=True,
  20. ondelete='cascade')
  21. company_id = fields.Many2one(
  22. comodel_name='res.company', string='Company',
  23. default=_default_company)
  24. unit_of_time = fields.Selection([
  25. (YEARLY, 'years'),
  26. (MONTHLY, 'months'),
  27. (WEEKLY, 'weeks'),
  28. (DAILY, 'days')], required=True)
  29. duration_count = fields.Integer('Duration', required=True)
  30. count = fields.Integer(
  31. string="Number of ranges to generate", required=True)
  32. @api.multi
  33. def _compute_date_ranges(self):
  34. self.ensure_one()
  35. vals = rrule(freq=self.unit_of_time, interval=self.duration_count,
  36. dtstart=fields.Date.from_string(self.date_start),
  37. count=self.count+1)
  38. vals = list(vals)
  39. date_ranges = []
  40. month_digits = len(unicode(self.count))
  41. for idx, dt_start in enumerate(vals[:-1]):
  42. date_start = fields.Date.to_string(dt_start.date())
  43. # always remove 1 day for the date_end since range limits are
  44. # inclusive
  45. dt_end = vals[idx+1].date() - relativedelta(days=1)
  46. date_end = fields.Date.to_string(dt_end)
  47. date_ranges.append({
  48. 'name': '%s%s' % (
  49. self.name_prefix,
  50. unicode(idx + 1).zfill(month_digits)),
  51. 'date_start': date_start,
  52. 'date_end': date_end,
  53. 'type_id': self.type_id.id,
  54. 'company_id': self.company_id.id})
  55. return date_ranges
  56. @api.multi
  57. def action_apply(self):
  58. date_ranges = self._compute_date_ranges()
  59. if date_ranges:
  60. for dr in date_ranges:
  61. self.env['date.range'].create(dr)
  62. return self.env['ir.actions.act_window'].for_xml_id(
  63. module='date_range', xml_id='date_range_action')