from flask_wtf import FlaskForm from wtforms import ( SubmitField, SelectField, HiddenField, StringField, PasswordField, IntegerField, FloatField, BooleanField, DateField, ) from wtforms.validators import InputRequired, Length, NumberRange from ...models import Customer class AddInvoice(FlaskForm): customer_id = SelectField("Customer", choices=[]) invoice_id_alt = StringField("Alternative invoice ID") customer_reference = StringField("Customer reference") date_billed = DateField('Date billed', format='%Y-%m-%d') date_due = DateField('Date due', format='%Y-%m-%d') amount_net = FloatField("Amount without tax", default=0) amount_gross = FloatField("Amount with tax", default=0) amount_tax = FloatField("Amount of tax", default=0) submit = SubmitField("Add Invoice") def __init__(self, **kwargs): super().__init__() self.customer_id.choices = [ (cus.primary_key, cus.name) for cus in Customer.query.all() ]