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 number
controllers/purchase_transaction.pyif '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.pydef __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/CGFkel06jcwthanks and best regards,
stifan