From 5972dd6b758e9e405712edcf0463e1d7fb3612a2 Mon Sep 17 00:00:00 2001 From: Tanshu Date: Fri, 21 Jun 2013 16:20:50 +0530 Subject: [PATCH] Updated batch to use a date instead of string as name. to update this step, also execute the following sql in the database. update entities_batches set "Name" = '01-Jan-2012' where "Name" = 'Old Products'; alter table entities_batches alter column "Name" type timestamp without time zone using "Name"::date; --- brewman/brewman/models/voucher.py | 4 ++-- brewman/brewman/views/services/batch.py | 3 +-- brewman/brewman/views/services/voucher/__init__.py | 2 +- brewman/brewman/views/services/voucher/purchase.py | 8 ++++---- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/brewman/brewman/models/voucher.py b/brewman/brewman/models/voucher.py index 7f8e99e3..3e94589a 100644 --- a/brewman/brewman/models/voucher.py +++ b/brewman/brewman/models/voucher.py @@ -218,7 +218,7 @@ class Batch(Base): __tablename__ = 'entities_batches' id = Column('BatchID', GUID(), primary_key=True, default=uuid.uuid4) - name = Column('Name', Unicode(255)) + name = Column('Date', DateTime) product_id = Column('ProductID', GUID(), ForeignKey('entities_products.ProductID')) quantity_remaining = Column('QuantityRemaining', Numeric) rate = Column('Rate', Numeric) @@ -246,7 +246,7 @@ class Batch(Base): query = query.filter(cls.quantity_remaining > 0) for item in name.split(): query = query.filter(Product.name.ilike('%' + item + '%')) - return query.order_by(Product.name).all() + return query.order_by(Product.name).order_by(cls.name).all() @classmethod diff --git a/brewman/brewman/views/services/batch.py b/brewman/brewman/views/services/batch.py index 1f9bd338..e5b87a91 100644 --- a/brewman/brewman/views/services/batch.py +++ b/brewman/brewman/views/services/batch.py @@ -11,8 +11,7 @@ def batch_term(request): list = [] for index, item in enumerate(Batch.list(filter, include_nil=False)): text = "{0} ({1}) {2:.2f}@{3:.2f} from {4}".format(item.product.name, item.product.units, - item.quantity_remaining, - item.rate, item.name) + item.quantity_remaining, item.rate, item.name.strftime('%d-%b-%Y')) list.append({'BatchID': item.id, 'Name': text, 'QuantityRemaining': item.quantity_remaining, 'Rate': item.rate, 'Tax': item.tax, 'Discount': item.discount, 'Product': {'ProductID': item.product.id, 'Name': item.product.name, 'Units': item.product.units}}) diff --git a/brewman/brewman/views/services/voucher/__init__.py b/brewman/brewman/views/services/voucher/__init__.py index 64c2b490..6f2667a9 100644 --- a/brewman/brewman/views/services/voucher/__init__.py +++ b/brewman/brewman/views/services/voucher/__init__.py @@ -169,7 +169,7 @@ def voucher_info(voucher): 'Tax': item.tax, 'Discount': item.discount, 'Amount': item.amount, 'Product': {'ProductID': item.product.id, 'Name': item.product.full_name, 'Units': item.product.units, 'Price': item.rate}, - 'Batch': {'BatchID': item.batch.id, 'Name': item.batch.name, 'QuantityRemaining': item.batch.quantity_remaining}}) + 'Batch': {'BatchID': item.batch.id, 'Name': item.batch.name.strftime('%d-%b-%Y'), 'QuantityRemaining': item.batch.quantity_remaining}}) return json_voucher diff --git a/brewman/brewman/views/services/voucher/purchase.py b/brewman/brewman/views/services/voucher/purchase.py index 2ca71270..b7f130eb 100644 --- a/brewman/brewman/views/services/voucher/purchase.py +++ b/brewman/brewman/views/services/voucher/purchase.py @@ -16,7 +16,7 @@ def purchase_create_voucher(json, user): DBSession.add(voucher) for item in json['Inventories']: - purchase_create_inventory(voucher, item, json['Date']) + purchase_create_inventory(voucher, item, dt) for item in purchase_create_journals(voucher.inventories, json['Journals'][0]['Ledger']['LedgerID']): DBSession.add(item) voucher.journals.append(item) @@ -72,14 +72,14 @@ def purchase_update_voucher(voucher, json, user): voucher.posted = False voucher.last_edit_date = datetime.datetime.utcnow() - purchase_update_inventory(voucher, json['Inventories'], json['Date']) + purchase_update_inventory(voucher, json['Inventories']) purchase_update_journals(voucher, json['Journals']) journals_valid(voucher) inventory_valid(voucher) return voucher -def purchase_update_inventory(voucher, newInventories, date): +def purchase_update_inventory(voucher, newInventories): for it in range(len(voucher.inventories), 0, -1): item = voucher.inventories[it - 1] found = False @@ -129,7 +129,7 @@ def purchase_update_inventory(voucher, newInventories, date): rate = round(Decimal(i['Rate']), 2) tax = round(Decimal(i['Tax']), 5) discount = round(Decimal(i['Discount']), 5) - batch = Batch(name=date, product_id=product.id, quantity_remaining=new_quantity, rate=rate, tax=tax, + batch = Batch(name=voucher.date, product_id=product.id, quantity_remaining=new_quantity, rate=rate, tax=tax, discount=discount) inventory = Inventory(id=None, product_id=product.id, batch=batch, quantity=new_quantity, rate=rate, tax=tax, discount=discount)