# coding:utf8
from flask.ext.wtf import Form
from wtforms import StringField,SubmitField,DecimalField,SelectField
from wtforms.validators import Required
from . import models

class SupplierForm(Form):
	name=StringField(u'名称',validators=[Required()])
	contact=StringField(u'联系人',validators=[Required()])
	tel=StringField(u'电话',validators=[Required()])
	submit=SubmitField(u'提交')

class ProductForm(Form):
	name=StringField(u'品名',validators=[Required()])
	in_price=DecimalField(u'进价',validators=[Required()])
	spec=StringField(u'规格',validators=[Required()])
	supplier=SelectField(u'供应商',coerce=int,validators=[Required()])
	piece=StringField(u'计价单位',validators=[Required()])
	backup=StringField(u'备注',validators=[])
	submit=SubmitField(u'提交')

	def __init__(self,*args,**kwargs):
		super(ProductForm,self).__init__(*args,**kwargs)
		self.supplier.choices=[(supplier.id,supplier.name) for supplier in models.Supplier.query.all()]
		self.piece.choices=[(x,x) for x in ['件','袋','斤','公斤','克','两','罐','扎','饼','沱','盒']]
