summaryrefslogtreecommitdiff
path: root/app/modules
diff options
context:
space:
mode:
Diffstat (limited to 'app/modules')
-rw-r--r--app/modules/common.py4
-rw-r--r--app/modules/ferti/forms.py21
-rw-r--r--app/modules/ferti/routes.py7
-rw-r--r--app/modules/forms.py19
-rw-r--r--app/modules/invoices/forms.py10
-rw-r--r--app/modules/invoices/routes.py4
-rw-r--r--app/modules/orders/routes.py7
7 files changed, 44 insertions, 28 deletions
diff --git a/app/modules/common.py b/app/modules/common.py
index f9ccba6..ff0aec7 100644
--- a/app/modules/common.py
+++ b/app/modules/common.py
@@ -25,8 +25,8 @@ def add_item(module, table):
if form.validate_on_submit():
model = getattr(models, table)
table_fields = inspect.signature(model).parameters
- form_values = {key: request.form[key] for key in table_fields}
- print(f"Ready to insert {form_values}")
+ form_values = {key: request.form.get(key) for key in table_fields}
+ print(f"Ready to insert in {table} from {module} {form_values}")
record = model(**form_values)
db.session.add(record)
db.session.commit()
diff --git a/app/modules/ferti/forms.py b/app/modules/ferti/forms.py
index d926931..1e25ec3 100644
--- a/app/modules/ferti/forms.py
+++ b/app/modules/ferti/forms.py
@@ -12,13 +12,10 @@ from wtforms import (
)
from wtforms.validators import InputRequired, Length, NumberRange
+from ...models import FertiLog
+
class AddFertiLog(FlaskForm):
- target = SelectField(
- "Type",
- choices=[("False", "Log"), ("True", "Target")],
- validators=[InputRequired()],
- )
nno3 = FloatField("NNO3", default=0)
p = FloatField("P", default=0)
k = FloatField("K", default=0)
@@ -39,9 +36,15 @@ class AddFertiLog(FlaskForm):
class AddFertiTarget(AddFertiLog):
- targeted_log = SelectField(
- "Log to target",
- choices=[("value1", "Last"), ("value2", "Named")],
+ target_id = SelectField(
+ "Target log",
+ choices=[],
validators=[InputRequired()],
)
- submit = SubmitField("Add/Update Log")
+ submit = SubmitField("Add target")
+
+ def __init__(self, **kwargs):
+ super().__init__()
+ self.target_id.choices = [
+ (target.primary_key, target.date_time_created) for target in FertiLog.query.all()
+ ]
diff --git a/app/modules/ferti/routes.py b/app/modules/ferti/routes.py
index b3bb03f..c0f3ab5 100644
--- a/app/modules/ferti/routes.py
+++ b/app/modules/ferti/routes.py
@@ -21,7 +21,7 @@ import inspect
-from ... import db
+# from ... import db
from ...models import *
from .forms import *
@@ -34,11 +34,10 @@ ferti = Blueprint("ferti", __name__)
@login_required
def view():
modules = Module.query.all()
- logs = Fertilog.query.order_by(Fertilog.primary_key.desc()).all()
- targets = Fertitarget.query.all()
+ logs = FertiLog.query.order_by(FertiLog.primary_key.desc()).all()
+ targets = FertiTarget.query.all()
module = "ferti"
flash(f"Latest target is {targets}.", "info")
- flash(f"Still fighting against styling in {module}.", "error")
return render_template(
f"modules/{module}.html",
modules=modules,
diff --git a/app/modules/forms.py b/app/modules/forms.py
index 7e4acde..001557a 100644
--- a/app/modules/forms.py
+++ b/app/modules/forms.py
@@ -9,3 +9,22 @@ from .customers.forms import AddCustomer
from .ferti.forms import AddFertiLog, AddFertiTarget
from .invoices.forms import AddInvoice
from .products.forms import AddProduct
+
+
+# class AddUser(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()
+# ]
+
diff --git a/app/modules/invoices/forms.py b/app/modules/invoices/forms.py
index 74df40e..7e2bc50 100644
--- a/app/modules/invoices/forms.py
+++ b/app/modules/invoices/forms.py
@@ -8,7 +8,7 @@ from wtforms import (
IntegerField,
FloatField,
BooleanField,
- DateTimeField,
+ DateField,
)
from wtforms.validators import InputRequired, Length, NumberRange
@@ -19,14 +19,14 @@ class AddInvoice(FlaskForm):
customer_id = SelectField("Customer", choices=[])
invoice_id_alt = StringField("Alternative invoice ID")
customer_reference = StringField("Customer reference")
- date_billed = StringField("Date billed")
- date_due = StringField("Date due")
+ 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 new Invoice")
+ submit = SubmitField("Add Invoice")
- def __init__(self):
+ def __init__(self, **kwargs):
super().__init__()
self.customer_id.choices = [
(cus.primary_key, cus.name) for cus in Customer.query.all()
diff --git a/app/modules/invoices/routes.py b/app/modules/invoices/routes.py
index b8a0a68..b6a4fd9 100644
--- a/app/modules/invoices/routes.py
+++ b/app/modules/invoices/routes.py
@@ -15,7 +15,7 @@ from flask import (
from flask_login import login_required, current_user
-from ... import db
+# from ... import db
from ...models import *
from .forms import *
@@ -31,8 +31,6 @@ def view():
page = request.args.get('page', 1, type=int)
invoices = Invoice.query.order_by(Invoice.primary_key.desc()).paginate(page=page, per_page=5)
module = "invoices"
- flash(f"Successfully accessed module {module}.", "info")
- flash(f"Still fighting against styling in {module}.", "error")
return render_template(
f"modules/{module}.html",
modules=modules,
diff --git a/app/modules/orders/routes.py b/app/modules/orders/routes.py
index 0d2e66a..cf4e70a 100644
--- a/app/modules/orders/routes.py
+++ b/app/modules/orders/routes.py
@@ -15,13 +15,9 @@ from flask import (
from flask_login import login_required, current_user
-# from datetime import datetime
-import inspect
-
-from ... import db
-from ...models import Module, Order
+from ...models import db, Module, Order, Invoice
from .forms import *
@@ -34,6 +30,7 @@ def view():
modules = Module.query.all()
page = request.args.get('page', 1, type=int)
orders = Order.query.order_by(Order.primary_key.desc()).paginate(page=page, per_page=5)
+ invoices = Invoice.query.order_by(Invoice.primary_key.desc()).paginate(page=page, per_page=5)
module = "orders"
flash(f"Successfully accessed module {module}.", "info")
flash(f"Still fighting against styling in {module}.", "error")
Copyright 2019--2024 Marius PETER