Browse Source

[IMP] mis_builder: remove deprecated api.one

pull/189/head
Stéphane Bidoul 9 years ago
parent
commit
3e68d3d435
  1. 30
      mis_builder/models/mis_report.py
  2. 87
      mis_builder/models/mis_report_instance.py
  3. 4
      mis_builder/models/mis_report_style.py

30
mis_builder/models/mis_report.py

@ -496,11 +496,12 @@ class MisReportKpi(models.Model):
_order = 'sequence, id' _order = 'sequence, id'
@api.one
@api.constrains('name') @api.constrains('name')
def _check_name(self): def _check_name(self):
if not _is_valid_python_var(self.name):
raise UserError(_('The name must be a valid python identifier'))
for record in self:
if not _is_valid_python_var(record.name):
raise UserError(_('The name must be a valid python '
'identifier'))
@api.onchange('name') @api.onchange('name')
def _onchange_name(self): def _onchange_name(self):
@ -595,11 +596,12 @@ class MisReportSubkpi(models.Model):
translate=True) translate=True)
expression_ids = fields.One2many('mis.report.kpi.expression', 'subkpi_id') expression_ids = fields.One2many('mis.report.kpi.expression', 'subkpi_id')
@api.one
@api.constrains('name') @api.constrains('name')
def _check_name(self): def _check_name(self):
if not _is_valid_python_var(self.name):
raise UserError(_('The name must be a valid python identifier'))
for record in self:
if not _is_valid_python_var(record.name):
raise UserError(_('The name must be a valid python '
'identifier'))
@api.onchange('name') @api.onchange('name')
def _onchange_name(self): def _onchange_name(self):
@ -658,11 +660,11 @@ class MisReportQuery(models.Model):
_name = 'mis.report.query' _name = 'mis.report.query'
@api.one
@api.depends('field_ids') @api.depends('field_ids')
def _compute_field_names(self): def _compute_field_names(self):
field_names = [field.name for field in self.field_ids]
self.field_names = ', '.join(field_names)
for record in self:
field_names = [field.name for field in record.field_ids]
record.field_names = ', '.join(field_names)
name = fields.Char(size=32, required=True, name = fields.Char(size=32, required=True,
string='Name') string='Name')
@ -687,11 +689,12 @@ class MisReportQuery(models.Model):
_order = 'name' _order = 'name'
@api.one
@api.constrains('name') @api.constrains('name')
def _check_name(self): def _check_name(self):
if not _is_valid_python_var(self.name):
raise UserError(_('The name must be a valid python identifier'))
for record in self:
if not _is_valid_python_var(record.name):
raise UserError(_('The name must be a valid python '
'identifier'))
class MisReport(models.Model): class MisReport(models.Model):
@ -767,8 +770,9 @@ class MisReport(models.Model):
}) })
return res return res
@api.one
@api.multi
def copy(self, default=None): def copy(self, default=None):
self.ensure_one()
default = dict(default or {}) default = dict(default or {})
default['name'] = _('%s (copy)') % self.name default['name'] = _('%s (copy)') % self.name
return super(MisReport, self).copy(default) return super(MisReport, self).copy(default)

87
mis_builder/models/mis_report_instance.py

