|
@ -2,6 +2,8 @@ |
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|
|
|
|
|
|
|
|
from odoo import api, fields, models |
|
|
from odoo import api, fields, models |
|
|
|
|
|
from odoo.tools.translate import _ |
|
|
|
|
|
from odoo.exceptions import ValidationError |
|
|
from dateutil.rrule import (rrule, |
|
|
from dateutil.rrule import (rrule, |
|
|
YEARLY, |
|
|
YEARLY, |
|
|
MONTHLY, |
|
|
MONTHLY, |
|
@ -21,7 +23,8 @@ class DateRangeGenerator(models.TransientModel): |
|
|
date_start = fields.Date(strint='Start date', required=True) |
|
|
date_start = fields.Date(strint='Start date', required=True) |
|
|
type_id = fields.Many2one( |
|
|
type_id = fields.Many2one( |
|
|
comodel_name='date.range.type', string='Type', required=True, |
|
|
comodel_name='date.range.type', string='Type', required=True, |
|
|
ondelete='cascade') |
|
|
|
|
|
|
|
|
domain="['|', ('company_id', '=', company_id), " |
|
|
|
|
|
"('company_id', '=', False)]", ondelete='cascade') |
|
|
company_id = fields.Many2one( |
|
|
company_id = fields.Many2one( |
|
|
comodel_name='res.company', string='Company', |
|
|
comodel_name='res.company', string='Company', |
|
|
default=_default_company) |
|
|
default=_default_company) |
|
@ -58,6 +61,23 @@ class DateRangeGenerator(models.TransientModel): |
|
|
'company_id': self.company_id.id}) |
|
|
'company_id': self.company_id.id}) |
|
|
return date_ranges |
|
|
return date_ranges |
|
|
|
|
|
|
|
|
|
|
|
@api.onchange('company_id') |
|
|
|
|
|
def _onchange_company_id(self): |
|
|
|
|
|
if self.company_id and self.type_id.company_id and \ |
|
|
|
|
|
self.type_id.company_id != self.company_id: |
|
|
|
|
|
self._cache.update( |
|
|
|
|
|
self._convert_to_cache({'type_id': False}, update=True)) |
|
|
|
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
@api.constrains('company_id', 'type_id') |
|
|
|
|
|
def _check_company_id_type_id(self): |
|
|
|
|
|
for rec in self.sudo(): |
|
|
|
|
|
if rec.company_id and rec.type_id.company_id and\ |
|
|
|
|
|
rec.company_id != rec.type_id.company_id: |
|
|
|
|
|
raise ValidationError( |
|
|
|
|
|
_('The Company in the Date Range Generator and in ' |
|
|
|
|
|
'Date Range Type must be the same.')) |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
|
def action_apply(self): |
|
|
def action_apply(self): |
|
|
date_ranges = self._compute_date_ranges() |
|
|
date_ranges = self._compute_date_ranges() |
|
|