Browse Source

[FIX] mis_builder: do not raise inside function fields

pull/86/head
Stéphane Bidoul 10 years ago
parent
commit
aa5893c730
  1. 54
      mis_builder/models/mis_builder.py
  2. 3
      mis_builder/views/mis_builder.xml

54
mis_builder/models/mis_builder.py

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

3
mis_builder/views/mis_builder.xml

@ -172,7 +172,7 @@
<field name="target_move"/> <field name="target_move"/>
<field name="date"/> <field name="date"/>
<field name="period_ids"> <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="sequence" widget="handle"/>
<field name="name"/> <field name="name"/>
<field name="type"/> <field name="type"/>
@ -183,6 +183,7 @@
<field name="date_to"/> <field name="date_to"/>
<field name="period_from"/> <field name="period_from"/>
<field name="period_to"/> <field name="period_to"/>
<field name="valid" invisible="1"/>
<field name="report_instance_id" invisible="1"/> <field name="report_instance_id" invisible="1"/>
<field name="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"/> <field name="comparison_column_ids" domain="[('report_instance_id', '=', report_instance_id), ('id', '!=', id)]" widget="many2many_tags"/>

Loading…
Cancel
Save