Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two return statements for one method? Python

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,
                            }
like image 830
Megha Sirisilla Avatar asked Jan 03 '23 18:01

Megha Sirisilla


2 Answers

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
like image 194
Dachi Darchiashvili Avatar answered Jan 06 '23 09:01

Dachi Darchiashvili


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"...

like image 29
Klipiklop Avatar answered Jan 06 '23 08:01

Klipiklop