Presumably you are calling this function as follows: callback_0(session.order, session.sale_order_net)
The problem is you later have: session_order_net = dict(...) At that point, you are not modifying the session.sale_order_net object but simply assigning a new object to the local variable session_order_net. This is equivalent to doing: session_order_net = current.session.sale_order_net session_order_net = dict(...) In the above case, you wouldn't expect the second line to have any effect on session.sale_order_net -- the second line simply makes the first line irrelevant (i.e., it simply overwrites the value of the session_order_net variable that is local to the function). The earlier line: session_order[id] = ... works because in that case, you are not assigning a new object to the session_order variable but merely mutating the object to which session_order refers (i.e., session.order). If you want to completely replace the value of session.sale_order_net, then pass in the session object and do: session.sale_order_net = ... Anthony On Wednesday, January 13, 2016 at 12:48:11 AM UTC-5, 黄祥 wrote: > > is it possible to update 2 sessions values using web2py module? i've > tested it only first session value work, the second session value work if > explicit define in the module (but the module is used by another > controller, so i want to create just 1 module for all controllers). > e.g. > *modules/transaction.py* > def callback_0(session_order, session_order_net): > if current.request.vars.action == 'adjust_total': > id = int(current.request.vars.id) > quantity = int(current.request.vars['quantity_%s' % id]) > price = int(current.request.vars['price_%s' % id]) > *session_order[id] = quantity, price # the first parameter work* > total_price = quantity * price > total_quantity = 0 > grand_total = 0 > for calculation_id, (calculation_quantity, calculation_price) in > session_order.items(): > calculation_total_price = calculation_quantity * calculation_price > total_quantity += calculation_quantity > grand_total += calculation_total_price > return "jQuery('#total_price_%s').html('%s'); > jQuery('#total_quantity').html('%s'); jQuery('#grand_total').html('%s');" % > (id, > format(total_price, ",d").replace(",", "."), format(total_quantity, > ",d").replace(",", "."), > format(grand_total, ",d").replace(",", ".") ) > if current.request.vars.action == 'adjust_total_net': > discount = int(current.request.vars['discount'] ) > delivery_fee = int(current.request.vars['delivery_fee'] ) > packing_fee = int(current.request.vars['packing_fee'] ) > stamp_fee = int(current.request.vars['stamp_fee'] ) > paid = int(current.request.vars['paid'] ) > > * current.session.sale_order_net = dict(discount = discount, delivery_fee > = delivery_fee, packing_fee = packing_fee, stamp_fee = stamp_fee, paid = > paid) # this work when explicit tell the session name* > > * #session_order_net = dict(discount = discount, delivery_fee = > delivery_fee, packing_fee = packing_fee, stamp_fee = stamp_fee, paid = > paid)** # the second parameter not work, no error traceback occured but > the result is not expected (not updated value)* > > grand_total = sum(calculation_quantity * calculation_price for > calculation_id, (calculation_quantity, calculation_price) in > session_order.items() ) > grand_total_net = grand_total-discount+delivery_fee+packing_fee+stamp_fee > paid_return = paid-grand_total_net > > return "jQuery('#grand_total_net').html('%s'); > jQuery('#paid_return').html('%s');" % ( > format(grand_total_net, ",d").replace(",", "."), format(paid_return, > ",d").replace(",", ".") ) > > as in the example code above the bold code is work if i explicit it and if > i use the second parameter (*session_order_net*) that been passed by > function in controller, it is not work, the funny things is the first > parameter work (*session_order*). no error traceback occured but the > result is not expected. > > any idea how to get it work in web2py way? > > thanks and best regards, > stifan > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.