[accounts] [perpetual] get account and stock balance difference

This commit is contained in:
Nabin Hait 2013-08-02 11:44:29 +05:30
parent 1e2f20a3da
commit cac622e097
3 changed files with 41 additions and 4 deletions

View File

@ -17,7 +17,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import nowdate, cstr, flt, now from webnotes.utils import nowdate, nowtime, cstr, flt, now
from webnotes.model.doc import addchild from webnotes.model.doc import addchild
from webnotes import msgprint, _ from webnotes import msgprint, _
from webnotes.utils import formatdate from webnotes.utils import formatdate
@ -352,3 +352,41 @@ def fix_total_debit_credit():
where voucher_type = %s and voucher_no = %s and %s > 0 limit 1""" % where voucher_type = %s and voucher_no = %s and %s > 0 limit 1""" %
(dr_or_cr, dr_or_cr, '%s', '%s', '%s', dr_or_cr), (dr_or_cr, dr_or_cr, '%s', '%s', '%s', dr_or_cr),
(d.diff, d.voucher_type, d.voucher_no)) (d.diff, d.voucher_type, d.voucher_no))
def validate_stock_and_account_balance():
difference = get_stock_and_account_difference()
if difference:
msgprint(_("Account balance must be synced with stock balance, \
to enable perpetual accounting." +
_(" Following accounts are not synced with stock balance") + ": \n" +
"\n".join(difference.keys())), raise_exception=1)
def get_stock_and_account_difference(warehouse_list=None):
from stock.utils import get_latest_stock_balance
if not warehouse_list:
warehouse_list = webnotes.conn.sql_list("""select name from tabWarehouse
where docstatus<2""")
account_warehouse_map = {}
warehouse_with_no_account = []
difference = {}
warehouse_account = webnotes.conn.sql("""select name, account from tabWarehouse
where name in (%s)""" % ', '.join(['%s']*len(warehouse_list)), warehouse_list, as_dict=1)
for wh in warehouse_account:
if not wh.account: warehouse_with_no_account.append(wh.name)
account_warehouse_map.setdefault(wh.account, []).append(wh.name)
if warehouse_with_no_account:
msgprint(_("Please mention Perpetual Account in warehouse master for following warehouses")
+ ": " + '\n'.join(warehouse_with_no_account), raise_exception=1)
for account, warehouse in account_warehouse_map.items():
account_balance = get_balance_on(account)
stock_value = get_latest_stock_balance(warehouse)
difference.setdefault(account, (account_balance - stock_value))
return difference

View File

@ -394,7 +394,6 @@ class AccountsController(TransactionBase):
total_billed_amt = flt(flt(already_billed) + flt(item.fields[based_on]), total_billed_amt = flt(flt(already_billed) + flt(item.fields[based_on]),
self.precision(based_on, item)) self.precision(based_on, item))
webnotes.errprint([max_allowed_amt, total_billed_amt])
if max_allowed_amt and total_billed_amt - max_allowed_amt > 0.02: if max_allowed_amt and total_billed_amt - max_allowed_amt > 0.02:
webnotes.msgprint(_("Row ")+ cstr(item.idx) + ": " + cstr(item.item_code) + webnotes.msgprint(_("Row ")+ cstr(item.idx) + ": " + cstr(item.item_code) +

View File

@ -55,7 +55,7 @@ class DocType:
for d in rec: for d in rec:
rec_list += d[0] + ' - ' + d[1] + '\n' rec_list += d[0] + ' - ' + d[1] + '\n'
self.doc.receiver_list = rec_list self.doc.receiver_list = rec_list
webnotes.errprint(rec_list)
def get_receiver_nos(self): def get_receiver_nos(self):
receiver_nos = [] receiver_nos = []
for d in self.doc.receiver_list.split('\n'): for d in self.doc.receiver_list.split('\n'):