[minor] fixed conflict while merging perpetual branch into master

This commit is contained in:
Nabin Hait
2013-09-24 14:36:55 +05:30
107 changed files with 2671 additions and 2122 deletions

View File

@@ -5,17 +5,35 @@ from __future__ import unicode_literals
import webnotes
from webnotes.utils import flt, cstr, now
from webnotes.model.doc import Document
from webnotes import msgprint, _
from accounts.utils import validate_expense_against_budget
class StockAccountInvalidTransaction(webnotes.ValidationError): pass
def make_gl_entries(gl_map, cancel=False, adv_adj=False, merge_entries=True,
update_outstanding='Yes'):
if gl_map:
if not cancel:
gl_map = process_gl_map(gl_map, merge_entries)
save_entries(gl_map, adv_adj, update_outstanding)
else:
delete_gl_entries(gl_map, adv_adj=adv_adj, update_outstanding=update_outstanding)
def process_gl_map(gl_map, merge_entries=True):
if merge_entries:
gl_map = merge_similar_entries(gl_map)
if cancel:
set_as_cancel(gl_map[0]["voucher_type"], gl_map[0]["voucher_no"])
for entry in gl_map:
# round off upto 2 decimal
entry.debit = flt(entry.debit, 2)
entry.credit = flt(entry.credit, 2)
# toggle debit, credit if negative entry
if flt(entry.debit) < 0 or flt(entry.credit) < 0:
entry.debit, entry.credit = abs(flt(entry.credit)), abs(flt(entry.debit))
check_budget(gl_map, cancel)
save_entries(gl_map, cancel, adv_adj, update_outstanding)
return gl_map
def merge_similar_entries(gl_map):
merged_gl_map = []
@@ -24,79 +42,86 @@ def merge_similar_entries(gl_map):
# to that entry
same_head = check_if_in_list(entry, merged_gl_map)
if same_head:
same_head['debit'] = flt(same_head['debit']) + flt(entry['debit'])
same_head['credit'] = flt(same_head['credit']) + flt(entry['credit'])
same_head.debit = flt(same_head.debit) + flt(entry.debit)
same_head.credit = flt(same_head.credit) + flt(entry.credit)
else:
merged_gl_map.append(entry)
# filter zero debit and credit entries
merged_gl_map = filter(lambda x: flt(x.debit)!=0 or flt(x.credit)!=0, merged_gl_map)
return merged_gl_map
def check_if_in_list(gle, gl_mqp):
for e in gl_mqp:
if e['account'] == gle['account'] and \
def check_if_in_list(gle, gl_map):
for e in gl_map:
if e.account == gle.account and \
cstr(e.get('against_voucher'))==cstr(gle.get('against_voucher')) \
and cstr(e.get('against_voucher_type')) == \
cstr(gle.get('against_voucher_type')) \
and cstr(e.get('cost_center')) == cstr(gle.get('cost_center')):
return e
def check_budget(gl_map, cancel):
for gle in gl_map:
if gle.get('cost_center'):
#check budget only if account is expense account
acc_details = webnotes.conn.get_value("Account", gle['account'],
['is_pl_account', 'debit_or_credit'])
if acc_details[0]=="Yes" and acc_details[1]=="Debit":
webnotes.get_obj('Budget Control').check_budget(gle, cancel)
def save_entries(gl_map, cancel, adv_adj, update_outstanding):
def save_entries(gl_map, adv_adj, update_outstanding):
validate_account_for_auto_accounting_for_stock(gl_map)
total_debit = total_credit = 0.0
def _swap(gle):
gle.debit, gle.credit = abs(flt(gle.credit)), abs(flt(gle.debit))
for entry in gl_map:
gle = Document('GL Entry', fielddata=entry)
make_entry(entry, adv_adj, update_outstanding)
# check against budget
validate_expense_against_budget(entry)
# round off upto 2 decimal
gle.debit = flt(gle.debit, 2)
gle.credit = flt(gle.credit, 2)
# toggle debit, credit if negative entry
if flt(gle.debit) < 0 or flt(gle.credit) < 0:
_swap(gle)
# toggled debit/credit in two separate condition because
# both should be executed at the
# time of cancellation when there is negative amount (tax discount)
if cancel:
_swap(gle)
gle_obj = webnotes.get_obj(doc=gle)
# validate except on_cancel
if not cancel:
gle_obj.validate()
# save
gle.save(1)
gle_obj.on_update(adv_adj, cancel, update_outstanding)
# update total debit / credit
total_debit += flt(gle.debit)
total_credit += flt(gle.credit)
total_debit += flt(entry.debit)
total_credit += flt(entry.credit)
# print gle.account, gle.debit, gle.credit, total_debit, total_credit
if not cancel:
validate_total_debit_credit(total_debit, total_credit)
validate_total_debit_credit(total_debit, total_credit)
def make_entry(args, adv_adj, update_outstanding):
args.update({"doctype": "GL Entry"})
gle = webnotes.bean([args])
gle.ignore_permissions = 1
gle.insert()
gle.run_method("on_update_with_args", adv_adj, update_outstanding)
gle.submit()
def validate_total_debit_credit(total_debit, total_credit):
if abs(total_debit - total_credit) > 0.005:
webnotes.msgprint("""Debit and Credit not equal for
this voucher: Diff (Debit) is %s""" %
(total_debit - total_credit), raise_exception=1)
def set_as_cancel(voucher_type, voucher_no):
webnotes.conn.sql("""update `tabGL Entry` set is_cancelled='Yes',
modified=%s, modified_by=%s
where voucher_type=%s and voucher_no=%s""",
(now(), webnotes.session.user, voucher_type, voucher_no))
webnotes.throw(_("Debit and Credit not equal for this voucher: Diff (Debit) is ") +
cstr(total_debit - total_credit))
def validate_account_for_auto_accounting_for_stock(gl_map):
if gl_map[0].voucher_type=="Journal Voucher":
aii_accounts = [d[0] for d in webnotes.conn.sql("""select name from tabAccount
where account_type = 'Warehouse' and ifnull(master_name, '')!=''""")]
for entry in gl_map:
if entry.account in aii_accounts:
webnotes.throw(_("Account") + ": " + entry.account +
_(" can only be debited/credited through Stock transactions"),
StockAccountInvalidTransaction)
def delete_gl_entries(gl_entries=None, voucher_type=None, voucher_no=None,
adv_adj=False, update_outstanding="Yes"):
from accounts.doctype.gl_entry.gl_entry import check_negative_balance, \
check_freezing_date, update_outstanding_amt, validate_frozen_account
if not gl_entries:
gl_entries = webnotes.conn.sql("""select * from `tabGL Entry`
where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no), as_dict=True)
if gl_entries:
check_freezing_date(gl_entries[0]["posting_date"], adv_adj)
webnotes.conn.sql("""delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s""",
(voucher_type or gl_entries[0]["voucher_type"], voucher_no or gl_entries[0]["voucher_no"]))
for entry in gl_entries:
validate_frozen_account(entry["account"], adv_adj)
check_negative_balance(entry["account"], adv_adj)
validate_expense_against_budget(entry)
if entry.get("against_voucher") and entry.get("against_voucher_type") != "POS" \
and update_outstanding == 'Yes':
update_outstanding_amt(entry["account"], entry.get("against_voucher_type"),
entry.get("against_voucher"), on_cancel=True)