2016-09-09 102 views
0

下面印刷qweb報告獲取問題是我使用從嚮導打印報告的函數的代碼..在odoo V8

class manager_monthly_salary_report_wizard(osv.osv_memory): 
    _name = "manager.monthly.salary.report.wizard" 

    _columns = { 
     'month': fields.integer("Month"), 
     'year': fields.integer("Year"), 
    } 

    def check_report(self, cr, uid, ids, context=None): 
     print "context -> ", context 
     print "ids -> ", ids 

     if context is None: 
      context = {} 

     self_read = self.read(cr, uid, ids)[0] 

     if (self_read['month'] >= 12 or self_read['month'] <= 0) and len(str(self_read['year'])) != 4: 
      raise osv.except_osv(_("Warning"), 
           _("You have invalid month/year ! please select correct one ... ")) 
     else: 
      print "working normally ... " 

     if self_read['month'] in [1, 2, 3, 4, 5, 6, 7, 8, 9]: 
      month_year = str("0" + str(self_read['month']) or self_read['month']) 
     elif self_read['month'] in [10, 11, 12]: 
      month_year = str(self_read['month']) 

     month_year = month_year + " - " + str(self_read['year']) 
     print "month_year ", month_year 

     departments = [] 
     office_staff = [] 

     for deprt in first_level_department_brws: 
      office_staff_ids = empl_obj.search(cr, uid, [('department_id', '=', deprt.id), '|', ('manager', '=', True), ('office_staff', '=', True)]) 
      office_staff_brw = empl_obj.browse(cr, uid, office_staff_ids) 
      print " office_staff_brw ", office_staff_brw 

      department = { 
       'name': deprt.name, 
       'office_staff': office_staff 
      } 
      for dep_employee in office_staff_brw: 

       office_staff.append({ 
        'name': dep_employee.name,... 
       }) 
       department['office_staff'] = office_staff 
       print "office_staff -> ", office_staff 

      office_staff = [] 
      departments.append(department) 
      print "Departments-> ", office_staff 
      department = {} 
      print "\n" 

     data = { 
      'ids': context.get('active_ids', []), 
      'model': context.get('active_model', 'ir.ui.menu'), 
      'form': departments 
     } 
     print "data -> ", data 
     print "__end__\n\n" 

     return self.pool['report'].get_action(cr, uid, [], 'custom_module.my_report', data=data, context=context) 

報告XML文件的樣子..

<?xml version="1.0" encoding="utf-8"?> 
<openerp> 
    <data> 
     <template id="my_report"> 
      <t t-call="report.html_container"> 
       <div class="page"> 
        <!--header --> 
        <!--<t t-call="report.internal_layout">--> 
        <!--content--> 

        <div class="row"> 
         <span >"====="</span> 
         <span t-esc="Departments"/> 
         <t t-esc="data"/> 

         <t t-set="model" t-value="data['model']"/> 
         <t t-set="data" t-value="data['form']"/> 
         <t t-esc="data"/> 
         <span >"++++++"</span> 
        </div> 
       </div> 
      </t> 
     </template> 
    </data> 
</openerp> 

如果departmens數據[「形式」]是一種字典,我是能夠打印,但現在我已切換到列表和我是個讓下面的錯誤,而打印報告

Traceback (most recent call last): 
    File "/home/demo/project/odoo/odoo_8/addons/report/controllers/main.py", line 120, in report_download 
    response = self.report_routes(reportname, converter='pdf', **dict(data)) 
    File "/home/demo/project/odoo/odoo_8/openerp/http.py", line 410, in response_wrap 
    response = f(*args, **kw) 
    File "/home/demo/project/odoo/odoo_8/addons/report/controllers/main.py", line 65, in report_routes 
    pdf = report_obj.get_pdf(cr, uid, docids, reportname, data=options_data, context=context) 
    File "/home/demo/project/odoo/odoo_8/openerp/api.py", line 268, in wrapper 
    return old_api(self, *args, **kwargs) 
    File "/home/demo/project/odoo/odoo_8/addons/report/models/report.py", line 192, in get_pdf 
    html = self.get_html(cr, uid, ids, report_name, data=data, context=context) 
    File "/home/demo/project/odoo/odoo_8/openerp/api.py", line 268, in wrapper 
    return old_api(self, *args, **kwargs) 
    File "/home/demo/project/odoo/odoo_8/addons/report/models/report.py", line 167, in get_html 
    return particularreport_obj.render_html(cr, uid, ids, data=data, context=context) 
    File "/home/demo/project/odoo/odoo_8/openerp/api.py", line 268, in wrapper 
    return old_api(self, *args, **kwargs) 
    File "/home/demo/project/odoo/odoo_8/addons/report/models/abstract_report.py", line 35, in render_html 
    if data and data.get('form', {}).get('landscape'): 
