From 3f5475f7439a035520909bbf9b0fac9b571d2a17 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 10 Feb 2021 17:43:07 +0100 Subject: [PATCH] [Plugin] orders: Testing with some stuff --- flaschengeist/plugins/orders/__init__.py | 21 ++++++++++ flaschengeist/plugins/orders/models.py | 49 ++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 flaschengeist/plugins/orders/__init__.py create mode 100644 flaschengeist/plugins/orders/models.py diff --git a/flaschengeist/plugins/orders/__init__.py b/flaschengeist/plugins/orders/__init__.py new file mode 100644 index 0000000..d3b3f46 --- /dev/null +++ b/flaschengeist/plugins/orders/__init__.py @@ -0,0 +1,21 @@ +"""Orders plugin""" + +from flask import Blueprint + +from flaschengeist.plugins import Plugin + +from . import models + +order_bp = Blueprint("orders", __name__) + + +class OrdersPlugin(Plugin): + models = models + + def __init__(self, config): + super().__init__(blueprint=order_bp) + + def install(self): + from flaschengeist.database import db + + db.create_all() diff --git a/flaschengeist/plugins/orders/models.py b/flaschengeist/plugins/orders/models.py new file mode 100644 index 0000000..cb48440 --- /dev/null +++ b/flaschengeist/plugins/orders/models.py @@ -0,0 +1,49 @@ +import datetime +from sqlalchemy.orm import relationship + +from flaschengeist.models import ModelSerializeMixin, UtcDateTime +from flaschengeist.database import db + + +class Product(db.Model, ModelSerializeMixin): + __tablename__ = "orders_product" + id: int = db.Column(db.Integer, primary_key=True) + name: str = db.Column(db.String(255)) + price: float = db.Column(db.Numeric(precision=19, scale=3, asdecimal=False)) + + tax_rate: float = db.Column(db.Float) + + +class Bill(db.Model, ModelSerializeMixin): + __tablename__ = "orders_bill" + id: int = db.Column(db.Integer, primary_key=True) + time: datetime.datetime = db.Column(UtcDateTime, nullable=False) + payment = ... + payed = db.Column(db.Boolean) + cancelled = db.Column(db.Integer, db.ForeignKey("orders_bill.id")) # Cancelled by + + orders = relationship("Order", back_populates="bill") + + +class Order(db.Model): + __tablename__ = "orders_order" + id: int = db.Column(db.Integer, primary_key=True) + bill = ... + product = ... + amount = ... + price = ... + tax_rate = ... + discount = ... + + userid: str = "" + value: float = db.Column(db.Numeric(precision=3, scale=2, asdecimal=False), nullable=False) + + _job_id = db.Column("job_id", db.Integer, db.ForeignKey("schedule_job.id"), nullable=False, primary_key=True) + _user_id = db.Column("user_id", db.Integer, db.ForeignKey("user.id"), nullable=False, primary_key=True) + + user_: User = db.relationship("User") + job_ = db.relationship("Job") + + @property + def userid(self): + return self.user_.userid