@ -20,59 +20,63 @@ class MisReportInstancePeriod(models.Model):
are defined as an offset relative to a pivot date. are defined as an offset relative to a pivot date.
""" """
@api.one
@api.multi
@api.depends('report_instance_id.pivot_date', @api.depends('report_instance_id.pivot_date',
'report_instance_id.comparison_mode', 'report_instance_id.comparison_mode',
'type', 'offset', 'duration', 'mode') 'type', 'offset', 'duration', 'mode')
def _compute_dates(self): def _compute_dates(self):
self.date_from = False
self.date_to = False
self.valid = False
report = self.report_instance_id
for record in self:
record.date_from = False
record.date_to = False
record.valid = False
report = record.report_instance_id
d = fields.Date.from_string(report.pivot_date) d = fields.Date.from_string(report.pivot_date)
if not report.comparison_mode: if not report.comparison_mode:
self.date_from = report.date_from
self.date_to = report.date_to
self.valid = True
elif self.mode == 'fix':
self.date_from = self.manual_date_from
self.date_to = self.manual_date_to
self.valid = True
elif self.type == 'd':
date_from = d + datetime.timedelta(days=self.offset)
record.date_from = report.date_from
record.date_to = report.date_to
record.valid = True
elif record.mode == 'fix':
record.date_from = record.manual_date_from
record.date_to = record.manual_date_to
record.valid = True
elif record.type == 'd':
date_from = d + datetime.timedelta(days=record.offset)
date_to = date_from + \ date_to = date_from + \
datetime.timedelta(days=self.duration - 1)
self.date_from = fields.Date.to_string(date_from)
self.date_to = fields.Date.to_string(date_to)
self.valid = True
elif self.type == 'w':
datetime.timedelta(days=record.duration - 1)
record.date_from = fields.Date.to_string(date_from)
record.date_to = fields.Date.to_string(date_to)
record.valid = True
elif record.type == 'w':
date_from = d - datetime.timedelta(d.weekday()) date_from = d - datetime.timedelta(d.weekday())
date_from = date_from + datetime.timedelta(days=self.offset * 7)
date_from = date_from + \
datetime.timedelta(days=record.offset * 7)
date_to = date_from + \ date_to = date_from + \
datetime.timedelta(days=(7 * self.duration) - 1)
self.date_from = fields.Date.to_string(date_from)
self.date_to = fields.Date.to_string(date_to)
self.valid = True
elif self.type == 'date_range':
date_range_obj = self.env['date.range']
datetime.timedelta(days=(7 * record.duration) - 1)
record.date_from = fields.Date.to_string(date_from)
record.date_to = fields.Date.to_string(date_to)
record.valid = True
elif record.type == 'date_range':
date_range_obj = record.env['date.range']
current_periods = date_range_obj.search( current_periods = date_range_obj.search(
[('type_id', '=', self.date_range_type_id.id),
[('type_id', '=', record.date_range_type_id.id),
('date_start', '<=', d), ('date_start', '<=', d),
('date_end', '>=', d), ('date_end', '>=', d),
('company_id', '=', self.report_instance_id.company_id.id)])
('company_id', '=',
record.report_instance_id.company_id.id)])
if current_periods: if current_periods:
all_periods = date_range_obj.search( all_periods = date_range_obj.search(
[('type_id', '=', self.date_range_type_id.id),
[('type_id', '=', record.date_range_type_id.id),
('company_id', '=', ('company_id', '=',
self.report_instance_id.company_id.id)],
record.report_instance_id.company_id.id)],
order='date_start') order='date_start')
all_period_ids = [p.id for p in all_periods] all_period_ids = [p.id for p in all_periods]
p = all_period_ids.index(current_periods[0].id) + self.offset
if p >= 0 and p + self.duration <= len(all_period_ids):
periods = all_periods[p:p + self.duration]
self.date_from = periods[0].date_start
self.date_to = periods[-1].date_end
self.valid = True
p = all_period_ids.index(current_periods[0].id) + \
record.offset
if p >= 0 and p + record.duration <= len(all_period_ids):
periods = all_periods[p:p + record.duration]
record.date_from = periods[0].date_start
record.date_to = periods[-1].date_end
record.valid = True
_name = 'mis.report.instance.period' _name = 'mis.report.instance.period'
@ -174,13 +178,13 @@ class MisReportInstance(models.Model):
"""The MIS report instance combines everything to compute """The MIS report instance combines everything to compute
a MIS report template for a set of periods.""" a MIS report template for a set of periods."""
@api.one
@api.depends('date') @api.depends('date')
def _compute_pivot_date(self): def _compute_pivot_date(self):
if self.date:
self.pivot_date = self.date
for record in self:
if record.date:
record.pivot_date = record.date
else: else:
self.pivot_date = fields.Date.context_today(self)
record.pivot_date = fields.Date.context_today(record)
@api.model @api.model
def _default_company(self): def _default_company(self):
@ -250,8 +254,9 @@ class MisReportInstance(models.Model):
_logger.debug('Vacuum %s Temporary MIS Builder Report', len(reports)) _logger.debug('Vacuum %s Temporary MIS Builder Report', len(reports))
return reports.unlink() return reports.unlink()
@api.one
@api.multi
def copy(self, default=None): def copy(self, default=None):
self.ensure_one()
default = dict(default or {}) default = dict(default or {})
default['name'] = _('%s (copy)') % self.name default['name'] = _('%s (copy)') % self.name
return super(MisReportInstance, self).copy(default) return super(MisReportInstance, self).copy(default)

4
mis_builder/models/mis_report_style.py

@ -45,10 +45,10 @@ class MisReportKpiStyle(models.Model):
_name = 'mis.report.style' _name = 'mis.report.style'
@api.one
@api.constrains('indent_level') @api.constrains('indent_level')
def check_positive_val(self): def check_positive_val(self):
if self.indent_level < 0:
for record in self:
if record.indent_level < 0:
raise UserError(_('Indent level must be greater than ' raise UserError(_('Indent level must be greater than '
'or equal to 0')) 'or equal to 0'))

Loading…
Cancel
Save