|
@ -1,13 +1,13 @@ |
|
|
# © 2016 ACSONE SA/NV (<http://acsone.eu>) |
|
|
|
|
|
|
|
|
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>) |
|
|
# 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.tools.translate import _ |
|
|
|
|
|
|
|
|
from odoo import _, api, fields, models |
|
|
from odoo.exceptions import ValidationError |
|
|
from odoo.exceptions import ValidationError |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DateRange(models.Model): |
|
|
class DateRange(models.Model): |
|
|
_name = "date.range" |
|
|
_name = "date.range" |
|
|
|
|
|
_description = "Date Range" |
|
|
_order = "type_name,date_start" |
|
|
_order = "type_name,date_start" |
|
|
|
|
|
|
|
|
@api.model |
|
|
@api.model |
|
@ -22,7 +22,7 @@ class DateRange(models.Model): |
|
|
ondelete='restrict', domain="['|', ('company_id', '=', company_id), " |
|
|
ondelete='restrict', domain="['|', ('company_id', '=', company_id), " |
|
|
"('company_id', '=', False)]") |
|
|
"('company_id', '=', False)]") |
|
|
type_name = fields.Char( |
|
|
type_name = fields.Char( |
|
|
string='Type', related='type_id.name', readonly=True, store=True) |
|
|
|
|
|
|
|
|
related='type_id.name', readonly=True, store=True, string="Type Name") |
|
|
company_id = fields.Many2one( |
|
|
company_id = fields.Many2one( |
|
|
comodel_name='res.company', string='Company', index=1, |
|
|
comodel_name='res.company', string='Company', index=1, |
|
|
default=_default_company) |
|
|
default=_default_company) |
|
@ -34,7 +34,7 @@ class DateRange(models.Model): |
|
|
('date_range_uniq', 'unique (name,type_id, company_id)', |
|
|
('date_range_uniq', 'unique (name,type_id, company_id)', |
|
|
'A date range must be unique per company !')] |
|
|
'A date range must be unique per company !')] |
|
|
|
|
|
|
|
|
@api.onchange('company_id') |
|
|
|
|
|
|
|
|
@api.onchange('company_id', 'type_id') |
|
|
def _onchange_company_id(self): |
|
|
def _onchange_company_id(self): |
|
|
if self.company_id and self.type_id.company_id and \ |
|
|
if self.company_id and self.type_id.company_id and \ |
|
|
self.type_id.company_id != self.company_id: |
|
|
self.type_id.company_id != self.company_id: |
|
@ -54,9 +54,7 @@ class DateRange(models.Model): |
|
|
@api.constrains('type_id', 'date_start', 'date_end', 'company_id') |
|
|
@api.constrains('type_id', 'date_start', 'date_end', 'company_id') |
|
|
def _validate_range(self): |
|
|
def _validate_range(self): |
|
|
for this in self: |
|
|
for this in self: |
|
|
start = fields.Date.from_string(this.date_start) |
|
|
|
|
|
end = fields.Date.from_string(this.date_end) |
|
|
|
|
|
if start > end: |
|
|
|
|
|
|
|
|
if this.date_start > this.date_end: |
|
|
raise ValidationError( |
|
|
raise ValidationError( |
|
|
_("%s is not a valid range (%s > %s)") % ( |
|
|
_("%s is not a valid range (%s > %s)") % ( |
|
|
this.name, this.date_start, this.date_end)) |
|
|
this.name, this.date_start, this.date_end)) |
|
|