ciclos

commit 5cd9678a9a528c5e09f3f6b12639629e4d59f3f7

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

Add price margin percentage to a cycle

 src/alembic/versions/1a8c88c6e1e4_add_margin_to_cycle.py | 28 ++++++++++
 src/blueprints/cycles.py | 3 
 src/templates/new_cycle.html | 15 +++-
 src/types/cycle.py | 5 +


diff --git a/src/alembic/versions/1a8c88c6e1e4_add_margin_to_cycle.py b/src/alembic/versions/1a8c88c6e1e4_add_margin_to_cycle.py
new file mode 100644
index 0000000000000000000000000000000000000000..3b446b60c8a93a94237ed67c7a1127f02efa4272
--- /dev/null
+++ b/src/alembic/versions/1a8c88c6e1e4_add_margin_to_cycle.py
@@ -0,0 +1,28 @@
+"""add margin to cycle
+
+Revision ID: 1a8c88c6e1e4
+Revises: b1a2b379ee3d
+Create Date: 2019-12-26 21:36:46.996515
+
+"""
+from alembic import op
+from alembic import op
+import sqlalchemy as sa
+from sqlalchemy import Column
+from sqlalchemy.types import DECIMAL
+
+# revision identifiers, used by Alembic.
+branch_labels = None
+revision = '1a8c88c6e1e4'
+down_revision = 'b1a2b379ee3d'
+depends_on = None
+
+
+def upgrade():
+    op.add_column('cycles',
+        Column('price_margin', DECIMAL(10, 2), nullable = False, default = 0)
+    )
+
+def downgrade():
+    op.drop_column('cycles', 'price_margin')
+import sqlalchemy as sa




diff --git a/src/blueprints/cycles.py b/src/blueprints/cycles.py
index f53f1c30ed28e9ae5e0b27680054399394bb0024..ad66828b70306c37239e5b8d0e73358a5abe1cde 100644
--- a/src/blueprints/cycles.py
+++ b/src/blueprints/cycles.py
@@ -47,7 +47,8 @@         start_at = start_at,
         end_at = end_at,
         delivery_start_at = params.get('delivery_start_at'),
         delivery_end_at = params.get('delivery_end_at'),
-        status = params.get('status')
+        status = params.get('status'),
+        price_margin = params.get('price_margin')
     )
 
     cycle.create()




diff --git a/src/templates/new_cycle.html b/src/templates/new_cycle.html
index 9eb448f63bdd868853f69748baf979e5066afc42..aa6522312473783a540b7c0889e239a11c8ad28d 100644
--- a/src/templates/new_cycle.html
+++ b/src/templates/new_cycle.html
@@ -12,21 +12,26 @@       
     </div>
     <div class="form-section">
       <label for="">Start At</label>
-      <input name="start_at" type="text">
+      <input name="start_at" type="text" />
     </div>
     <div class="form-section">
       <label for="">Ends At</label>
-      <input name="end_at" type="text">
+      <input name="end_at" type="text" />
     </div>
     <div class="form-section">
       <label for="">Delivery Start At</label>
-      <input name="delivery_start_at" type="text">
+      <input name="delivery_start_at" type="text" />
     </div>
     <div class="form-section">
       <label for="">Delivery Ends At</label>
-      <input name="delivery_end_at" type="text">
+      <input name="delivery_end_at" type="text" />
+    </div>
+  
+    <div class="form-section">
+      <label for="">Price Margin</label>
+      <input name="price_margin" type="text" />
     </div>
- 
+
     <div class="form-section">
       <label for="">Status</label>
       <select name="status">




diff --git a/src/types/cycle.py b/src/types/cycle.py
index 41fa195cd630b8f7c4acee30af56c3fcf67e9e8b..649b7e0977aa4df20704fc9cdfcbef8ae469be33 100644
--- a/src/types/cycle.py
+++ b/src/types/cycle.py
@@ -25,10 +25,12 @@     delivery_end_at = db.Column(db.DateTime, nullable = False)
 
     status = db.Column(sau.ChoiceType(CycleStatus, impl = sa.String()), server_default = 'draft')
 
+    price_margin = db.Column(db.Numeric(10, 2), nullable = False, default = 0.0)
+
     created_at = db.Column(db.DateTime, default = dt.utcnow)
     updated_at = db.Column(db.DateTime, default = dt.utcnow)
 
-    def __init__(self, name, description, start_at, end_at, delivery_start_at, delivery_end_at, status):
+    def __init__(self, name, description, start_at, end_at, delivery_start_at, delivery_end_at, status, price_margin):
         self.name = name
         self.description = description
         self.start_at = start_at
@@ -36,6 +38,7 @@         self.end_at = end_at
         self.delivery_start_at = delivery_start_at
         self.delivery_end_at = delivery_end_at
         self.status = status
+        self.price_margin = price_margin
 
     def create(self):
         db.session.add(self)