1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
# -*- mode: python; -*-
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
from flask_login import UserMixin
from . import db
def date_time_now():
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
class User(UserMixin, db.Model):
__tablename__ = "User"
def get_id(self):
return self.primary_key
primary_key = db.Column("UserId", db.Integer, primary_key=True)
username = db.Column("Username", db.String(20), nullable=False)
hashed_password = db.Column("HashedPassword", db.String(100), nullable=False)
name_first = db.Column("NameFirst", db.String(20), nullable=False)
name_last = db.Column("NameLast", db.String(20), nullable=False)
email = db.Column("Email", db.String(20), nullable=False)
phone_mobile = db.Column("PhoneMobile", db.Integer)
phone_alternative = db.Column("PhoneAlternative", db.Integer)
date_time_created = db.Column(
"DateTimeCreated", db.String, server_default=date_time_now()
)
date_time_updated = db.Column(
"DateTimeUpdated", db.String, server_onupdate=date_time_now()
)
def __repr__(self):
return f"<User {self.name_first} {self.name_last}>"
class Module(db.Model):
__tablename__ = "Module"
name = db.Column(
"Name", db.String(20), unique=True, nullable=False, primary_key=True
)
description = db.Column("Description", db.String(50), nullable=False)
def __repr__(self):
return f"<Module {self.name}>"
class Customer(db.Model):
__tablename__ = "Customer"
primary_key = db.Column("CustomerId", db.Integer, nullable=False, primary_key=True)
name = db.Column("Name", db.String(20), nullable=False)
name_alternative = db.Column("NameAlternative", db.String(20))
code_customer = db.Column("CodeCustomer", db.String(20), unique=True)
code_accounting = db.Column("CodeAccounting", db.String(20), unique=True)
address = db.Column("Address", db.String(20))
postal_code = db.Column("PostalCode", db.Integer)
city = db.Column("City", db.String(20))
country = db.Column("Country", db.String(20))
phone = db.Column("Phone", db.String(20))
website = db.Column("Website", db.String(20))
email = db.Column("Email", db.String(20))
professional_id_1 = db.Column("ProfessionalId1", db.String(20), unique=True)
professional_id_2 = db.Column("ProfessionalId2", db.String(20), unique=True)
tax_id = db.Column("TaxId", db.String(20), unique=True)
payment_terms = db.Column("PaymentTerms", db.String(20), unique=True)
date_time_created = db.Column("DateTimeCreated", db.String(20), nullable=False)
date_time_updated = db.Column("DateTimeUpdated", db.String(20), nullable=False)
invoices = db.relationship("Invoice", back_populates="customer")
def __init__(
self,
name,
name_alternative,
code_customer,
code_accounting,
address,
postal_code,
city,
country,
phone,
website,
email,
professional_id_1,
professional_id_2,
tax_id,
payment_terms,
):
self.name = name
self.name_alternative = name_alternative
self.code_customer = code_customer
self.code_accounting = code_accounting
self.address = address
self.postal_code = postal_code
self.city = city
self.country = country
self.phone = phone
self.website = website
self.email = email
self.professional_id_1 = professional_id_1
self.professional_id_2 = professional_id_2
self.tax_id = tax_id
self.payment_terms = payment_terms
def __repr__(self):
return f"<Customer {self.name}>"
class Invoice(db.Model):
__tablename__ = "Invoice"
primary_key = db.Column("InvoiceId", db.Integer, primary_key=True)
invoice_id_alt = db.Column("InvoiceIdAlt", db.String)
customer_reference = db.Column("CustomerReference", db.String)
date_billed = db.Column("DateBilled", db.String)
date_due = db.Column("DateDue", db.String)
amount_net = db.Column("AmountNet", db.String)
amount_gross = db.Column("AmountGross", db.String)
amount_tax = db.Column("AmountTax", db.String)
date_time_created = db.Column(
"DateTimeCreated", db.String, default=date_time_now()
)
customer_id = db.Column(
"CustomerId", db.Integer, db.ForeignKey("Customer.CustomerId")
)
customer = db.relationship("Customer", back_populates="invoices")
def __init__(
self,
invoice_id_alt,
customer_id,
customer_reference,
date_billed,
date_due,
amount_net,
amount_gross,
amount_tax,
):
self.invoice_id_alt = invoice_id_alt
self.customer_id = customer_id
self.customer_reference = customer_reference
self.date_billed = date_billed
self.date_due = date_due
self.amount_net = amount_net
self.amount_gross = amount_gross
self.amount_tax = amount_tax
def __repr__(self):
return f"<Invoice for {self.customer.name} at {self.updated}>"
class Product(db.Model):
__tablename__ = "Product"
primary_key = db.Column("ProductId", db.Integer, primary_key=True)
name = db.Column("Name", db.String(20), nullable=False, unique=True)
code_accounting = db.Column("CodeAccounting", db.String(20))
unit_weight = db.Column("UnitWeight", db.Float)
price_net = db.Column("PriceNet", db.Float)
price_gross = db.Column("PriceGross", db.Float)
tax_rate = db.Column("TaxRate", db.Float)
date_time_created = db.Column(
"DateTimeCreated", db.String, server_default=date_time_now()
)
date_time_updated = db.Column(
"DateTimeUpdated", db.String, server_onupdate=date_time_now()
)
def __init__(
self,
name,
code_accounting,
unit_weight,
price_net,
price_gross,
tax_rate,
):
self.name = name
self.code_accounting = code_accounting
self.unit_weight = unit_weight
self.price_net = price_net
self.price_gross = price_gross
self.tax_rate = tax_rate
def __repr__(self):
return f"<Product {self.name}>"
class FertiLog(db.Model):
__tablename__ = "Fertilog"
primary_key = db.Column("FertiLogId", db.Integer, primary_key=True)
nno3 = db.Column("NNO3", db.Float, default=0)
p = db.Column("P", db.Float, default=0)
k = db.Column("K", db.Float, default=0)
ca = db.Column("Ca", db.Float, default=0)
mg = db.Column("Mg", db.Float, default=0)
s = db.Column("S", db.Float, default=0)
na = db.Column("Na", db.Float, default=0)
cl = db.Column("Cl", db.Float, default=0)
fe = db.Column("Fe", db.Float, default=0)
zn = db.Column("Zn", db.Float, default=0)
b = db.Column("B", db.Float, default=0)
mn = db.Column("Mn", db.Float, default=0)
cu = db.Column("Cu", db.Float, default=0)
mo = db.Column("Mo", db.Float, default=0)
si = db.Column("Si", db.Float, default=0)
nnh4 = db.Column("NNH4", db.Float, default=0)
date_time_created = db.Column(
"DateTimeCreated", db.String, server_default=date_time_now()
)
date_time_updated = db.Column(
"DateTimeUpdated", db.String, server_onupdate=date_time_now()
)
def __init__(self, nno3, p, k, ca, mg, s, na, cl, fe, zn, b, mn, cu, mo, si, nnh4):
self.nno3 = nno3
self.p = p
self.k = k
self.ca = ca
self.mg = mg
self.s = s
self.na = na
self.cl = cl
self.fe = fe
self.zn = zn
self.b = b
self.mn = mn
self.cu = cu
self.mo = mo
self.si = si
self.nnh4 = nnh4
self.date_time_created = date_time_now
def __repr__(self):
return f"<Log ID {self.primary_key}>"
class FertiTarget(FertiLog):
__tablename__ = "Fertitarget"
primary_key = db.Column("FertiTargetId", db.Integer, primary_key=True)
targeted_log = db.Column(
"FertiLogId", db.Integer, db.ForeignKey("Fertilog.FertiLogId")
)
def __repr__(self):
return f"<Target ID {self.primary_key}>"
# Everything after here is garbage
class Order(db.Model): # TODO
id = db.Column(db.Integer, primary_key=True)
date = db.Column(db.String(20), nullable=False)
customer = db.Column(db.String(20), nullable=False)
content = db.Column(db.String(10), nullable=False)
updated = db.Column(db.String)
def __repr__(self):
return f"<Order {self.name} at {self.updated}>"
|