2016-12-29 108 views
0

我有兩個報告cout_materiel_facture_detail_report.xml(詳細報告)和cout_materiel_facture_report.xml(簡單報告),並有一個嚮導,用戶輸入一些數據並選擇他/她是否打印簡單報告或詳細的。這裏是精靈的等級:odoo:使用嚮導打印qweb報告

class CoutMaterielFactureWizard(models.TransientModel): 
_name = 'gc.cout_materiel_facture_wizard' 

directeur_parc_id = fields.Many2one('hr.employee', string='Directeur Parc') 

procedure = fields.Char(string='Procedure') 
version = fields.Char(string='Verion') 
date_realisation = fields.Date(string='Date realisation') 

# is_landscape = fields.Boolean(string='Mode paysage?') 
is_detail = fields.Boolean(string='Version simplifiee?') 

@api.multi 
def do_toggle_print(self): 
    cout_materiel = self.env['gc.cout_materiel'].browse(self._context.get('active_id', False)) 
    cout_materiel.write({ 
     'directeur_parc_id': self.directeur_parc_id.id 
    }) 
    # Print the simple report 
    if not self.is_detail: 

     return { 
      'type': 'ir.actions.report.xml', 
      'name': 'gestion_cout.cout_materiel_facture_report_template', 
      'report_name': 'gestion_cout.cout_materiel_facture_report_template', 
     } 
    # Print the detailed report 
    else: 
     sql = "SELECT SUM(h_sup)+SUM(h_exp),SUM(h_im),count(*),SUM(total), famille FROM gc_cout_materiel_line where " \ 
       "cout_materiel_id =%s group by famille " 
     self.env.cr.execute(sql, (cout_materiel.id,)) 
     results = self.env.cr.fetchall() 
     if len(results) > 0: 
      line_ids = [] 
      for nbht, nbhim, qte, prix_total, famille in results: 
       line_ids.append((0, 0, { 
        'famille': famille, 
        'type': 'VA', 
        'qte': qte, 
        'nbr_heures': nbht, 
        'nbr_heures_im': nbhim, 
        'nbr_jours': 28, 
        'prix_unitaire': 'VA', 
        'prix_total': prix_total, 
         })) 
      self.env['gc.cout_materiel_facture_temp'].create({ 
       'chantier_name': cout_materiel.chantier_id.name, 
       'mois_name': cout_materiel.mois_id.name, 
       'num_annexe': cout_materiel.num_annexe, 
       'expediteur': cout_materiel.expediteur, 
       'destinateur': cout_materiel.destinateur, 
       'application_date': cout_materiel.application_date, 
       'date_realisation': self.date_realisation, 
       'directeur_parc_name': self.directeur_parc_id.name, 
       'procedure': self.procedure, 
       'version': self.version, 
       'prix_total_global': cout_materiel.total_global, 
       'line_ids': line_ids, 
      }) 
     return { 
      'type': 'ir.actions.report.xml', 
      'name': 'gestion_cout.gc_cout_materiel_facture_detail_report_template', 
      'report_name': 'gestion_cout.gc_cout_materiel_facture_detail_report_template', 
     } 

But i get this error after i hit the print button

我檢查了數據庫,發現兩份報告都存在那裏。

任何幫助?請!!

回答

0

最後我設法解決了我的問題! 這裏是我做的:

  • 我創建了返回我whant打印和鏈接嚮導將qweb報告對象的列表精靈模型的方法。
  • 然後,我在t-foreach循環中使用object.my_mehtod()從qweb報告中調用方法,其中對象代表嚮導。

用這種方式,我能夠創建複雜的報表,輕鬆地打印出來。可以使用此方法從多個表中獲取數據並組織數據並將它們作爲列表返回。

我希望它能幫助別人。

最好的問候!