From e41cb22f006d90930600e017709589c21d8da8e7 Mon Sep 17 00:00:00 2001 From: Pat Pannuto Date: Sun, 1 May 2016 13:54:43 -0400 Subject: [PATCH] Add sticky prices for items Closes #261. --- .../migrations/migration_1.14.1-1.15.0.sql | 3 +++ chezbetty/models/item.py | 23 ++++++++++--------- chezbetty/templates/admin/item_edit.jinja2 | 4 ++++ chezbetty/views_admin.py | 3 ++- 4 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 chezbetty/migrations/migration_1.14.1-1.15.0.sql diff --git a/chezbetty/migrations/migration_1.14.1-1.15.0.sql b/chezbetty/migrations/migration_1.14.1-1.15.0.sql new file mode 100644 index 0000000..83eec6b --- /dev/null +++ b/chezbetty/migrations/migration_1.14.1-1.15.0.sql @@ -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; + diff --git a/chezbetty/models/item.py b/chezbetty/models/item.py index 7dd9e40..be1c285 100644 --- a/chezbetty/models/item.py +++ b/chezbetty/models/item.py @@ -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): diff --git a/chezbetty/templates/admin/item_edit.jinja2 b/chezbetty/templates/admin/item_edit.jinja2 index 4d230ba..37149d0 100644 --- a/chezbetty/templates/admin/item_edit.jinja2 +++ b/chezbetty/templates/admin/item_edit.jinja2 @@ -29,6 +29,10 @@
Price
+
Sticky Price
+ +
+
Wholesale
diff --git a/chezbetty/views_admin.py b/chezbetty/views_admin.py index a383ee0..0b279dd 100644 --- a/chezbetty/views_admin.py +++ b/chezbetty/views_admin.py @@ -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')