I think the problem is in the line
if datetime.now() == payment_date:
This will literally see if there is payment_date right now. I think you want to see whether payment_date is greater than or equal payment_date , in which case you should use
if datetime.now() >= payment_date:
You can also simply filter invoices when querying the database:
invoices_list = Invoice.objects.filter(payment_date__lte=datetime.now())
Update
Your code is incorrect because you have mutually exclusive conditions. Take a look:
if payment_date <= datetime.now(): owing = invoice_gross if payment_date > datetime.now(): owing = 0
First it checks to see if there is a payment_date before that. He then sets owing to invoice_gross . Then, in the same condition, it checks to see if payment_date thereafter. But this cannot be! You are only in this block of code if payment_date is still there!
I think you have an indented error, and instead want:
if payment_date <= datetime.now(): owing = invoice_gross if payment_date > datetime.now(): owing = 0
Which, of course, matches:
if payment_date <= datetime.now(): owing = invoice_gross else: owing = 0
mipadi
source share