我有一个打印报告的方法。有两份使用相同方法打印但条件不同的报告。我已经给出了 if-else 条件,但由于某些原因,else 部分没有被执行! 请帮我解决这个问题
count = 80
a = 20
if a > count:
return xyz
else:
return abc
abc 和 xyz 是我拥有的两种不同类型的报告。
编辑: 这是我的实际功能。在每一个中我都在获取我的记录。
for inv_no in each:
if inv_no.invoice_date > '2017-06-30':
return {
'type': 'ir.actions.report.xml',
'report_name': 'gst_invoice_print',
'datas': datas,
}
else:
return {
'type': 'ir.actions.report.xml',
'report_name': 'invoice_print',
'datas': datas,
}
最佳答案
我看到了你最后的表扬,所以这就是你比较日期的方式。
在将 Odoo 日期转换为 datetime 对象之前,Odoo 日期是不可比较的,因此要将 odoo date 转换为 datetime 对象,请使用:
a = datetime.strptime(self.date_field1, "%Y-%m-%d")
b = datetime.strptime(self.date_field1, "%Y-%m-%d")
# where date_field1 and date_field2 are something like this 2017-01-01
# now you can compare a and b
if a < b:
drink beer
else:
drink more beer
关于python - 一种方法有两个返回语句? Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44928209/