def index(): from invoices import Fiscal, Order, Orderlist from shops import Product, PricePlan Fiscal(db), Product(db), PricePlan(db), Order(db), Orderlist(db) fiscal=db(db.fiscals.user==auth.user_id).select().first() order=None orderlist=None if fiscal: order=db((db.orders.user==auth.user_id) & (db.orders.status=="Creando")).select().first() if order: orderlist=db(db.orderlist.g_order==order.id).select() flatrate=False for item in orderlist: if item.product.plan: if item.product.plan.paymode=="flatrate": flatrate=True else: redirect(URL(c='account',f='index')) else: redirect(URL('myaccount', 'fiscal', vars=dict(wizard=True))) form=FORM( INPUT(_type='radio', _name='paypal', _id='paypal', _value='paypal', value='yes').xml(), INPUT(_type='radio', _name='bank', _id='bank', _value='bank', value='no').xml(), INPUT(_name="confirm", _type='submit', _class="btn btn-grove-two btn-xlg"), _action=URL('confirm_order') ) return dict(form=form, fiscal=fiscal, orderlist=orderlist, order=order, flatrate=flatrate)
def newbudget(): from shops import Product from invoices import Fiscal, Budget from adminsettings import Adminsettings Adminsettings(db), Product(db), Fiscal(db), Budget(db) settings = db(db.adminsettings.id > 0).select(db.adminsettings.ALL).first() if auth.has_membership('superadministradores') or auth.has_membership( 'administradores'): if request.args(0): products = db(db.products.active == True).select() if request.args(1): budget = db((db.budgets.user == request.args(0)) & ( db.budgets.id == request.args(1))).select().first() else: budget = db((db.budgets.user == request.args(0)) & (db.budgets.status == "Creando")).select().first() if not budget: budgetid = db.budgets.insert(status="Creando", tax=settings.tax, user=request.args(0)) budget = db.budgets(budgetid) customer = db(db.auth_user.id == request.args(0)).select( db.auth_user.id, db.auth_user.first_name, db.auth_user.last_name, db.auth_user.email, db.fiscals.ALL, left=[db.fiscals.on(db.fiscals.user == db.auth_user.id) ]).first() db.commit() return dict(products=products, customer=customer, tax=budget.tax, budgetid=budget.id) else: redirect(URL(request.application, 'administrator', 'users')) else: redirect(URL(request.application, 'default', 'user/login'))
def billing(): if auth.has_membership('administradores') or auth.has_membership('superadministradores'): from invoices import Fiscal, Invoice,Order from pagination import Pagination Fiscal(db), Invoice(db), Order(db) settings = db(db.adminsettings.id>0).select(db.adminsettings.ALL).first() count=db.invoices.id.count() records=db((db.invoices.id>0)).select(count, left=[ db.auth_user.on(db.auth_user.id==db.invoices.user), db.fiscals.on(db.fiscals.user==db.auth_user.id)], orderby=~db.invoices.id).first() items_per_page=settings.invoiceitems pag=Pagination(int(records[count]), items_per_page) invoices= db((db.invoices.id>0)).select(db.orders.status, db.orders.invoice, db.invoices.ALL, db.auth_user.id, db.auth_user.first_name, db.auth_user.last_name, db.fiscals.fiscalname, left=[ db.orders.on(db.orders.invoice==db.invoices.id), db.auth_user.on(db.auth_user.id==db.invoices.user), db.fiscals.on(db.fiscals.user==db.auth_user.id), ], orderby=~db.invoices.id, limitby=pag.limitby()) total=0 totaltaxes=0 for invoice in db(db.invoices.created_at>=datetime.date(datetime.datetime.today().year,1,1)).select(): total=total+ invoice.total totaltaxes= totaltaxes + invoice.taxes return dict(invoices=invoices, pagination=pag, records=records[count], items_per_page=items_per_page, total=total, totaltaxes=totaltaxes) else: redirect(URL(request.application,'default','user/login'))
import datetime import copy import gluon.contenttype import gluon.fileutils from blog import Blog, Draft, Images from shops import Shop, DomainShop, PricePlan, Product, ContractedProduct, ProfilePlan, PricePlan, CustomerAgreement, Agreement from invoices import Invoice, Order, Orderlist, Fiscal, CreditAccount, AccountingEntry, Budget, Budgetlist from regnews import Regnews from province import Province from cities import Cities Images(db), Blog(db, ckeditor), Draft( db, ckeditor), Regnews(db), Province(db), Cities(db) Shop(db), PricePlan(db), DomainShop(db), Product(db) ProfilePlan(db), PricePlan(db), CustomerAgreement(db), Agreement(db) Invoice(db), Order(db), Orderlist(db), Budget(db), Budgetlist(db), Fiscal( db), ContractedProduct(db), CreditAccount(db), AccountingEntry(db) try: import pygraphviz as pgv except ImportError: pgv = None # ## critical --- make a copy of the environment global_env = copy.copy(globals()) global_env['datetime'] = datetime http_host = request.env.http_host.split(':')[0] remote_addr = request.env.remote_addr try: hosts = (http_host, socket.gethostname(), socket.gethostbyname(http_host),
def fiscal(): from invoices import Fiscal from cities import Cities from province import Province Fiscal(db), Province(db), Cities(db) fiscal = db(db.fiscals.user == auth.user_id).select().first() logger.debug(fiscal) wpoblacion = SQLFORM.widgets.autocomplete(request, db.cities.poblacion, limitby=(0, 10), min_length=2) wprovincia = SQLFORM.widgets.autocomplete(request, db.province.provincia, limitby=(0, 10), min_length=2) if request.vars.wizard: wizard = request.vars.wizard else: wizard = False if fiscal: tax_identification = Field( 'tax_identification', 'string', label=XML( "<strong>NIF/CIF/NIE</strong> <span class='glyphicon glyphicon-question-sign'></span>" ), default=fiscal.tax_identification, length=45, notnull=True, requires=IS_NOT_EMPTY(error_message="No olvide esta dato")) fiscalname = Field('fiscalname', 'string', label=XML("<strong>Nombre empresa</strong>"), default=fiscal.fiscalname, length=128, notnull=False) address = Field( 'address', 'string', label=XML("<strong>Dirección</strong>"), default=fiscal.address, length=250, notnull=True, requires=IS_NOT_EMPTY(error_message="no olvide este dato")) city = Field( 'city', 'string', label=XML("<strong>Ciudad/Población</strong>"), default=fiscal.city, length=45, notnull=True, requires=IS_NOT_EMPTY(error_message="no olvide este dato"), widget=wpoblacion) province = Field('province', 'string', label=XML("<strong>Provincia</strong>"), default=fiscal.province, notnull=False, widget=wprovincia) country = Field( 'country', 'string', label=XML("<strong>Pais</strong>"), length=45, default=fiscal.country, notnull=True, requires=IS_NOT_EMPTY(error_message="no olvide este dato")) postalcode = Field( 'postal_code', 'string', label=XML("<strong>Código postal</strong>"), default=fiscal.postal_code, length=10, notnull=True, requires=IS_NOT_EMPTY(error_message="no olvide este dato")) phone = Field('phone', 'string', label=XML("<strong>Teléfono de contacto</strong>"), length=20, default=fiscal.phone, notnull=False) else: tax_identification = Field( 'tax_identification', 'string', label=XML( "<strong>NIF/CIF/NIE</strong> <span class='glyphicon glyphicon-question-sign'></span>" ), length=45, notnull=True, requires=IS_NOT_EMPTY(error_message="No olvide esta dato")) fiscalname = Field('fiscalname', 'string', label=XML("<strong>Nombre empresa</strong>"), length=128, notnull=False) address = Field( 'address', 'string', label=XML("<strong>Dirección</strong>"), length=196, notnull=True, requires=IS_NOT_EMPTY(error_message="no olvide este dato")) city = Field( 'city', 'string', label=XML("<strong>Ciudad/Población</strong>"), length=45, notnull=True, requires=IS_NOT_EMPTY(error_message="no olvide este dato"), widget=wpoblacion) province = Field('province', 'string', label=XML("<strong>Provincia</strong>"), length=45, notnull=False, widget=wprovincia) country = Field( 'country', 'string', label=XML("<strong>Pais</strong>"), length=45, notnull=True, requires=IS_NOT_EMPTY(error_message="no olvide este dato")) postalcode = Field( 'postal_code', 'string', label=XML("<strong>Código postal</strong>"), length=10, notnull=True, requires=IS_NOT_EMPTY(error_message="no olvide este dato")) phone = Field('phone', 'string', label=XML("<strong>Teléfono de contacto</strong>"), length=20, notnull=False) form = SQLFORM.factory(tax_identification, fiscalname, address, city, province, country, postalcode, phone, submit_button=('enviar datos', 'siguiente')[wizard == True], formstyle='bootstrap3_inline') if form.validate(keepvalues=True): if fiscal: #update db(db.fiscals.id == fiscal.id).update( tax_identification=form.vars.tax_identification, fiscalname=form.vars.fiscalname, address=form.vars.address, city=form.vars.city, province=form.vars.province, country=form.vars.country, postal_code=form.vars.postal_code, phone=form.vars.phone) else: #insert db.fiscals.insert(user=auth.user_id, tax_identification=form.vars.tax_identification, fiscalname=form.vars.fiscalname, address=form.vars.address, city=form.vars.city, province=form.vars.province, country=form.vars.country, postal_code=form.vars.postal_code, phone=form.vars.phone) session.flash = "Datos enviados correctamente" if wizard: redirect(URL(request.application, 'payment', 'index')) else: redirect(URL('account')) elif form.errors: response.flash = 'Hay errores' form.element('input[name=city]')['_class'] = 'form-control' form.element('input[name=province]')['_class'] = 'form-control' form.element('div#no_table_tax_identification__row div.col-sm-9' )['_class'] = 'col-sm-3' form.element( 'div#no_table_fiscalname__row div.col-sm-9')['_class'] = 'col-sm-4' form.element('div#no_table_city__row div.col-sm-9')['_class'] = 'col-sm-4' form.element( 'div#no_table_province__row div.col-sm-9')['_class'] = 'col-sm-3' form.element( 'div#no_table_country__row div.col-sm-9')['_class'] = 'col-sm-2' form.element( 'div#no_table_postal_code__row div.col-sm-9')['_class'] = 'col-sm-2' form.element('div#no_table_phone__row div.col-sm-9')['_class'] = 'col-sm-4' # form.element('label.col-lg-2')['_class']='col-lg-3 control-label' # form.element('label.col-lg-2')['_class']='col-lg-3 control-label' # form.element('label.col-lg-2')['_class']='col-lg-3 control-label' # form.element('label.col-lg-2')['_class']='col-lg-3 control-label' # form.element('label.col-lg-2')['_class']='col-lg-3 control-label' # form.element('label.col-lg-2')['_class']='col-lg-3 control-label' # form.element('label.col-lg-2')['_class']='col-lg-3 control-label' # form.element('label.col-lg-2')['_class']='col-lg-3 control-label' return dict(form=form)
def neworder(): from shops import Product from invoices import Fiscal, Order, Orderlist, Budgetlist from adminsettings import Adminsettings Adminsettings(db), Product(db), Fiscal(db), Order(db), Orderlist( db), Budgetlist(db) settings = db(db.adminsettings.id > 0).select(db.adminsettings.ALL).first() if auth.has_membership('superadministradores') or auth.has_membership( 'administradores'): if request.args(0): products = db(db.products.active == True).select() if request.vars.budget: order = db((db.orders.user == request.args(0)) & (db.orders.status == "CreandoAdmin") & (db.orders.budget == request.vars.budget)).select( ).first() if not order: orderid = db.orders.insert(status="CreandoAdmin", user=request.args(0), budget=request.vars.budget, tax=settings.tax, payment_method='Transferencia', manual_operation=True) order = db.orders(orderid) for row in db(db.budgetlist.g_budget == request.vars.budget).select(): db.orderlist.insert(product=row.product, g_order=orderid, quantity=row.quantity, price=row.price, price_wdto=row.price_wdto, tax=row.tax, dto=row.dto, dto_percentage=row.dto_percentage) else: if request.args(1): order = db((db.orders.user == request.args(0)) & ( db.orders.id == request.args(1))).select().first() else: order = db((db.orders.user == request.args(0)) & ( db.orders.status == "CreandoAdmin")).select().first() if not order: orderid = db.orders.insert(status="CreandoAdmin", tax=settings.tax, user=request.args(0), payment_method='Transferencia', manual_operation=True) order = db.orders(orderid) customer = db(db.auth_user.id == request.args(0)).select( db.auth_user.id, db.auth_user.first_name, db.auth_user.last_name, db.auth_user.email, db.fiscals.ALL, left=[db.fiscals.on(db.fiscals.user == db.auth_user.id) ]).first() db.commit() return dict(products=products, customer=customer, tax=order.tax, order=order) else: redirect(URL(request.application, 'administrator', 'users')) else: redirect(URL(request.application, 'default', 'user/login'))
def editcustomer(): if auth.has_membership('administradores') or auth.has_membership('superadministradores'): if request.args(0): from invoices import Fiscal, Order, Orderlist, Invoice, Budget, AccountingEntry, CreditAccount from shops import ContractedProduct, Product, Shop from cities import Cities from province import Province Fiscal(db), Province(db), Cities(db), ContractedProduct(db), Product(db), Shop(db), Order(db), Orderlist(db), AccountingEntry(db), CreditAccount(db), Invoice(db), Budget(db) customer=db(db.auth_user.id==request.args(0)).select( db.auth_user.id, db.auth_user.first_name, db.auth_user.last_name, db.auth_user.email, db.fiscals.ALL, left=[db.fiscals.on(db.fiscals.user==db.auth_user.id)]).first() wpoblacion = SQLFORM.widgets.autocomplete(request, db.cities.poblacion, limitby=(0,10), min_length=2) wprovincia = SQLFORM.widgets.autocomplete(request, db.province.provincia, limitby=(0,10), min_length=2) inc=datetime.timedelta(days=30) contractedproducts = db((db.contractedproducts.user==request.args(0)) & ( (db.contractedproducts.expiration+inc>=datetime.datetime.now()) | (db.contractedproducts.expiration==None) )).select( db.contractedproducts.ALL, db.products.ALL, db.shop.ALL, db.auth_user.ALL, db.fiscals.ALL, left=[ db.products.on(db.products.id==db.contractedproducts.product), db.shop.on(db.shop.id==db.contractedproducts.shop), db.auth_user.on(db.auth_user.id==db.contractedproducts.user), db.fiscals.on(db.fiscals.user==db.auth_user.id)], orderby=~db.contractedproducts.expiration) invoices = db( db.invoices.user==request.args(0)).select(db.invoices.ALL, db.orders.id, db.orders.status, left=[ db.orders.on(db.orders.invoice==db.invoices.id)], orderby=~db.invoices.id, groupby=db.orders.id ) budgets = db((db.budgets.user==request.args(0)) & (db.budgets.status!="Creando")).select(db.budgets.ALL, orderby=~db.budgets.id) orders= db((db.orders.invoice==None) & (db.orders.user==request.args(0))).select(orderby=~db.orders.id) if customer!=None: first_name= Field('first_name', 'string', label=XML("<strong>Nombre</strong>"), length=128, notnull=True, default=customer.auth_user.first_name, requires=IS_NOT_EMPTY(error_message="No olvide esta dato")) last_name= Field('last_name', 'string', label=XML("<strong>Apellidos</strong>"), length=128, notnull=True, default=customer.auth_user.last_name, requires=IS_NOT_EMPTY(error_message="No olvide esta dato")) email=Field('email', label=XML('<strong>Email</strong>'), length=128, writable=False, notnull=True, default=customer.auth_user.email, requires=[IS_NOT_EMPTY(), IS_EMAIL(error_message='No puede estar vacío.')]) tax_identification = Field('tax_identification', 'string', label=XML("<strong>NIF/CIF/NIE</strong> <span class='glyphicon glyphicon-question-sign'></span>"),length=45, notnull=True, default=customer.fiscals.tax_identification, requires=IS_NOT_EMPTY(error_message="No olvide esta dato")) fiscalname=Field('fiscalname', 'string', label=XML("<strong>Nombre empresa</strong>") ,length =128, notnull=False, default=customer.fiscals.fiscalname) address=Field('address', 'string', label=XML("<strong>Dirección</strong>"), length =196, notnull=True, default=customer.fiscals.address, requires=IS_NOT_EMPTY(error_message="no olvide este dato")) city= Field('city', 'string', label=XML("<strong>Ciudad/Población</strong>"), length=45, notnull=True, default=customer.fiscals.city, requires=IS_NOT_EMPTY(error_message="no olvide este dato"), widget=wpoblacion) province = Field('province', 'string', label=XML("<strong>Provincia</strong>"), length=45, notnull=True, default=customer.fiscals.province, requires=IS_NOT_EMPTY(error_message="no olvide este dato"), widget=wprovincia) country=Field('country', 'string', label=XML("<strong>Pais</strong>"), length =45, notnull=True, default=customer.fiscals.country, requires=IS_NOT_EMPTY(error_message="no olvide este dato")) postalcode=Field('postal_code', 'string', label=XML("<strong>Código postal</strong>"), length=10, notnull=False, default=customer.fiscals.postal_code) phone=Field('phone', 'string', label=XML("<strong>Teléfono</strong>"), length=20, notnull=False, default=customer.fiscals.phone) form = SQLFORM.factory(first_name, last_name, email, tax_identification, fiscalname, address, city, province, country, postalcode, phone, submit_button = 'enviar datos', formstyle='bootstrap3_inline') if form.validate(keepvalues=True): try: db(db.auth_user.id==customer.auth_user.id).update(first_name=form.vars.first_name, last_name=form.vars.last_name) db(db.fiscals.id==customer.fiscals.id).update(tax_identification=form.vars.tax_identification, fiscalname=form.vars.fiscalname, address=form.vars.address, city=form.vars.city, province=form.vars.province, country=form.vars.country, postal_code=form.vars.postal_code, phone=form.vars.phone) db.commit() except Exception, ex: logger.debug("No se pudo modificar los datos del usuario/fiscal: %s" % ex) db.rollback() response.flash = 'Hubo un error: %s' % ex response.flash="Datos enviados correctamente" elif form.errors: response.flash = 'Hay errores' form.element('input[name=city]')['_class']='form-control' form.element('input[name=province]')['_class']='form-control' creditaccount=db(db.creditaccounts.user==customer.auth_user.id).select().first() accountingentries=None if creditaccount: accountingentries = db( (db.accountingentries.creditaccount==creditaccount.id) & (db.accountingentries.active==True) ).select( db.accountingentries.ALL, db.orders.ALL, db.invoices.ALL, db.products.name, join=[ db.orderlist.on(db.accountingentries.orderlist==db.orderlist.id), db.products.on(db.products.id==db.orderlist.product), db.orders.on(db.orders.id==db.orderlist.g_order), db.invoices.on(db.invoices.id==db.orders.invoice)], orderby=~db.accountingentries.id) return dict(form=form, contractedproducts=contractedproducts, invoices=invoices, budgets=budgets, orders=orders, userid=customer.auth_user.id, accountingentries=accountingentries, creditaccount=creditaccount) else: redirect(URL('administrator','newcustomer')) else: redirect(URL('administrator','users'))
def newcustomer(): if auth.has_membership('administradores') or auth.has_membership('superadministradores'): from invoices import Fiscal from cities import Cities from province import Province Fiscal(db), Province(db), Cities(db) wpoblacion = SQLFORM.widgets.autocomplete(request, db.cities.poblacion, limitby=(0,10), min_length=2) wprovincia = SQLFORM.widgets.autocomplete(request, db.province.provincia, limitby=(0,10), min_length=2) first_name = Field('first_name', 'string', label=XML("<strong>Nombre</strong>"), length=128, notnull=True, requires=IS_NOT_EMPTY(error_message="No olvide esta dato")) last_name = Field('last_name', 'string', label=XML("<strong>Apellidos</strong>"), length=128, notnull=True, requires=IS_NOT_EMPTY(error_message="No olvide esta dato")) password = Field('password', label = XML("<strong>Contraseña</strong>"), requires=[IS_NOT_EMPTY(error_message="No olvide esta dato")]) email = Field('email', label=XML('<strong>Email</strong>'), length=128, notnull=True, requires=[IS_NOT_EMPTY(), IS_EMAIL(error_message='No puede estar vacío.'), IS_NOT_IN_DB(db,'auth_user.email')]) tax_identification = Field('tax_identification', 'string', label=XML("<strong>NIF/CIF/NIE</strong> <span class='glyphicon glyphicon-question-sign'></span>"),length=45, notnull=False) fiscalname = Field('fiscalname', 'string', label=XML("<strong>Nombre empresa</strong>") ,length =128, notnull=False) address = Field('address', 'string', label=XML("<strong>Dirección</strong>"), length =196, notnull=False) city = Field('city', 'string', label=XML("<strong>Ciudad/Población</strong>"), length=45, notnull=False, widget=wpoblacion) province = Field('province', 'string', label=XML("<strong>Provincia</strong>"), length=45, notnull=False, widget=wprovincia) country = Field('country', 'string', label=XML("<strong>Pais</strong>"), length =45, notnull=False) postalcode = Field('postal_code', 'string', label=XML("<strong>Código postal</strong>"), length=10, notnull=False) phone = Field('phone', 'string', label=XML("<strong>Teléfono</strong>"), length=20, notnull=False) form = SQLFORM.factory(first_name, last_name, password, email, tax_identification, fiscalname, address, city, province, country, postalcode, phone, submit_button = 'enviar datos', formstyle='bootstrap3_inline') if form.validate(keepvalues=True): try: userid=db.auth_user.insert(first_name=form.vars.first_name, last_name=form.vars.last_name, password=CRYPT(key=Auth.get_or_create_key(), digest_alg='pbkdf2(1000,20,sha512)', salt=True)(form.vars.password)[0], email=form.vars.email) if userid: db.fiscals.insert( user=userid, tax_identification=form.vars.tax_identification, fiscalname=form.vars.fiscalname, address=form.vars.address, city=form.vars.city, province=form.vars.province, country=form.vars.country, postal_code=form.vars.postal_code, phone=form.vars.phone) auth.add_membership(db(db.auth_group.role=="clientes").select().first()["id"], userid) db.commit() else: response.flash="no se ha creado al usario" except Exception, ex: logger.debug("No se pudo crear al nuevo cliente: %s" % ex) db.rollback() response.flash = 'Hubo un error: %s' % ex redirect(URL('administrator','editcustomer', args=userid)) elif form.errors: response.flash = 'Hay errores' else: response.flash = 'Por favor completa los campos' form.element('input[name=city]')['_class']='form-control' form.element('input[name=province]')['_class']='form-control' return dict(form=form)
def myaccount(): from invoices import Fiscal from cities import Cities from province import Province Fiscal(db), Province(db), Cities(db), customer = db(db.auth_user.id == auth.user_id).select( db.auth_user.id, db.auth_user.first_name, db.auth_user.last_name, db.auth_user.email, db.fiscals.ALL, left=[db.fiscals.on(db.fiscals.user == db.auth_user.id)]).first() wpoblacion = SQLFORM.widgets.autocomplete(request, db.cities.poblacion, limitby=(0, 10), min_length=2) wprovincia = SQLFORM.widgets.autocomplete(request, db.province.provincia, limitby=(0, 10), min_length=2) if customer != None: first_name = Field( 'first_name', 'string', label=XML("<strong>Nombre</strong>"), length=128, notnull=True, default=customer.auth_user.first_name, requires=IS_NOT_EMPTY(error_message="No olvide esta dato")) last_name = Field( 'last_name', 'string', label=XML("<strong>Apellidos</strong>"), length=128, notnull=True, default=customer.auth_user.last_name, requires=IS_NOT_EMPTY(error_message="No olvide esta dato")) email = Field('email', label=XML('<strong>Email</strong>'), length=128, writable=False, notnull=True, default=customer.auth_user.email, requires=[ IS_NOT_EMPTY(), IS_EMAIL(error_message='No puede estar vacío.') ]) tax_identification = Field( 'tax_identification', 'string', label=XML( "<strong>NIF/CIF/NIE</strong> <span class='glyphicon glyphicon-question-sign'></span>" ), length=45, notnull=True, default=customer.fiscals.tax_identification, requires=IS_NOT_EMPTY(error_message="No olvide esta dato")) fiscalname = Field('fiscalname', 'string', label=XML("<strong>Nombre empresa</strong>"), length=128, notnull=False, default=customer.fiscals.fiscalname) address = Field( 'address', 'string', label=XML("<strong>Dirección</strong>"), length=196, notnull=True, default=customer.fiscals.address, requires=IS_NOT_EMPTY(error_message="no olvide este dato")) city = Field( 'city', 'string', label=XML("<strong>Ciudad/Población</strong>"), length=45, notnull=True, default=customer.fiscals.city, requires=IS_NOT_EMPTY(error_message="no olvide este dato"), widget=wpoblacion) province = Field( 'province', 'string', label=XML("<strong>Provincia</strong>"), length=45, notnull=True, default=customer.fiscals.province, requires=IS_NOT_EMPTY(error_message="no olvide este dato"), widget=wprovincia) country = Field( 'country', 'string', label=XML("<strong>Pais</strong>"), length=45, notnull=True, default=customer.fiscals.country, requires=IS_NOT_EMPTY(error_message="no olvide este dato")) postalcode = Field('postal_code', 'string', label=XML("<strong>Código postal</strong>"), length=10, notnull=False, default=customer.fiscals.postal_code) phone = Field('phone', 'string', label=XML("<strong>Teléfono</strong>"), length=20, notnull=False, default=customer.fiscals.phone) form = SQLFORM.factory(first_name, last_name, email, tax_identification, fiscalname, address, city, province, country, postalcode, phone, submit_button='modificar datos', formstyle='bootstrap3_inline') if form.validate(keepvalues=True): try: db(db.auth_user.id == customer.auth_user.id).update( first_name=form.vars.first_name, last_name=form.vars.last_name) db(db.fiscals.id == customer.fiscals.id).update( tax_identification=form.vars.tax_identification, fiscalname=form.vars.fiscalname, address=form.vars.address, city=form.vars.city, province=form.vars.province, country=form.vars.country, postal_code=form.vars.postal_code, phone=form.vars.phone) db.commit() except Exception, ex: logger.debug( "No se pudo modificar los datos del usuario/fiscal: %s" % ex) db.rollback() response.flash = 'Hubo un error: %s' % ex response.flash = "Datos modificados correctamente" elif form.errors: response.flash = 'Hay errores' else: response.flash = 'Por favor completa los campos' form.element('input[name=city]')['_class'] = 'form-control' form.element('input[name=province]')['_class'] = 'form-control' form.element('input[name=city]')['_class'] = 'form-control' form.element('input[name=province]')['_class'] = 'form-control' form.element( 'div#no_table_first_name__row div.col-sm-9')['_class'] = 'col-sm-4' form.element( 'div#no_table_last_name__row div.col-sm-9')['_class'] = 'col-sm-4' form.element('div#no_table_tax_identification__row div.col-sm-9' )['_class'] = 'col-sm-3' form.element( 'div#no_table_fiscalname__row div.col-sm-9')['_class'] = 'col-sm-4' form.element( 'div#no_table_city__row div.col-sm-9')['_class'] = 'col-sm-4' form.element( 'div#no_table_province__row div.col-sm-9')['_class'] = 'col-sm-3' form.element( 'div#no_table_country__row div.col-sm-9')['_class'] = 'col-sm-2' form.element('div#no_table_postal_code__row div.col-sm-9' )['_class'] = 'col-sm-2' form.element( 'div#no_table_phone__row div.col-sm-9')['_class'] = 'col-sm-4' form.element('label#no_table_first_name__label' )['_class'] = 'col-sm-2 control-label' form.element('label#no_table_last_name__label' )['_class'] = 'col-sm-2 control-label' form.element( 'label#no_table_email__label')['_class'] = 'col-sm-2 control-label' form.element('label#no_table_fiscalname__label' )['_class'] = 'col-sm-2 control-label' form.element('label#no_table_tax_identification__label' )['_class'] = 'col-sm-2 control-label' form.element('label#no_table_address__label' )['_class'] = 'col-sm-2 control-label' form.element( 'label#no_table_city__label')['_class'] = 'col-sm-2 control-label' form.element('label#no_table_province__label' )['_class'] = 'col-sm-2 control-label' form.element('label#no_table_country__label' )['_class'] = 'col-sm-2 control-label' form.element('label#no_table_postal_code__label' )['_class'] = 'col-sm-2 control-label' form.element( 'label#no_table_phone__label')['_class'] = 'col-sm-2 control-label' form.element('div#submit_record__row div.col-sm-9' )['_class'] = 'col-sm-9 col-sm-offset-2' return dict(form=form, userid=customer.auth_user.id)