hi, what is the best approach to have auto generate document number or codification (e.g. product code) using web2py? what i've done right now is something like :
*document numbercontrollers/purchase_transaction.py* if 'purchase_order' in request.function : # purchase_order_header id_max_purchase_order_header = db.purchase_order_header.id.max() maxID_purchase_order_header = db(db.purchase_order_header).select(id_max_purchase_order_header).first()[id_max_purchase_order_header] purchase_order_no_id = int(maxID_purchase_order_header) + 1 if maxID_purchase_order_header else 1 supplier_for_purchase_order_no = str(request.vars.supplier) purchase_order_no = str(purchase_order_no_id)+'/PO/'+request.now.strftime('%y%m%d')+'/'+supplier_for_purchase_order_no db.purchase_order_header.purchase_order_no.default = purchase_order_no # purchase_order_detail db.purchase_order_detail.purchase_order_no.default = purchase_order_no_id *codification (e.g. product code)controllers/master.py* def __onvalidation_product(form): row = db(db.model.id == form.vars.model).select().first() form.vars.brand = row.brand count_product_brand = db(db.product.brand == row.brand).count() next_product_count = int(count_product_brand) + 1 if count_product_brand else 1 product_no = str(row.brand.code)+str(next_product_count) db.product.product_no.default = product_no but anthony mention in another discussion that this kind of approach is not the best approach, any idea or suggestion what is the best approach to handle this kind of situation? *discussion ref:* https://groups.google.com/forum/#!topic/web2py/CGFkel06jcw thanks and 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.