[FIX] Adapted the render_report and try_report_action methods used in yml test to...
authorSimon Lejeune <sle@openerp.com>
Tue, 1 Apr 2014 15:33:39 +0000 (17:33 +0200)
committerSimon Lejeune <sle@openerp.com>
Tue, 1 Apr 2014 15:33:39 +0000 (17:33 +0200)
bzr revid: sle@openerp.com-20140401153339-3n0xw5whx82uu0pu

openerp/addons/base/ir/ir_actions.py
openerp/tools/test_reports.py

index 4cd0492..61c7a1d 100644 (file)
@@ -104,7 +104,9 @@ class ir_actions_report_xml(osv.osv):
             cr.execute("SELECT * FROM ir_act_report_xml WHERE report_name=%s", (name,))
             r = cr.dictfetchone()
             if r:
-                if r['report_rml'] or r['report_rml_content_data']:
+                if r['report_type'] in ['qweb-pdf', 'qweb-html']:
+                    return r['report_name']
+                elif r['report_rml'] or r['report_rml_content_data']:
                     if r['parser']:
                         kwargs = { 'parser': operator.attrgetter(r['parser'])(openerp.addons) }
                     else:
@@ -127,7 +129,11 @@ class ir_actions_report_xml(osv.osv):
         Look up a report definition and render the report for the provided IDs.
         """
         new_report = self._lookup_report(cr, name)
-        return new_report.create(cr, uid, res_ids, data, context)
+        # in order to use current yml test files with qweb reports
+        if isinstance(new_report, (str, unicode)):
+            return self.pool['report'].get_pdf(cr, uid, res_ids, new_report, data=data, context=context), 'pdf'
+        else:
+            return new_report.create(cr, uid, res_ids, data, context)
 
     _name = 'ir.actions.report.xml'
     _inherit = 'ir.actions.actions'
index 874a8cc..9aa5523 100644 (file)
@@ -114,7 +114,6 @@ def try_report_action(cr, uid, action_id, active_model=None, active_ids=None,
                 Eg. 'OK' or 'gtk-print'
         :param our_module: the name of the calling module (string), like 'account'
     """
-
     if not our_module and isinstance(action_id, basestring):
         if '.' in action_id:
             our_module = action_id.split('.', 1)[0]
@@ -161,7 +160,10 @@ def try_report_action(cr, uid, action_id, active_model=None, active_ids=None,
         # Updating the context : Adding the context of action in order to use it on Views called from buttons
         if datas.get('id',False):
             context.update( {'active_id': datas.get('id',False), 'active_ids': datas.get('ids',[]), 'active_model': datas.get('model',False)})
-        context.update(safe_eval(action.get('context','{}'), context.copy()))
+        context1 = action.get('context', {})
+        if isinstance(context1, basestring):
+            context1 = safe_eval(context1, context.copy())
+        context.update(context1)
         if action['type'] in ['ir.actions.act_window', 'ir.actions.submenu']:
             for key in ('res_id', 'res_model', 'view_type', 'view_mode',
                     'limit', 'auto_refresh', 'search_view', 'auto_search', 'search_view_id'):
@@ -272,12 +274,17 @@ def try_report_action(cr, uid, action_id, active_model=None, active_ids=None,
             if 'window' in datas:
                 del datas['window']
             if not datas:
-                datas = action.get('datas',{})
+                datas = action.get('datas')
+                if not datas:
+                    datas = action.get('data')
             datas = datas.copy()
             ids = datas.get('ids')
             if 'ids' in datas:
                 del datas['ids']
-            res = try_report(cr, uid, 'report.'+action['report_name'], ids, datas, context, our_module=our_module)
+            if action.get('report_type') in ['qweb-pdf', 'qweb-html']:
+                res = registry['report'].get_html(cr, uid, [], action.get('report_name'), data=datas, context=context)
+            else:
+                res = try_report(cr, uid, 'report.'+action['report_name'], ids, datas, context, our_module=our_module)
             return res
         else:
             raise Exception("Cannot handle action of type %s" % act_model)
@@ -303,6 +310,4 @@ def try_report_action(cr, uid, action_id, active_model=None, active_ids=None,
 
     return True
 
-#eof
-
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: