I have a method which should print reports. There are two reports that are printed using the same method but has different conditions. I have given the if-else condition but some reason the else part is not being executed! Kindly help me with the issue
count = 80
a = 20
if a > count:
return xyz
else:
return abc
abc and xyz are two different types of reports that I have.
Edit: This is my actual function. In each I'm fetching my records.
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,
}
I saw your last commend so this is how you should compare dates.
Odoo dates are not comparable until you convert them to datetime objects, so to convert odoo date to datetime object use:
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
I don't understand your problem, because your code works perfectly. This code below works for me:
count = 80
a = 20
def test(a, count):
if a > count:
return "xyz"
else:
return "abc"
print test(a,count)
it returns "abc"...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With