it's work well now, thank you so much. massimo, already tested with many cases 1. have promotion price, the others don't have 2. both have promotion price 3. both don't have promotion price, use unit price
the results are as expected. grand_total=sum((item.promotion_price or item.unit_price)*session.order[item.id] for item in *db(db.product.id.belongs(*session.order.keys())).select(db.product.id,db.product.promotion_price,db.product.unit_price)) thanks and best regards On Monday, April 29, 2013 10:47:36 AM UTC-4, Massimo Di Pierro wrote: > > rand_total=sum((item.promotion_price or > item.unit_price)*session.order[item.id] for item in > *db(db.product.id.belongs(*session.order.keys())).select(db.product.id,db.product.promotion_price,db.product.unit_price)) > > > On Sunday, 28 April 2013 23:37:37 UTC-5, 黄祥 wrote: >> >> pardon me, for not tell obviously about the code that i want to achieve >> my objective : >> i want to have a grand total of items (sum) that have been in shopping >> cart's session, check is the item have a promotion price or not, if have >> a promotion price (promotion_price > 0) use promotion price of item * >> quantity, if don't have promotion price (promotion_price = 0) use unit >> price of item * quantity >> >> in pseudo code : >> grand_total = sum(for id, qty in session.order.items(): >> if db.product(id).promotion_price: >> db.product(id).promotion_price*qty >> else: >> db.product(id).unit_price*qty >> ) >> any idea or suggestion how to achieve pseudo code above in python or >> web2py way? >> thank you so 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.

