mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-13 02:01:21 +00:00
deprecated gl_control and some rewrites
This commit is contained in:
@@ -17,7 +17,9 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import webnotes
|
||||
from webnotes.utils import nowdate
|
||||
from webnotes.utils import nowdate, cstr, flt
|
||||
from webnotes.model.doc import addchild
|
||||
from webnotes import msgprint, _
|
||||
|
||||
class FiscalYearError(webnotes.ValidationError): pass
|
||||
|
||||
@@ -96,4 +98,102 @@ def get_balance_on(account=None, date=None):
|
||||
bal = -bal
|
||||
|
||||
# if bal is None, return 0
|
||||
return bal or 0
|
||||
return bal or 0
|
||||
|
||||
@webnotes.whitelist()
|
||||
def add_ac(args=None):
|
||||
if not args:
|
||||
args = webnotes.form_dict
|
||||
args.pop("cmd")
|
||||
|
||||
ac = webnotes.model_wrapper(args)
|
||||
ac.doc.doctype = "Account"
|
||||
ac.doc.old_parent = ""
|
||||
ac.doc.freeze_account = "No"
|
||||
ac.ignore_permissions = 1
|
||||
ac.insert()
|
||||
return ac.doc.name
|
||||
|
||||
@webnotes.whitelist()
|
||||
def add_cc(args=None):
|
||||
if not args:
|
||||
args = webnotes.form_dict
|
||||
args.pop("cmd")
|
||||
|
||||
cc = webnotes.model_wrapper(args)
|
||||
cc.doc.doctype = "Cost Center"
|
||||
cc.doc.old_parent = ""
|
||||
cc.ignore_permissions = 1
|
||||
cc.insert()
|
||||
return cc.doc.name
|
||||
|
||||
def reconcile_against_document(args):
|
||||
"""
|
||||
Cancel JV, Update aginst document, split if required and resubmit jv
|
||||
"""
|
||||
for d in args:
|
||||
check_if_jv_modified(d)
|
||||
|
||||
against_fld = {
|
||||
'Journal Voucher' : 'against_jv',
|
||||
'Sales Invoice' : 'against_invoice',
|
||||
'Purchase Invoice' : 'against_voucher'
|
||||
}
|
||||
|
||||
d['against_fld'] = against_fld[d['against_voucher_type']]
|
||||
|
||||
# cancel JV
|
||||
jv_obj = webnotes.get_obj('Journal Voucher', d['voucher_no'], with_children=1)
|
||||
jv_obj.make_gl_entries(cancel=1, adv_adj=1)
|
||||
|
||||
# update ref in JV Detail
|
||||
update_against_doc(d, jv_obj)
|
||||
|
||||
# re-submit JV
|
||||
jv_obj = webnotes.get_obj('Journal Voucher', d['voucher_no'], with_children =1)
|
||||
jv_obj.make_gl_entries(cancel = 0, adv_adj =1)
|
||||
|
||||
|
||||
def check_if_jv_modified(args):
|
||||
"""
|
||||
check if there is already a voucher reference
|
||||
check if amount is same
|
||||
check if jv is submitted
|
||||
"""
|
||||
ret = webnotes.conn.sql("""
|
||||
select t2.%(dr_or_cr)s from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2
|
||||
where t1.name = t2.parent and t2.account = '%(account)s'
|
||||
and ifnull(t2.against_voucher, '')=''
|
||||
and ifnull(t2.against_invoice, '')='' and ifnull(t2.against_jv, '')=''
|
||||
and t1.name = '%(voucher_no)s' and t2.name = '%(voucher_detail_no)s'
|
||||
and t1.docstatus=1 and t2.%(dr_or_cr)s = %(unadjusted_amt)s""" % args)
|
||||
|
||||
if not ret:
|
||||
msgprint(_("""Payment Entry has been modified after you pulled it.
|
||||
Please pull it again."""), raise_exception=1)
|
||||
|
||||
def update_against_doc(d, jv_obj):
|
||||
"""
|
||||
Updates against document, if partial amount splits into rows
|
||||
"""
|
||||
|
||||
webnotes.conn.sql("""
|
||||
update `tabJournal Voucher Detail` t1, `tabJournal Voucher` t2
|
||||
set t1.%(dr_or_cr)s = '%(allocated_amt)s',
|
||||
t1.%(against_fld)s = '%(against_voucher)s', t2.modified = now()
|
||||
where t1.name = '%(voucher_detail_no)s' and t1.parent = t2.name""" % d)
|
||||
|
||||
if d['allocated_amt'] < d['unadjusted_amt']:
|
||||
jvd = webnotes.conn.sql("""select cost_center, balance, against_account, is_advance
|
||||
from `tabJournal Voucher Detail` where name = %s""", d['voucher_detail_no'])
|
||||
# new entry with balance amount
|
||||
ch = addchild(jv_obj.doc, 'entries', 'Journal Voucher Detail')
|
||||
ch.account = d['account']
|
||||
ch.cost_center = cstr(jvd[0][0])
|
||||
ch.balance = cstr(jvd[0][1])
|
||||
ch.fields[d['dr_or_cr']] = flt(d['unadjusted_amt']) - flt(d['allocated_amt'])
|
||||
ch.fields[d['dr_or_cr']== 'debit' and 'credit' or 'debit'] = 0
|
||||
ch.against_account = cstr(jvd[0][2])
|
||||
ch.is_advance = cstr(jvd[0][3])
|
||||
ch.docstatus = 1
|
||||
ch.save(1)
|
||||
Reference in New Issue
Block a user