122 lines
4.0 KiB
Python
122 lines
4.0 KiB
Python
from pony import orm
|
|
import datetime
|
|
from hashlib import sha256
|
|
from datetime import datetime
|
|
|
|
db = orm.Database ()
|
|
key = "b9281aea-4a9e-4721-b932-5b5ffbc66cfe"
|
|
|
|
class User (db.Entity) :
|
|
|
|
username = orm.Required (str, unique = True)
|
|
password = orm.Required (str)
|
|
active = orm.Optional (bool)
|
|
last_logedin = orm.Optional (datetime)
|
|
created = orm.Optional (datetime)
|
|
actions = orm.Set ("Action")
|
|
orders = orm.Set ("Order")
|
|
|
|
def __init__ (self, username, password, active = True) :
|
|
pwd = f"{key}:{password}"
|
|
password = sha256 (pwd.encode ("utf-8")).hexdigest ()
|
|
super ().__init__ \
|
|
( username = username
|
|
, password = password
|
|
, active = active
|
|
, created = datetime.now ()
|
|
)
|
|
# end def __init__
|
|
|
|
def check_password (self, password) :
|
|
pwd = f"{key}:{password}"
|
|
password = sha256 (pwd.encode ("utf-8")).hexdigest ()
|
|
return self.password == password
|
|
# end def check_password
|
|
|
|
def change_password (self, password) :
|
|
pwd = f"{key}:{password}"
|
|
self.password = sha256 (pwd.encode ("utf-8")).hexdigest ()
|
|
# end def change_password
|
|
|
|
# end class User
|
|
|
|
class Production_Line (db.Entity) :
|
|
|
|
short = orm.Required (str)
|
|
name = orm.Required (str)
|
|
orders = orm.Set ("Order")
|
|
|
|
def __str__ (self) :
|
|
return f"{self.name} ({self.short})"
|
|
# end def __str__
|
|
|
|
# end class Production_Line
|
|
|
|
class Order (db.Entity) :
|
|
basket_no = orm.Required (str)
|
|
state = orm.Required (int)
|
|
commission = orm.Optional (str)
|
|
imos_user = orm.Required (str)
|
|
production_line = orm.Required (Production_Line)
|
|
user = orm.Optional (User)
|
|
active = orm.Optional (bool)
|
|
actions = orm.Set ("Action")
|
|
order_lines = orm.Set ("Order_Line")
|
|
# end class Order
|
|
|
|
class Action (db.Entity) :
|
|
user = orm.Required (User)
|
|
date = orm.Required (datetime)
|
|
action_kind = orm.Required (int)
|
|
action = orm.Optional (str)
|
|
order = orm.Optional (Order)
|
|
# end class Action
|
|
|
|
class Odoo_Article (db.Entity) :
|
|
name = orm.Required (str)
|
|
default_text = orm.Optional (str)
|
|
default_price = orm.Optional (float)
|
|
order_lines = orm.Set ("Order_Line")
|
|
# end class Odoo_Article
|
|
|
|
class Order_Line (db.Entity) :
|
|
order = orm.Required (Order)
|
|
position = orm.Required (str)
|
|
count = orm.Required (int)
|
|
text = orm.Required (str)
|
|
price = orm.Required (float)
|
|
odoo_article = orm.Required (Odoo_Article)
|
|
# end class Order_Line
|
|
|
|
class State (db.Entity) :
|
|
|
|
imos_factory_root = orm.Required (str)
|
|
imos_sim_root = orm.Required (str)
|
|
last_directory_scan = orm.Required (datetime)
|
|
|
|
def __str__ (self) :
|
|
return f"""
|
|
IMOS Facory root {self.imos_factory_root}
|
|
IMOS SIM toot {self.imos_sim_root}
|
|
Last scan {self.last_directory_scan}
|
|
""".strip ()
|
|
# end def __str__
|
|
|
|
# end class State
|
|
|
|
if __name__ == "__main__" :
|
|
import argparse
|
|
parser = argparse.ArgumentParser ()
|
|
parser.add_argument ("database", type = str)
|
|
parser.add_argument ("-d", "--sql-debug", action = "store_true")
|
|
cmd = parser.parse_args ()
|
|
orm.set_sql_debug (cmd.sql_debug)
|
|
db.bind (provider = "sqlite", filename = cmd.database, create_db = True)
|
|
db.generate_mapping (create_tables = True)
|
|
if False :
|
|
with orm.db_session :
|
|
u = User (username = "glueckm", password = "123")
|
|
if True :
|
|
with orm.db_session :
|
|
u = User.get (username = "glueckm")
|
|
print (u, u.check_password ("123")) |