Hello Everyone !
I'm beginner with web2py. I'm writing a code to sell product.
My question is about the billing form (SQLFORM on 'db.bill').
Each time a product (represented by it's 'code') is chosen from the drop
down list, I'd like to able to find the corresponding product in the
'product' table,
copy infos and show them automatically (fields 'name', 'description', and
'weight') in the form.
Could you help me? what would be the simplest way to do it?
Below is the code. I also attached it.
Thanks.
=====
# for the model
db = DAL("sqlite://storage.sqlite")
db.define_table('vendor',
Field('name_vendor', unique=True, length=128),
Field('address_vendor', length=128),
format = '%(name_vendor)s')
db.define_table('client',
Field('name_client', unique=True, length=128,),
Field('address_client', length=128),
format = '%(name_client)s')
db.define_table('product',
Field('name', length=128,),
Field('code', unique=True, length=17,),
Field('description', length=128),
Field('weight', 'double'),
Field('vendor_id', 'reference vendor'),
Field('acquired_on', 'date'),
Field('sold', 'boolean', default=False),
format = '%(code)s %(name)s')
db.define_table('bill',
Field('date_billing', 'date'),
Field('hour_billing', 'time'),
Field('client_id', 'reference client'),
Field('code', length=17),
Field('name', length=128),
Field('description', length=128),
Field('weight', 'double'),
Field('montant_ht', 'integer', default=0),
Field('author', length=128),
format = '%(id)s %(date_billing)s %(client_id)s')
db.vendor.name_vendor.requires = IS_NOT_EMPTY()
db.vendor.name_vendor.requires = IS_NOT_IN_DB(db, db.vendor.name_vendor)
db.client.name_client.requires = IS_NOT_EMPTY()
db.client.name_client.requires = IS_NOT_IN_DB(db, db.vendor.name_client)
db.product.name.requires = IS_NOT_EMPTY()
db.product.code.requires = IS_NOT_EMPTY()
db.product.code.requires = IS_NOT_IN_DB(db, db.product.code)
db.product.vendor_id.requires = IS_IN_DB(db, db.vendor.id,
'%(name_vendor)s')
db.bill.date_billing.requires = db.bill.hour_billing.requires =
IS_NOT_EMPTY()
db.bill.date_billing.requires = IS_DATE()
db.bill.hour_billing.requires = IS_TIME()
db.bill.client_id.requires = IS_IN_DB(db, db.client.id, '%(name_client)s')
db.bill.code.requires = IS_IN_DB(db(db.product.sold == False),
db.product.code, '%(code)s')
db.bill.name.writable = False
db.bill.name.writable = db.bill.description.writable =
db.bill.weight.writable = False
db.bill.author.writable = db.bill.author.readable = False
# For the controller
def sell():
"""
"""
form = SQLFORM(db.bill, labels= {'date_billing':'Date',
'hour_billing':'Hour',
'client_id':'Client',
'code':'Code',
'name':'Product name',
'description':'Description',
'weight':'Weight',
'montant_ht':'Montant HT'})
if form.process().accepted:
response.flash = 'Record OK!'
elif form.errors:
response.flash = 'Errors in form!'
else:
response.flash = 'Fill form!'
return dict(form=form)
--
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.
# for the model
db = DAL("sqlite://storage.sqlite")
db.define_table('vendor',
Field('name_vendor', unique=True, length=128),
Field('address_vendor', length=128),
format = '%(name_vendor)s')
db.define_table('client',
Field('name_client', unique=True, length=128,),
Field('address_client', length=128),
format = '%(name_client)s')
db.define_table('product',
Field('name', length=128,),
Field('code', unique=True, length=17,),
Field('description', length=128),
Field('weight', 'double'),
Field('vendor_id', 'reference vendor'),
Field('acquired_on', 'date'),
Field('sold', 'boolean', default=False),
format = '%(code)s %(name)s')
db.define_table('bill',
Field('date_billing', 'date'),
Field('hour_billing', 'time'),
Field('client_id', 'reference client'),
Field('code', length=17),
Field('name', length=128),
Field('description', length=128),
Field('weight', 'double'),
Field('montant_ht', 'integer', default=0),
Field('author', length=128),
format = '%(id)s %(date_billing)s %(client_id)s')
db.vendor.name_vendor.requires = IS_NOT_EMPTY()
db.vendor.name_vendor.requires = IS_NOT_IN_DB(db, db.vendor.name_vendor)
db.client.name_client.requires = IS_NOT_EMPTY()
db.client.name_client.requires = IS_NOT_IN_DB(db, db.vendor.name_client)
db.product.name.requires = IS_NOT_EMPTY()
db.product.code.requires = IS_NOT_EMPTY()
db.product.code.requires = IS_NOT_IN_DB(db, db.product.code)
db.product.vendor_id.requires = IS_IN_DB(db, db.vendor.id, '%(name_vendor)s')
db.bill.date_billing.requires = db.bill.hour_billing.requires = IS_NOT_EMPTY()
db.bill.date_billing.requires = IS_DATE()
db.bill.hour_billing.requires = IS_TIME()
db.bill.client_id.requires = IS_IN_DB(db, db.client.id, '%(name_client)s')
db.bill.code.requires = IS_IN_DB(db(db.product.sold == False), db.product.code,
'%(code)s')
db.bill.name.writable = False
db.bill.name.writable = db.bill.description.writable = db.bill.weight.writable
= False
db.bill.author.writable = db.bill.author.readable = False
# For the controller
def sell():
"""
"""
form = SQLFORM(db.bill, labels= {'date_billing':'Date',
'hour_billing':'Hour',
'client_id':'Client',
'code':'Code',
'name':'Product name',
'description':'Description',
'weight':'Weight',
'montant_ht':'Montant HT'})
if form.process().accepted:
response.flash = 'Record OK!'
elif form.errors:
response.flash = 'Errors in form!'
else:
response.flash = 'Fill form!'
return dict(form=form)