ciclos

commit 3179846d135a32e288aeed35f64c2b2c7c5d4d25

Author: Pedro Lucas Porcellis <pedrolucasporcellis@gmail.com>

Rig the orders and cycles with the user

 core/app.py | 4 ++++
 core/types/__init__.py | 3 +++
 core/types/user.py | 8 ++++++++


diff --git a/core/app.py b/core/app.py
index 50253f4d3c3149962f029b181a812e9370ee8683..35e2afab601f35e7a96e36821d9c91a9a4f784ba 100644
--- a/core/app.py
+++ b/core/app.py
@@ -33,12 +33,16 @@ from core.blueprints.auth import auth
 from core.blueprints.groups import groups
 from core.blueprints.product_categories import product_categories
 from core.blueprints.products import pro as products
+from core.blueprints.cycles import cycles
+from core.blueprints.orders import orders
 
 app.register_blueprint(basic)
 app.register_blueprint(auth)
 app.register_blueprint(groups)
 app.register_blueprint(product_categories)
 app.register_blueprint(products)
+app.register_blueprint(cycles)
+app.register_blueprint(orders)
 
 @app.errorhandler(404)
 def handle_404(e):




diff --git a/core/types/__init__.py b/core/types/__init__.py
index 266672d1c6034802b9b596219502e244913b5c12..3c4df11cca7c07970ec337a50a4decbfbba1d68b 100644
--- a/core/types/__init__.py
+++ b/core/types/__init__.py
@@ -3,3 +3,6 @@ from . import product
 from . import product_category
 from . import group
 from . import balance
+from . import order
+from . import order_product
+from . import cycle




diff --git a/core/types/user.py b/core/types/user.py
index 045f142f612173e8f098ef42fe341147d05cfeff..0caba194a478f1f422a55ffe8712af8e1d787b52 100644
--- a/core/types/user.py
+++ b/core/types/user.py
@@ -2,6 +2,8 @@ from sqlalchemy import Column, Integer, String, Unicode, Boolean, DateTime
 from sqlalchemy import ForeignKey, Table, Text, text
 from sqlalchemy.orm import relationship, backref
 from core.database import Base
+from core.types.order import Order
+from core.types.cycle import Cycle, CycleStatus
 
 class User(Base):
     __tablename__ = 'users'
@@ -13,6 +15,8 @@     first_name = Column(String(250), nullable=False)
     last_name = Column(String(250))
     created_at = Column(DateTime, nullable=False)
     updated_at = Column(DateTime, nullable=False)
+
+    orders = relationship("Order", backref="user", lazy=True)
 
     def __init__(self, email, password, username, first_name, last_name):
         self.email = email
@@ -24,6 +28,10 @@
     def is_admin(self):
         # TODO: Move this to a field on the database
         return self.email in ["porcellis@eletrotupi.com"]
+
+
+    def current_order(self):
+        return Order.query.join(User).join(Cycle).filter(User.id == self.id, Cycle.status == CycleStatus.published).first()
 
 
     # Flask.Login stuff