我希望按date_from
和date_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
答案 0 :(得分:1)
我假设你的向导是'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,
}
我希望这个答案对你有帮助。