Home > Back-end >  Correct multiply condition in if statement
Correct multiply condition in if statement

Time:11-16

for sale_order in sale_orders:
    new_line = sale_order.filter(lambda x:x.status = 'new')
    for sale_order_line in sale_order.sale_order_lines:

        if sale_order_line.status != 'closed' and not new_line and sale_order_line.type != 'service':
            print('need to print')

how can I make my conditions right?

  1. I want to print if my sale_order_line status is not 'closed' and the line type is not 'service'
  2. I want to print if sale_order_line status is closed but if there is new_line and the line type is not 'service'

Basically never print if order_line.type is service and print always if the status is not closed, but also should print if the status is closed and there is new_line.

CodePudding user response:

for sale_order in sale_orders:
new_line = sale_order.filter(lambda x:x.status = 'new')
for sale_order_line in sale_order.sale_order_lines:
    if sale_order_line.type != "service":
        if sale_order_line.status != 'closed' or sale_order_line.status == "closed" and new_line:
            print('need to print')

the above code is based on the following requirements, you set

Basically never print if order_line.type is service and print always if the status is not closed, but also should print if the status is closed and there is new_line.

  • Related