Hopefully fixed purchase return update journal.

This commit is contained in:
Tanshu 2013-05-18 12:42:38 +05:30
parent 9db47afb7a
commit 1a4a136058
1 changed files with 5 additions and 5 deletions

View File

@ -110,26 +110,26 @@ def purchase_return_update_journals(voucher, journals):
amount = 0
for item in voucher.inventories:
ledger = Product.by_id(item.product_id).ledger
amount += item.amount
amount += round(item.amount, 2)
if ledger.id in journals:
journals[ledger.id].amount += item.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=round(item.amount), 2)
journals[otherLedger.id] = Journal(debit=1, cost_center_id=otherLedger.costcenter_id, ledger_id=otherLedger.id,
amount=amount)
for i in range(len(voucher.journals), 0, -1):
item = voucher.journals[i - 1]
if item.ledger_id in journals:
item.debit = journals[item.ledger_id].debit
item.amount = round(journals[item.ledger_id].amount, 2)
item.amount = journals[item.ledger_id].amount
item.cost_center_id = journals[item.ledger_id].cost_center_id
del journals[item.ledger_id]
else:
DBSession.delete(item)
voucher.journals.remove(item)
for item in journals.values():
item.amount = round(item.amount, 2)
item.amount = item.amount
DBSession.add(item)
voucher.journals.append(item)