ciclos

commit b4b5bcaa4602a36e60fe8fa6f7372f434d160cc3

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

Create Balance model

 src/types/balance.py | 25 +++++++++++++++++++++++++


diff --git a/src/types/balance.py b/src/types/balance.py
new file mode 100644
index 0000000000000000000000000000000000000000..b6fae1c590b49fed1c279b771ec7ffe787d912b1
--- /dev/null
+++ b/src/types/balance.py
@@ -0,0 +1,25 @@
+from . import db
+from datetime import datetime as dt
+
+class Balance(db.Model):
+    __tablename__ = "balances"
+    id = db.Column(db.Integer, primary_key = True)
+    value = db.Column(db.Numeric(10, 2), nullable = False)
+    product_id = db.Column(db.Integer, db.ForeignKey('products.id'), nullable = False)
+
+    created_at = db.Column(db.DateTime, default = dt.utcnow)
+    updated_at = db.Column(db.DateTime, default = dt.utcnow)
+
+    def __init__(self, value, product_id):
+        self.value = value
+        self.product_id = product_id
+
+    def create(self):
+        db.session.add(self)
+        db.session.commit()
+
+    def to_json(self):
+        return {
+            "value": self.value,
+            "updated_at": self.updated_at.__str__()
+        }