here is the db.py file (it's a work-in-progress), the default.py (it's
a welcome app modification) and the movqta.html.
Look to default/movqta url
Marco
#########
db.define_table('movtempi_mast',
Field('IDStaffatura','string'),
Field('fase','string'),
Field('data_inizio','datetime'),
Field('ora_inizio','time'),
Field('data_fine','datetime'),
Field('ora_fine','time'))
db.define_table('movtempi_dett',
Field('IDStaffatura',db.movtempi_mast),
Field('operatore','string'),
Field('tempo','integer'),
Field('nome_operazione','string'))
db.define_table('operatore',
Field('nome','string'),
Field('Descrizione','string'))
db.movtempi_mast.fase.requires=IS_IN_SET(['Formatura','Ramolaggio','Distaffatura'])
db.movtempi_dett.operatore.requires=IS_IN_DB(db,'operatore.id','operatore.nome')
db.define_table('magazzino',
Field('nome','string'))
db.define_table('articoli',
Field('codice','string'),
Field('descrizione','string'),
Field('leadtime_acquisto','integer',default=0),
Field('leadtime_produzione','integer',default=0),
Field('fornitore_pref','string'),
Field('classe1','string'),
Field('classe2','string'),
Field('classe3','string'),
Field('classe4','string'),
Field('lotto_minimo','integer',default=0),
Field('punto_riordino','integer',default=0),
Field('unimis1','string',requires=IS_IN_SET(['kg','mt','pz','altro'])),
Field('unimis2','string',requires=IS_IN_SET(['','kg','mt','pz','altro'])),
Field('conversione','decimal(3,3)',default=1.0))
#unimis2=conversione*unimis1
#campi di costo non inseriti perche gia presenti su gestionale, da
valutare collegamento con tabelle per recuperare i dati di costo
db.define_table('mov_qta',
Field('causale','string',requires=IS_NOT_EMPTY(error_message=T('inserire
un valore'))),
Field('articolo',db.articoli),
Field('magazzino','string'),
Field('qta','integer'),
Field('segno','integer'),
Field('data_prevista','datetime'),
Field('data_effettiva','datetime',default=request.now),
Field('stato','string'))
db.mov_qta.stato.requires=IS_IN_SET(['E','P'])
db.mov_qta.causale.requires=IS_IN_SET(['Carico da acquisto', 'Scarico
vs produzione','Prelievo per prove distruttive','Carico da
produzione'])
db.mov_qta.magazzino.requires=IS_IN_DB(db,'magazzino.id','magazzino.nome')
db.mov_qta.articolo.requires=IS_IN_DB(db,'articoli.id','articoli.codice')
############
#default.py
def index():
"""
example action using the internationalization operator T and flash
rendered by views/default/index.html or views/generic.html
"""
response.flash = T('Welcome to web2py')
form=SQLFORM.factory(
Field('IDStaffatura','string'),
Field('fase','string'),
Field('data_inizio','date',requires = IS_DATE(format=T('%Y-%m-
%d'))),
Field('ora_inizio','time'),
Field('operatore1',
requires=IS_EMPTY_OR(IS_IN_DB(db,'operatore.nome'))),
Field('tempo1','integer'),
Field('operatore2',requires=IS_EMPTY_OR(IS_IN_DB(db,'operatore.nome'))),
Field('tempo2','integer'),
Field('operatore3',requires=IS_EMPTY_OR(IS_IN_DB(db,'operatore.nome'))),
Field('tempo3','integer'),
Field('operatore4',requires=IS_EMPTY_OR(IS_IN_DB(db,'operatore.nome'))),
Field('tempo4','integer'),
Field('operatore5',requires=IS_EMPTY_OR(IS_IN_DB(db,'operatore.nome'))),
Field('tempo5','integer'),
Field('tempo6','integer',label='Indurimento'),
Field('data_fine','date',requires = IS_DATE(format=T('%Y-%m-
%d'))),
Field('ora_fine','time'))
#db.movtempi_mast.IDStaffatura, db.movtempi_mast.data_inizio,
db.movtempi_dett.tempo)
msg='Prova 3'
if form.accepts(request.vars):
id1=db.movtempi_mast.insert(IDStaffatura=form.vars.IDStaffatura,
fase=form.vars.fase,
data_inizio=form.vars.data_inizio,
ora_inizio=form.vars.ora_inizio,
data_fine=form.vars.data_fine,
ora_fine=form.vars.ora_fine)
for i in range(1,6,1):
if getattr(form.vars,'operatore%s' % i)!=None and
getattr(form.vars,'tempo%s' % i)!=None:
idx=db.movtempi_dett.insert(IDStaffatura=id1,
tempo=getattr(form.vars,'tempo%s'
% i),
operatore=getattr(form.vars,'operatore%s' % i))
#msg=str(idx)
if form.vars.tempo6!=None:
db.movtempi_dett.insert(IDStaffatura=id1,
tempo=form.vars.tempo6,
nome_operazione='indurimento')
return dict(message=msg,scheda=form)
def movqta():
form=SQLFORM(db.mov_qta)
if form.accepts(request.vars,session):
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
return dict(scheda=form)
def articoli():
form=crud.create(db.articoli)
if form.accepts(request.vars,session):
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
return dict(scheda=form)
def user():
"""
exposes:
http://..../[app]/default/user/login
http://..../[app]/default/user/logout
http://..../[app]/default/user/register
http://..../[app]/default/user/profile
http://..../[app]/default/user/retrieve_password
http://..../[app]/default/user/change_password
use @auth.requires_login()
@auth.requires_membership('group name')
@auth.requires_permission('read','table name',record_id)
to decorate functions that need access control
"""
return dict(form=auth())
def download():
"""
allows downloading of uploaded files
http://..../[app]/default/download/[filename]
"""
return response.download(request,db)
def call():
"""
exposes services. for example:
http://..../[app]/default/call/jsonrpc
decorate with @services.jsonrpc the functions to expose
supports xml, json, xmlrpc, jsonrpc, amfrpc, rss, csv
"""
session.forget()
return service()
#####movqta.html
{{extend 'layout.html'}}
<h1>Form movimenti di magazzino</h1>
{{=scheda}}