我正在创建一个银行模块,客户可以从银行购买贷款。我想打印一份报告声明。在打印特定客户的记录之前,我想过滤日期。我想通过给出从日期到迄今来过滤它。因此,客户在该特定日期从银行购买的贷款金额应该打印出来。
谢谢,
希望我能获得一些知识。
答案 0 :(得分:2)
下面的向导代码
class BankCustomer(models.TransientModel):
_name = 'bank.customer'
_description = 'Bank Customer Report'
date_from = fields.Date(string='From date', required=True,default=lambda *a: time.strftime('%Y-%m-01'))
date_to = fields.Date(string='To date', required=True,default=lambda *a: str(datetime.now() + relativedelta.relativedelta(months=+1, day=1, days=-1))[:10])
@api.multi
def pdf_bank_customer_report(self):
data = self.read()[0]
datas = {
'ids': [],
'model': 'bank.customer',
'form': data
}
return self.env['report'].with_context(landscape=True).get_action(self, 'module_name.template_name', data=datas)
class BankCustomerReport(models.AbstractModel):
_name = 'report.module_name.template_name
def get(self):
self.env.cr.execute(""" you query """+ datas['date_from'],datas['date_to'] ))
line_list = [i for i in self.env.cr.dictfetchall()]
finallist = []
import datetime
for fin in line_list:
#sale_date = datetime.datetime.strptime(fin['date'], '%Y-%m-%d').strftime('%d-%m-%y')
finallist.append({
'date': fin['date'],
'here gat you requirened field from query'
})
finally pass thislist to report template
return finallist
@api.model
def render_html(self, docids, data=None):
Report = self.env['report']
sale_report = Report._get_report_from_name('module_name.report_template_name')
context = dict(self._context or {})
active_ids = context.get('active_ids', [])
register = self.env['bank.customer'].browse(active_ids)
docargs = {
'doc_ids': self.ids,
'doc_model': sale_report.model,
'docs': register,
'details':self.get_det,
}
return Report.render('module_name.report_template_name', docargs)