单击向导中的按钮时如何生成树视图和透视视图

How to generate a tree view and a pivot view when clicking a button in wizard

我想通过 date_fromdate_to

过滤树视图和数据透视表

请帮忙
Python代码:

from odoo import models, fields, api
from datetime import datetime,timedelta

class despatch(models.TransientModel):
 _name = "od.despatch"

  date_from = fields.Date('Date From',required=True)
  date_to = fields.Date('Date To',required=True,default=fields.Date.context_today)

  def od_gen(self):
    invoice = self.env['account.invoice']
    invoice_ids = invoice.search([('od_despatch_date','>=',self.date_from),('od_despatch_date','<=',self.date_to)])     
    print invoice_ids
    data = self.od_mk_qry(self.date_from,self.date_to)
    return {
        'name':'Despatch',
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'od.despatch',
        'res_id': self.id,
        'target': 'new',
        'type': 'ir.actions.act_window',
    }

  def od_mk_qry(self,date_from,date_to):
    qry = """ SELECT od_despatch_date,partner_id,date_invoice from account_invoice where od_despatch_date >= '%s' AND od_despatch_date <= '%s' """ % (date_from,date_to)
    print qry
    return qry

我假设你的向导是'od.despatch'并且你需要显示'account.invoice'模型的数据,然后,在return{}中你需要添加domain来过滤您要查找的数据,并将 'res_model' 更改为 'account.invoice' 因为这是您要显示的数据。

@api.multi
def od_gen(self):
    view_mode = 'tree,pivot'
    #You need to define(xml) the views of tree and pivot before
    tree_view_id = self.env.ref('your_module.your_tree_view').id
    tree_pivot_id = self.env.ref('your_module.your_pivot_view').id
    domain = [('od_despatch_date','>=',self.date_from),('od_despatch_date','<=',self.date_to)]

    return {
        'name':'Despatch',
        'type': 'ir.actions.act_window',
        'res_model': 'account.invoice',
        'view_mode': view_mode,
        'views' : [(view_tree_id, 'tree'),
                  (view_pivot_id, 'pivot')],
        'res_id': False,
        'target': 'self',
        'domain': domain,
    }

希望这个回答对您有所帮助。