139
def link_inherit_report(self, cr, uid, report, new_replace_report_id=False, context={}):
141
if new_replace_report_id:
142
inherit_report = self.browse(cr, uid, new_replace_report_id, context=context)
144
inherit_report = report.replace_report_id
147
ir_values_obj = self.pool.get('ir.values')
148
if inherit_report.report_wizard:
149
src_action_type = 'ir.actions.act_window'
150
action_id = report.wizard_id.id
152
src_action_type = 'ir.actions.report.xml'
153
action_id = inherit_report.id
154
event_id = ir_values_obj.search(cr, uid, [('value','=',"%s,%s" % (src_action_type,action_id))])
156
event_id = event_id[0]
157
if report.report_wizard:
158
dest_action_type = 'ir.actions.act_window'
160
action_id = report.wizard_id.id
162
action_id = self._set_report_wizard(cr, uid, inherit_report.id, report.id, linked_report_id=report.id, report_name=report.name, context=context)
163
res['wizard_id'] = action_id
165
dest_action_type = 'ir.actions.report.xml'
166
action_id = report.id
167
ir_values_obj.write(cr, uid, event_id, {'value':"%s,%s" % (dest_action_type,action_id)}, context=context)
170
def unlink_inherit_report(self, cr, uid, ids, context={}):
172
report_id = isinstance(ids, list) and ids[0] or ids
173
report = self.browse(cr, uid, report_id, context=context)
174
keep_wizard = context and context.get('keep_wizard') or False
176
if report.replace_report_id:
177
ir_values_obj = self.pool.get('ir.values')
178
if report.report_wizard:
179
src_action_type = 'ir.actions.act_window'
180
action_id = report.wizard_id.id
182
res['wizard_id'] = False
184
src_action_type = 'ir.actions.report.xml'
185
action_id = report.id
186
event_id = ir_values_obj.search(cr, uid, [('value','=',"%s,%s" % (src_action_type,action_id))])
188
event_id = event_id[0]
189
if report.replace_report_id.report_wizard:
190
dest_action_type = 'ir.actions.act_window'
191
action_id = report.wizard_id.id
193
dest_action_type = 'ir.actions.report.xml'
194
action_id = report.replace_report_id.id
195
ir_values_obj.write(cr, uid, event_id, {'value':"%s,%s" % (dest_action_type,action_id)}, context=context)
197
if not keep_wizard and report.wizard_id and not res.get('wizard_id',True):
198
report.wizard_id.unlink(context=context)
139
201
def delete_report_service(self, name):
140
202
service_name = 'report.%s' % name
141
203
if netsvc.Service.exists( service_name ): # change for OpenERP 6.0 - Service class usage
152
214
if netsvc.Service.exists( service_name ):
153
215
netsvc.Service.remove( service_name )
154
216
cr.execute("SELECT * FROM ir_act_report_xml WHERE report_name = %s and active = true ORDER BY id", (name,))
155
report = cr.dictfetchall()[-1]
157
if report['parser_state']=='loc' and report['parser_loc']:
158
parser=self.load_from_file(report['parser_loc'], cr.dbname, report['id']) or parser
159
elif report['parser_state']=='def' and report['parser_def']:
160
parser=self.load_from_source("from report import report_sxw\n"+report['parser_def']) or parser
161
self.register_report(cr, report['report_name'], report['model'], report['report_rml'], parser)
217
report = cr.dictfetchall()
221
if report['parser_state']=='loc' and report['parser_loc']:
222
parser=self.load_from_file(report['parser_loc'], cr.dbname, report['id']) or parser
223
elif report['parser_state']=='def' and report['parser_def']:
224
parser=self.load_from_source("from report import report_sxw\n"+report['parser_def']) or parser
225
self.register_report(cr, report['report_name'], report['model'], report['report_rml'], parser)
163
227
def register_all(self, cr):
164
228
super(report_xml, self).register_all(cr)
281
361
'report_sxw_content': fields.function(_report_content,
282
362
fnct_inv=_report_content_inv, method=True,
283
363
type='binary', string='SXW content',),
284
'active':fields.boolean('Active'),
364
'active':fields.boolean('Active', help='Disables the report if unchecked.'),
285
365
'report_wizard':fields.boolean('Report Wizard'),
286
'copies': fields.integer('Number of copies'),
287
'fallback_false':fields.boolean('Disable format fallback'),
366
'copies': fields.integer('Number of Copies'),
367
'fallback_false':fields.boolean('Disable Format Fallback'),
288
368
'xml_id': fields.function(_get_xml_id, type='char', size=128, string="XML ID",
289
369
method=True, help="ID of the report defined in xml file"),
370
'extras': fields.function(_get_extras, method=True, type='char', size='256', string='Extra options'),
371
'deferred':fields.selection([
373
('adaptive',_('Adaptive')),
375
],'Deferred', help='Deferred (aka Batch) reporting, for reporting on large amount of data.'),
376
'deferred_limit': fields.integer('Deferred Records Limit', help='Records limit at which you are invited to start the deferred process.'),
377
'replace_report_id':fields.many2one('ir.actions.report.xml', 'Replace Report'),
378
'wizard_id':fields.many2one('ir.actions.act_window', 'Wizard Action'),
382
def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
383
res = super(report_xml, self).fields_view_get(cr, user, view_id, view_type, context, toolbar, submenu)
384
if view_type=='form':
385
##### Check deferred_processing module #####
386
cr.execute("SELECT id, state FROM ir_module_module WHERE name='deferred_processing'")
387
deferred_proc_module = cr.dictfetchone()
388
if not (deferred_proc_module and deferred_proc_module['state'] in ('installed', 'to upgrade')):
389
doc = etree.XML(res['arch'])
390
deferred_node = doc.xpath("//field[@name='deferred']")
391
deferred_node[0].attrib['invisible'] = '1'
392
deferred_limit_node = doc.xpath("//field[@name='deferred_limit']")
393
deferred_limit_node[0].attrib['invisible'] = '1'
394
res['arch'] = etree.tostring(doc)
395
############################################
293
398
def read(self, cr, user, ids, fields=None, context=None, load='_classic_read'):
294
399
##### check new model fields, that while not exist in database #####
295
400
cr.execute("SELECT name FROM ir_model_fields WHERE model = 'ir.actions.report.xml'")
312
417
####################################################################################
315
def unlink(self, cr, uid, ids, context=None):
420
def unlink(self, cr, uid, ids, context={}):
316
421
#TODO: process before delete resource
317
422
trans_obj = self.pool.get('ir.translation')
318
423
act_win_obj = self.pool.get('ir.actions.act_window')
319
424
trans_ids = trans_obj.search(cr, uid, [('type','=','report'),('res_id','in',ids)])
320
425
trans_obj.unlink(cr, uid, trans_ids)
426
self.unlink_inherit_report(cr, uid, ids, context=context)
321
427
####################################
322
reports = self.read(cr, uid, ids, ['report_name','model','report_wizard'])
428
reports = self.read(cr, uid, ids, ['report_name','model','report_wizard','replace_report_id'])
323
429
for r in reports:
324
430
if r['report_wizard']:
325
431
act_win_ids = act_win_obj.search(cr, uid, [('res_model','=','aeroo.print_actions')], context=context)
349
454
parser=self.load_from_source("from report import report_sxw\n"+vals['parser_def']) or parser
351
456
res_id = super(report_xml, self).create(cr, user, vals, context)
457
if vals.get('report_wizard'):
458
wizard_id = self._set_report_wizard(cr, user, vals['replace_report_id'] or res_id, \
459
res_id, linked_report_id=res_id, report_name=vals['name'], context=context)
460
self.write(cr, user, res_id, {'wizard_id': wizard_id}, context)
461
if vals.get('replace_report_id'):
462
report = self.browse(cr, user, res_id, context=context)
463
self.link_inherit_report(cr, user, report, new_replace_report_id=vals['replace_report_id'], context=context)
353
465
if vals.get('active', False):
354
466
self.register_report(cr, vals['report_name'], vals['model'], vals.get('report_rml', False), parser)
371
481
vals['report_sxw_content_data'] = False
372
482
if type(ids)==list:
374
record = self.read(cr, user, ids)
484
record = self.browse(cr, user, ids)
375
485
#if context and 'model' in vals and not self.pool.get('ir.model').search(cr, user, [('model','=',vals['model'])]):
376
486
# raise osv.except_osv(_('Object model is not correct !'),_('Please check "Object" field !') )
377
if vals.get('report_type', record['report_type']) == 'aeroo':
378
if vals.get('report_wizard'):
379
self._set_report_wizard(cr, user, ids, context)
380
elif 'report_wizard' in vals and not vals['report_wizard'] and record['report_wizard']:
487
if vals.get('report_type', record.report_type) == 'aeroo':
488
if vals.get('report_wizard') and vals.get('active', record.active) and \
489
(record.replace_report_id and vals.get('replace_report_id',True) or not record.replace_report_id):
490
vals['wizard_id'] = self._set_report_wizard(cr, user, ids, ids, linked_report_id=vals.get('replace_report_id'), context=context)
491
record.report_wizard = True
492
record.wizard_id = vals['wizard_id']
493
elif 'report_wizard' in vals and not vals['report_wizard'] and record.report_wizard:
381
494
self._unset_report_wizard(cr, user, ids, context)
495
vals['wizard_id'] = False
496
record.report_wizard = False
497
record.wizard_id = False
383
499
if vals.get('parser_state', False)=='loc':
384
parser = self.load_from_file(vals.get('parser_loc', False) or record['parser_loc'], cr.dbname, record['id']) or parser
500
parser = self.load_from_file(vals.get('parser_loc', False) or record.parser_loc, cr.dbname, record.id) or parser
385
501
elif vals.get('parser_state', False)=='def':
386
parser = self.load_from_source("from report import report_sxw\n"+(vals.get('parser_loc', False) or record['parser_def'] or '')) or parser
502
parser = self.load_from_source("from report import report_sxw\n"+(vals.get('parser_loc', False) or record.parser_def or '')) or parser
387
503
elif vals.get('parser_state', False)=='default':
388
504
parser = rml_parse
389
elif record['parser_state']=='loc':
390
parser = self.load_from_file(record['parser_loc'], cr.dbname, record['id']) or parser
391
elif record['parser_state']=='def':
392
parser = self.load_from_source("from report import report_sxw\n"+record['parser_def']) or parser
393
elif record['parser_state']=='default':
505
elif record.parser_state=='loc':
506
parser = self.load_from_file(record.parser_loc, cr.dbname, record.id) or parser
507
elif record.parser_state=='def':
508
parser = self.load_from_source("from report import report_sxw\n"+record.parser_def) or parser
509
elif record.parser_state=='default':
394
510
parser = rml_parse
396
512
if vals.get('parser_loc', False):
397
parser=self.load_from_file(vals['parser_loc'], cr.dbname, record['id']) or parser
513
parser=self.load_from_file(vals['parser_loc'], cr.dbname, record.id) or parser
398
514
elif vals.get('parser_def', False):
399
515
parser=self.load_from_source("from report import report_sxw\n"+vals['parser_def']) or parser
400
if vals.get('report_name', False) and vals['report_name']!=record['report_name']:
401
self.delete_report_service(record['report_name'])
516
if vals.get('report_name', False) and vals['report_name']!=record.report_name:
517
self.delete_report_service(record.report_name)
402
518
report_name = vals['report_name']
404
self.delete_report_service(record['report_name'])
405
report_name = record['report_name']
520
self.delete_report_service(record.report_name)
521
report_name = record.report_name
522
##### Link / unlink inherited report #####
525
if 'replace_report_id' in vals and vals.get('active', record.active):
526
if vals['replace_report_id']:
527
if record.replace_report_id and vals['replace_report_id']!=record.replace_report_id.id:
529
ctx['keep_wizard'] = True # keep window action for wizard, if only inherit report changed
530
link_vals.update(self.unlink_inherit_report(cr, user, ids, ctx))
532
link_vals.update(self.link_inherit_report(cr, user, record, new_replace_report_id=vals['replace_report_id'], context=context))
533
self.register_report(cr, report_name, vals.get('model', record.model), vals.get('report_rml', record.report_rml), parser)
535
link_vals.update(self.unlink_inherit_report(cr, user, ids, context=context))
537
##########################################
539
if vals.get('active', record.active):
540
self.register_report(cr, report_name, vals.get('model', record.model), vals.get('report_rml', record.report_rml), parser)
541
if not record.active and vals.get('replace_report_id',record.replace_report_id):
542
link_vals.update(self.link_inherit_report(cr, user, record, new_replace_report_id=vals.get('replace_report_id',False), context=context))
543
elif not vals.get('active', record.active):
544
self.unregister_report(cr, report_name)
546
link_vals.update(self.unlink_inherit_report(cr, user, ids, context=context))
549
raise osv.except_osv(_('Report registration error !'), _('Report was not registered in system !'))
551
vals.update(link_vals)
407
552
res = super(report_xml, self).write(cr, user, ids, vals, context)
409
if vals.get('active', record['active']):
410
self.register_report(cr, report_name, vals.get('model', record['model']), vals.get('report_rml', record['report_rml']), parser)
412
self.unregister_report(cr, report_name)
415
raise osv.except_osv(_('Report registration error !'), _('Report was not registered in system !'))
418
555
res = super(report_xml, self).write(cr, user, ids, vals, context)
427
564
res_id = super(report_xml, self).copy(cr, uid, id, default, context)
430
def _set_report_wizard(self, cr, uid, ids, context=None):
567
def _set_report_wizard(self, cr, uid, ids, report_action_id, linked_report_id=False, report_name=False, context=None):
431
568
id = isinstance(ids, list) and ids[0] or ids
569
report = self.browse(cr, uid, id, context=context)
432
570
ir_values_obj = self.pool.get('ir.values')
433
571
trans_obj = self.pool.get('ir.translation')
434
event_id = ir_values_obj.search(cr, uid, [('value','=',"ir.actions.report.xml,%s" % id)])
435
name = self.read(cr, uid, id, ['name'])['name']
573
linked_report = self.browse(cr, uid, linked_report_id, context=context)
575
linked_report = report.replace_report_id
576
event_id = ir_values_obj.search(cr, uid, [('value','=',"ir.actions.report.xml,%s" % report.id)])
578
event_id = ir_values_obj.search(cr, uid, [('value','=',"ir.actions.report.xml,%s" % linked_report.id)])
437
580
event_id = event_id[0]
438
action_data = {'name':name,
581
action_data = {'name':report_name or report.name,
439
582
'view_mode':'form',
440
583
'view_type':'form',
442
585
'res_model':'aeroo.print_actions',
443
'context':{'report_action_id':id}
586
'context':{'report_action_id':report_action_id}
445
588
act_id = self.pool.get('ir.actions.act_window').create(cr, uid, action_data, context)
446
589
ir_values_obj.write(cr, uid, event_id, {'value':"ir.actions.act_window,%s" % act_id}, context=context)
448
translations = trans_obj.search(cr, uid, [('res_id','=',id),('src','=',name),('name','=','ir.actions.report.xml,name')])
591
translations = trans_obj.search(cr, uid, [('res_id','=',report.id),('src','=',report.name),('name','=','ir.actions.report.xml,name')])
449
592
for trans in trans_obj.browse(cr, uid, translations, context):
450
593
trans_obj.copy(cr, uid, trans.id, default={'name':'ir.actions.act_window,name','res_id':act_id})