def __after_insert_redemption_detail(f, id): query_unit = db.unit.account == f['account'] row_unit = db(query_unit).select(orderby = ~current.db.unit.id).first()
insert_unit_unit = row_unit.unit - f['unit'] if row_unit else f['unit'] insert_unit_previous_unit = row_unit.unit if row_unit else 0 insert_unit_trade_unit = insert_unit_unit - insert_unit_previous_unit insert_unit_trade_amount = insert_unit_trade_unit * f['nav_per_unit'] insert_unit_amount = insert_unit_unit * f['nav_per_unit'] insert_unit_due_date = datetime.datetime.strptime(f['nav_date'], '%Y-%m-%d').date() + datetime.timedelta(days = 0) db.unit.insert(account = f['account'], unit = insert_unit_unit, previous_unit = insert_unit_previous_unit, trade_unit = insert_unit_trade_unit, nav_date = f['nav_date'], nav_per_unit = f['nav_per_unit'], trade_amount = insert_unit_trade_amount, amount = insert_unit_amount,due_date = insert_unit_due_date) redemption_unit = f['unit'] rows_remaining_unit = db(query_unit & db.unit.remaining_unit > 0).select(orderby = current.db.unit.id) first_row_remaining_unit = rows_remaining_unit.first() if redemption_unit <= first_row_remaining_unit.remaining_unit: db(db.unit.id == first_row_remaining_unit.id).update(remaining_unit = db.unit(first_row_remaining_unit.id).remaining_unit - redemption_unit) else: for row_remaining_unit in rows_remaining_unit: if redemption_unit > row_remaining_unit.remaining_unit and redemption_unit != 0: db(db.unit.id == row_remaining_unit.id).update(remaining_unit = db.unit(first_row_remaining_unit.id).remaining_unit - row_remaining_unit.remaining_unit) redemption_unit = redemption_unit - row_remaining_unit.remaining_unit elif redemption_unit <= row_remaining_unit.remaining_unit and redemption_unit != 0: db(db.unit.id == row_remaining_unit.id).update(remaining_unit = db.unit(row_remaining_unit.id).remaining_unit - redemption_unit) redemption_unit = 0 my bad, just have wrong logic in orderby and double check conditional if 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.