diff --git a/brewman/brewman/views/services/voucher/purchase_return.py b/brewman/brewman/views/services/voucher/purchase_return.py index 0fd42e1e..9f234996 100644 --- a/brewman/brewman/views/services/voucher/purchase_return.py +++ b/brewman/brewman/views/services/voucher/purchase_return.py @@ -9,6 +9,7 @@ from brewman.models.voucher import Voucher, VoucherType, Batch, Inventory, Journ __author__ = 'tanshu' + def purchase_return_create_voucher(json, user): dt = datetime.datetime.strptime(json['Date'], '%d-%b-%Y') voucher = Voucher(date=dt, narration=json['Narration'], user_id=user.id, type=VoucherType.by_name(json['Type'])) @@ -37,7 +38,7 @@ def purchase_return_create_inventory(voucher, item): batch.quantity_remaining -= quantity item = Inventory(id=inventory_id, product_id=batch.product.id, quantity=quantity, rate=batch.rate, tax=batch.tax, - discount=batch.discount, batch=batch) + discount=batch.discount, batch=batch) DBSession.add(item) voucher.inventories.append(item) @@ -50,12 +51,12 @@ def purchase_return_create_journals(inventories, ledgerID): ledger = Product.by_id(item.product_id).ledger amount += round(item.amount, 2) if ledger.id in journals: - journals[ledger.id].amount += amount + journals[ledger.id].amount += round(item.amount, 2) else: journals[ledger.id] = Journal(debit=-1, cost_center_id=ledger.costcenter_id, ledger_id=ledger.id, - amount=item.amount) + amount=item.amount) journals[otherLedger.id] = Journal(debit=1, cost_center_id=otherLedger.costcenter_id, ledger_id=otherLedger.id, - amount=amount) + amount=amount) return list(journals.values()) @@ -88,8 +89,8 @@ def purchase_return_update_inventory(voucher, newInventories, date): if quantity == 0: raise ValidationError("Quantity of {0} cannot be zero".format(item.product.name)) if quantity - item.quantity > item.batch.quantity_remaining: - raise ValidationError("Maximum quantity available for {0} is {1}".format( item.product.full_name, - item.quantity + item.batch.quantity_remaining)) + raise ValidationError("Maximum quantity available for {0} is {1}".format(item.product.full_name, + item.quantity + item.batch.quantity_remaining)) item.batch.quantity_remaining -= (quantity - item.quantity) item.quantity = quantity newInventories.remove(i) @@ -114,9 +115,9 @@ def purchase_return_update_journals(voucher, journals): journals[ledger.id].amount += item.amount else: journals[ledger.id] = Journal(debit=-1, cost_center_id=ledger.costcenter_id, ledger_id=ledger.id, - amount=item.amount) + amount=item.amount) journals[otherLedger.id] = Journal(debit=1, cost_center_id=otherLedger.costcenter_id, ledger_id=otherLedger.id, - amount=amount) + amount=amount) for i in range(len(voucher.journals), 0, -1): item = voucher.journals[i - 1] if item.ledger_id in journals: