The syntax error is

grand_total=sum(db.product(id).promotion_price*qty else: 
db.product(id).unit_price*qty for id, qty in session.order.items() if 
db.product(id).promotion_price
)


should be

grand_total=sum(db.product(id).promotion_price*qty for id, qty in 
session.order.items() if db.product(id).promotion_price)

but what is the problem with the suggested solution. Not sure I understand.



On Sunday, 28 April 2013 22:38:48 UTC-5, 黄祥 wrote:
>
> a, i'm sorry, i'm just tested 'one single query' only when promotion_price 
> > 0, when i set promotion price = 0, both query is return 0.
> when i use one query per item it returns an error :
> Traceback
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
>
> Traceback (most recent call last):
>   File "/home/stifank/Desktop/web2py/gluon/restricted.py", line 211, in 
> restricted
>     ccode = compile2(code, layer)
>   File "/home/stifank/Desktop/web2py/gluon/restricted.py", line 194, in 
> compile2
>     return compile(code.rstrip().replace('\r\n', '\n') + '\n', layer, 'exec')
>   File 
> "/home/stifank/Desktop/web2py/applications/onlineshopping/controllers/default.py"
>  
> <http://127.0.0.1:8000/admin/default/edit/onlineshopping/controllers/default.py>,
>  line 181
>     grand_total=sum(db.product(id).promotion_price*qty else: 
> db.product(id).unit_price*qty for id, qty in session.order.items() if 
> db.product(id).promotion_price)
>                                                           ^
> SyntaxError: invalid syntax
>
> i prefer check conditionally per item (is it have a promotion price or 
> not, if have a promotion price use promotion price, else use unit price) 
> and then sum the total price of products, because, not every products have 
> a promotion price, any idea how to do face this problem?
> thank you very much
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to