Hi,

I have only just started learning python and web2py so please bear with me.

When a user inserts an item and amount in tr_items, I am trying to have the 
system check whether the item exists in products_summary, if it does, 
update the amount by the amount input by the user into tr_items - if it 
doesn't exist, the product should be added to products_summary and the 
amount set to the amount input by the user.

Below I have put in three variations that most make sense, but I have tried 
a whole load of different possibilities.  Any ideas on how I could go about 
solving this problem would be great!

Model:

db.define_table('products_summary',
                Field('product'),
                Field('cumulative_amount', default='0', type='double'))


db.define_table('tr_items',
                Field('item'),
                Field('amount', type='double'))



Controller:

def index():
    form = SQLFORM(db.tr_items)
    if form.process().accepted:
        item_in_out = form.vars.item
        amount_in_out = form.vars.amount
        #1
        
#db.products_summary.update_or_insert(db.products_summary.product==item_in_out, 
product=item_in_out, 
cumulative_amount=db.products_summary.cumulative_amount+form.vars.amount)
        #2
        
#db.products_summary.update_or_insert(db.products_summary.product==item_in_out, 
product=item_in_out, 
cumulative_amount=db(db.products_summary.product).select(db.products_summary.cumulative_amount)+form.vars.amount)
        #3
        db.products_summary.update_or_insert(db.products_summary.product==
item_in_out, product=item_in_out, cumulative_amount=+form.vars.amount)
        response.flash = T("Product: %s Amount: %d") % (item_in_out, 
amount_in_out)
    return locals()



Error message #1

<class 'sqlite3.OperationalError'> no such column: 
products_summary.cumulative_amount

Error message #2

<type 'exceptions.TypeError'> unsupported operand type(s) for +: 'Rows' and 
'float'

Error message #3

No error message - this overwrites cumulative amount to the amount entered 
by the user, no memory.



Thanks for any help!!

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to