Search code examples
pythontext

is this python error due to Syntax or program-specific error


Newbie to python here, learning it as I go along because our new ERP uses it.

I'm making a custom warning to which I have put together the following output;

'Check the Opportunity stage is at "Prospect-Quoted!"' + ('\n\n If this quote value is different from previous quotes, remember to also update the Opportunity value.' if any([i.id for i in obj.sale_order_ids]))

For context, this is when raising a quote against a CRM opportunity, I want to remind the user to update the saved opportunity value if there are other quotes linked to the opportunity (obj) from which this is being called.

I'm confident based on the system's Dynamic Values Builder that the section any([i.id for i in obj.sale_order_ids]) is correct, and the if statement is structured the same as others elsewhere in the system, but when attempting to save the custom warning I get an error message saying

Cannot evaluate Warning. Error: unexpected EOF while parsing (, line 1)

Can someone more experienced tell me, is this a problem with my syntax or more likely to be a program-specific problem?


Solution

  • When doing this kind of syntax, with inlined if, you must always specify an else statement :

    str1 = 'Check the Opportunity stage is at "Prospect-Quoted!"'
    str2 = '\n\n If this quote value is different from previous quotes, remember to also update the Opportunity value.'
    result = str1 + (str2 if any([i.id for i in obj.sale_order_ids]) else "")