hi, 

i face the same problem, when trying to update the other table that have 
computed field with after_update callback.
e.g.
# after_update_purchase_header
def __after_update_purchase_header(s, f):
purchase = s.select().first()
# purchase_header
db(db.purchase_detail.purchase_no == purchase.id).update(grand_total = 
purchase.grand_total)

# on_define_purchase_header
def on_define_purchase_header(table): 
# callbacks
if not 'install' in request.controller :
# _after_update
table._after_update.append(__after_update_purchase_header)

# create table : purchase_header
db.define_table('purchase_header', 
Field('purchase_no'), 
Field('purchase_date', 'date'), 
Field('supplier', 'reference buyer_seller'), 
Field('payment_method', 'reference payment_method'), 
Field('notes', 'text'), 
Field('grand_total', 'integer'), 
on_define = on_define_purchase_header, 
format = '%(purchase_no)s')

# after_update_purchase_detail
def __after_update_purchase_detail(s, f):
purchase = s.select().first()
# product
db(db.product.id == purchase.product).update(capital = purchase.price)
# purchase_header
db(db.purchase_header.id == purchase.purchase_no).update(grand_total = 
purchase.grand_total)

# on_define_purchase_detail
def on_define_purchase_detail(table): 
# callbacks
if not 'install' in request.controller :
# _after_update
table._after_update.append(__after_update_purchase_detail)
# compute
table.total_price.compute = lambda r: r['quantity'] * r['price']

# create table : purchase_detail
db.define_table('purchase_detail', 
Field('purchase_no', 'reference purchase_header'), 
Field('product', 'reference product'), 
Field('quantity', 'integer'), 
Field('price', 'integer'), 
Field('total_price', 'integer'), 
Field('grand_total', 'integer'), 
on_define = on_define_purchase_detail, 
format = '%(purchase_no)s')

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.

Reply via email to