Browse Source

[FIX] mis_builder: do not raise inside function fields

pull/90/head
Stéphane Bidoul 10 years ago
parent
commit
ec6a03d182
  1. 40
      mis_builder/models/mis_builder.py
  2. 3
      mis_builder/views/mis_builder.xml

40
mis_builder/models/mis_builder.py

@ -335,6 +335,10 @@ class mis_report_instance_period(orm.Model):
ids = [ids]
res = {}
for c in self.browse(cr, uid, ids, context=context):
date_from = False
date_to = False
period_ids = None
valid = False
d = parser.parse(c.report_instance_id.pivot_date)
if c.type == 'd':
date_from = d + timedelta(days=c.offset)
@ -342,7 +346,7 @@ class mis_report_instance_period(orm.Model):
date_from = date_from.strftime(
tools.DEFAULT_SERVER_DATE_FORMAT)
date_to = date_to.strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
period_ids = None
valid = True
elif c.type == 'w':
date_from = d - timedelta(d.weekday())
date_from = date_from + timedelta(days=c.offset * 7)
@ -350,45 +354,38 @@ class mis_report_instance_period(orm.Model):
date_from = date_from.strftime(
tools.DEFAULT_SERVER_DATE_FORMAT)
date_to = date_to.strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
period_ids = None
valid = True
elif c.type == 'fp':
period_obj = self.pool['account.period']
all_period_ids = period_obj.search(
current_period_ids = period_obj.search(
cr, uid,
[('special', '=', False),
('date_start', '<=', d),
('date_stop', '>=', d),
('company_id', '=', c.company_id.id)],
order='date_start',
context=context)
current_period_ids = period_obj.search(
if current_period_ids:
all_period_ids = period_obj.search(
cr, uid,
[('special', '=', False),
('date_start', '<=', d),
('date_stop', '>=', d),
('company_id', '=', c.company_id.id)],
order='date_start',
context=context)
if not current_period_ids:
raise orm.except_orm(_("Error!"),
_("No current fiscal period for %s")
% d)
p = all_period_ids.index(current_period_ids[0]) + c.offset
if p < 0 or p >= len(all_period_ids):
raise orm.except_orm(_("Error!"),
_("No such fiscal period for %s "
"with offset %d") % (d, c.offset))
if p >= 0 and p + c.duration <= len(all_period_ids):
period_ids = all_period_ids[p:p + c.duration]
periods = period_obj.browse(cr, uid, period_ids,
context=context)
date_from = periods[0].date_start
date_to = periods[-1].date_stop
else:
raise orm.except_orm(_("Error!"),
_("Unimplemented period type %s") %
(c.type,))
valid = True
res[c.id] = {
'date_from': date_from,
'date_to': date_to,
'period_from': period_ids and period_ids[0] or False,
'period_to': period_ids and period_ids[-1] or False,
'valid': valid,
}
return res
@ -422,6 +419,9 @@ class mis_report_instance_period(orm.Model):
'period_to': fields.function(_get_dates,
type='many2one', obj='account.period',
multi="dates", string="To period"),
'valid': fields.function(_get_dates,
type='boolean',
multi='dates', string='Valid'),
'sequence': fields.integer(string='Sequence'),
'report_instance_id': fields.many2one('mis.report.instance',
string='Report Instance',
@ -712,6 +712,8 @@ class mis_report_instance(orm.Model):
cr, uid, [('code', '=', lang)], context=context)
for period in r.period_ids:
if not period.valid:
continue
# add the column header
header['']['cols'].append(dict(
name=period.name,

3
mis_builder/views/mis_builder.xml

@ -172,7 +172,7 @@
<field name="target_move"/>
<field name="date"/>
<field name="period_ids">
<tree string="KPI's" editable="bottom">
<tree string="KPI's" editable="bottom" colors="red:valid==False">
<field name="sequence" widget="handle"/>
<field name="name"/>
<field name="type"/>
@ -183,6 +183,7 @@
<field name="date_to"/>
<field name="period_from"/>
<field name="period_to"/>
<field name="valid" invisible="1"/>
<field name="report_instance_id" invisible="1"/>
<field name="id" invisible="1"/>
<field name="comparison_column_ids" domain="[('report_instance_id', '=', report_instance_id), ('id', '!=', id)]" widget="many2many_tags"/>

Loading…
Cancel
Save