AttributeError: 'list' object has no attribute 'get' 
在PY代碼

更新

我剛纔改爲

data = { 
     'ids': context.get('active_ids', []), 
     'model': context.get('active_model', 'ir.ui.menu'), 
     'form': {'departments': departments} 
    } 

,並且正在打印報表....現在的問題是,爲什麼他們不能直接打印報告,如果我使用

data = { 
     'ids': context.get('active_ids', []), 
     'model': context.get('active_model', 'ir.ui.menu'), 
     'form': departments 
    } 

list代替字典在data['form'] ...?

回答

0

我不確定但是我認爲你在使用數據['form']時有衝突。它在您的錯誤中引用的abstract_report.py文件中提及。如果你按照Odoo Reports的文檔,他們描述了像這樣覆蓋render_html函數。而不是在你的qweb中使用數據['form']嘗試直接使用部門,因爲變量應該是可用的。

class MyReport(models.AbstractModel): 
    _name = 'report.custom_module.my_report' 

    @api.multi 
    def render_html(self, data=None): 
     departments = [] 
     office_staff = [] 

     for deprt in first_level_department_brws: 
      office_staff_ids = empl_obj.search(cr, uid, [('department_id', '=', deprt.id), '|', ('manager', '=', True), ('office_staff', '=', True)]) 
      office_staff_brw = empl_obj.browse(cr, uid, office_staff_ids) 
      print " office_staff_brw ", office_staff_brw 

      department = { 
       'name': deprt.name, 
       'office_staff': office_staff 
      } 

      for dep_employee in office_staff_brw: 
       office_staff.append({ 
        'name': dep_employee.name, ... 
       }) 

      department['office_staff'] = office_staff 
      print "office_staff -> ", office_staff 

      office_staff = [] 
      departments.append(department) 
      print "Departments-> ", office_staff 
      department = {} 

     report = self.env['report']._get_report_from_name('custom_addon.my_report') 
     docs = self.env['custom_addon.model_name'].browse(context.get('active_ids', [])) 

     docargs = { 
      'doc_model': report.model, 
      'docs': docs, 
      'departments': departments 
     } 
     return report_obj.render('custom_addon.my_report', docargs) 

嘗試定義另一個qweb varable var或其他數據。有幾個參考資料,我想知道是否有衝突。你的原始方法看起來並不完全錯誤,但是使用odoo已經使用的變量名稱(如數據和表單)可能會產生衝突。如果你看看/addons/report/abstract_report.py,你會注意到它們使用了一個data ['form'],但它看起來不像你通過表單傳遞的東西。他們試圖確定表單是否爲橫向格式,並且您的數據['form']似乎與您正在創建報告的記錄有關。不是報告佈局。

<?xml version="1.0" encoding="utf-8"?> 
<openerp> 
    <data> 
     <template id="my_report"> 
      <t t-call="report.html_container"> 
       <div class="page"> 
        <!--header --> 
        <!--<t t-call="report.internal_layout">--> 
        <!--content--> 

        <div class="row"> 
         <span >"====="</span> 
         <span>Departments</span> 
         <t t-raw="departments"/> 

         <span >"++++++"</span> 
        </div> 
       </div> 
      </t> 
     </template> 
    </data> 
</openerp> 
+0

謝謝,但是,這是我的格式是 '數據= { '形式':[{ 'A':1, 'B':[{..}]},{ 'A':1 ,'b':[{..}]},..]' 和我剛剛嘗試打印的數據['form']'這是一個列表,不訪問任何元素... '...用你的例子我只是試圖打印'form',然後才能做''...... – Bhuro

+0

使用t-raw,看看我的編輯 –

+0

同樣的錯誤......'<! - < t t-esc =「data」/> - ><! - - ><! - - - ><! - - >'... – Bhuro