Skip to content

Commit

Permalink
Add sticky prices for items
Browse files Browse the repository at this point in the history
Closes #261.
  • Loading branch information
ppannuto committed May 1, 2016
1 parent 63dad51 commit e41cb22
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
3 changes: 3 additions & 0 deletions chezbetty/migrations/migration_1.14.1-1.15.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE items ADD COLUMN sticky_price BOOLEAN DEFAULT FALSE;
ALTER TABLE items_history ADD COLUMN sticky_price BOOLEAN DEFAULT FALSE;

23 changes: 12 additions & 11 deletions chezbetty/models/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ def __str__(self):
class Item(Versioned, Base):
__tablename__ = 'items'

id = Column(Integer, primary_key=True, nullable=False)
name = Column(String(255), nullable=False, unique=True)
barcode = Column(String(255), nullable=True, unique=True)
price = Column(Numeric, nullable=False)
wholesale = Column(Numeric, nullable=False)
bottle_dep = Column(Boolean, nullable=False, default=False)
sales_tax = Column(Boolean, nullable=False, default=False)
in_stock = Column(Integer, nullable=False, default=0)
img = relationship(ItemImage, uselist=False, backref="item")

enabled = Column(Boolean, default=True, nullable=False)
id = Column(Integer, primary_key=True, nullable=False)
name = Column(String(255), nullable=False, unique=True)
barcode = Column(String(255), nullable=True, unique=True)
price = Column(Numeric, nullable=False)
sticky_price = Column(Boolean, default=False)
wholesale = Column(Numeric, nullable=False)
bottle_dep = Column(Boolean, nullable=False, default=False)
sales_tax = Column(Boolean, nullable=False, default=False)
in_stock = Column(Integer, nullable=False, default=0)
img = relationship(ItemImage, uselist=False, backref="item")

enabled = Column(Boolean, default=True, nullable=False)

def __init__(self, name, barcode, price, wholesale, bottle_dep, sales_tax,
in_stock, enabled):
Expand Down
4 changes: 4 additions & 0 deletions chezbetty/templates/admin/item_edit.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<dt>Price</dt>
<dd><input type="text" class="form-control numeric" id="item-price" name="item-price" value="{{ item.price|round(2) }}"></dd>

<dt>Sticky Price</dt>
<input type="hidden" name="item-sticky_price" value="off">
<dd><input type="checkbox" id="item-sticky_price" name="item-sticky_price" {% if item.sticky_price == True %}checked="checked"{% endif %}></input></dd>

<dt>Wholesale</dt>
<dd><input type="text" class="form-control numeric" id="item-wholesale" name="item-wholesale" value="{{ item.wholesale|round(4) }}"></dd>

Expand Down
3 changes: 2 additions & 1 deletion chezbetty/views_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,8 @@ def add_item(item, quantity, total):
continue
item.wholesale = round((total/quantity) + global_cost_item_addition, 4)
# Set the item price
item.price = round(item.wholesale * Decimal('1.15'), 2)
if not item.sticky_price:
item.price = round(item.wholesale * Decimal('1.15'), 2)

if len(items) == 0:
request.session.flash('Have to restock at least one item.', 'error')
Expand Down

0 comments on commit e41cb22

Please sign in to comment.