mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 11:19:09 +00:00
Rewritten update_against_document function
This commit is contained in:
@@ -5,18 +5,19 @@
|
|||||||
{
|
{
|
||||||
'creation': '2010-08-08 17:08:56',
|
'creation': '2010-08-08 17:08:56',
|
||||||
'docstatus': 0,
|
'docstatus': 0,
|
||||||
'modified': '2010-12-29 18:18:55',
|
'modified': '2011-09-26 18:55:05',
|
||||||
'modified_by': 'umair@iwebnotes.com',
|
'modified_by': 'Administrator',
|
||||||
'owner': 'Administrator'
|
'owner': 'Administrator'
|
||||||
},
|
},
|
||||||
|
|
||||||
# These values are common for all DocType
|
# These values are common for all DocType
|
||||||
{
|
{
|
||||||
'_last_update': '1308741898',
|
'_last_update': '1316075905',
|
||||||
'allow_copy': 1,
|
'allow_copy': 1,
|
||||||
'allow_trash': 1,
|
'allow_trash': 1,
|
||||||
'autoname': 'field:cost_center_name',
|
'autoname': 'field:cost_center_name',
|
||||||
'colour': 'White:FFF',
|
'colour': 'White:FFF',
|
||||||
|
'default_print_format': 'Standard',
|
||||||
'doctype': 'DocType',
|
'doctype': 'DocType',
|
||||||
'document_type': 'Master',
|
'document_type': 'Master',
|
||||||
'in_create': 1,
|
'in_create': 1,
|
||||||
@@ -26,7 +27,7 @@
|
|||||||
'section_style': 'Simple',
|
'section_style': 'Simple',
|
||||||
'server_code_error': ' ',
|
'server_code_error': ' ',
|
||||||
'show_in_menu': 0,
|
'show_in_menu': 0,
|
||||||
'version': 104
|
'version': 107
|
||||||
},
|
},
|
||||||
|
|
||||||
# These values are common for all DocField
|
# These values are common for all DocField
|
||||||
@@ -60,7 +61,6 @@
|
|||||||
'cancel': 0,
|
'cancel': 0,
|
||||||
'create': 0,
|
'create': 0,
|
||||||
'doctype': 'DocPerm',
|
'doctype': 'DocPerm',
|
||||||
'idx': 1,
|
|
||||||
'permlevel': 1,
|
'permlevel': 1,
|
||||||
'role': 'Accounts Manager',
|
'role': 'Accounts Manager',
|
||||||
'submit': 0,
|
'submit': 0,
|
||||||
@@ -73,7 +73,6 @@
|
|||||||
'cancel': 1,
|
'cancel': 1,
|
||||||
'create': 1,
|
'create': 1,
|
||||||
'doctype': 'DocPerm',
|
'doctype': 'DocPerm',
|
||||||
'idx': 2,
|
|
||||||
'permlevel': 0,
|
'permlevel': 0,
|
||||||
'role': 'Accounts Manager',
|
'role': 'Accounts Manager',
|
||||||
'submit': 0,
|
'submit': 0,
|
||||||
@@ -86,7 +85,6 @@
|
|||||||
'cancel': 0,
|
'cancel': 0,
|
||||||
'create': 0,
|
'create': 0,
|
||||||
'doctype': 'DocPerm',
|
'doctype': 'DocPerm',
|
||||||
'idx': 3,
|
|
||||||
'permlevel': 1,
|
'permlevel': 1,
|
||||||
'role': 'Accounts User',
|
'role': 'Accounts User',
|
||||||
'submit': 0,
|
'submit': 0,
|
||||||
@@ -99,7 +97,6 @@
|
|||||||
'cancel': 0,
|
'cancel': 0,
|
||||||
'create': 0,
|
'create': 0,
|
||||||
'doctype': 'DocPerm',
|
'doctype': 'DocPerm',
|
||||||
'idx': 4,
|
|
||||||
'permlevel': 0,
|
'permlevel': 0,
|
||||||
'role': 'Accounts User',
|
'role': 'Accounts User',
|
||||||
'submit': 0,
|
'submit': 0,
|
||||||
@@ -111,7 +108,6 @@
|
|||||||
'cancel': 1,
|
'cancel': 1,
|
||||||
'create': 1,
|
'create': 1,
|
||||||
'doctype': 'DocPerm',
|
'doctype': 'DocPerm',
|
||||||
'idx': 5,
|
|
||||||
'permlevel': 0,
|
'permlevel': 0,
|
||||||
'role': 'System Manager',
|
'role': 'System Manager',
|
||||||
'write': 1
|
'write': 1
|
||||||
@@ -120,7 +116,6 @@
|
|||||||
# DocPerm
|
# DocPerm
|
||||||
{
|
{
|
||||||
'doctype': 'DocPerm',
|
'doctype': 'DocPerm',
|
||||||
'idx': 6,
|
|
||||||
'permlevel': 1,
|
'permlevel': 1,
|
||||||
'role': 'All'
|
'role': 'All'
|
||||||
},
|
},
|
||||||
@@ -130,7 +125,6 @@
|
|||||||
'doctype': 'DocField',
|
'doctype': 'DocField',
|
||||||
'fieldname': 'trash_reason',
|
'fieldname': 'trash_reason',
|
||||||
'fieldtype': 'Small Text',
|
'fieldtype': 'Small Text',
|
||||||
'idx': 1,
|
|
||||||
'label': 'Trash Reason',
|
'label': 'Trash Reason',
|
||||||
'oldfieldname': 'trash_reason',
|
'oldfieldname': 'trash_reason',
|
||||||
'oldfieldtype': 'Small Text',
|
'oldfieldtype': 'Small Text',
|
||||||
@@ -142,7 +136,6 @@
|
|||||||
'doctype': 'DocField',
|
'doctype': 'DocField',
|
||||||
'fieldname': 'cost_center_name',
|
'fieldname': 'cost_center_name',
|
||||||
'fieldtype': 'Data',
|
'fieldtype': 'Data',
|
||||||
'idx': 2,
|
|
||||||
'in_filter': 0,
|
'in_filter': 0,
|
||||||
'label': 'Cost Center Name',
|
'label': 'Cost Center Name',
|
||||||
'no_copy': 1,
|
'no_copy': 1,
|
||||||
@@ -159,7 +152,6 @@
|
|||||||
'doctype': 'DocField',
|
'doctype': 'DocField',
|
||||||
'fieldname': 'parent_cost_center',
|
'fieldname': 'parent_cost_center',
|
||||||
'fieldtype': 'Link',
|
'fieldtype': 'Link',
|
||||||
'idx': 3,
|
|
||||||
'label': 'Parent Cost Center',
|
'label': 'Parent Cost Center',
|
||||||
'oldfieldname': 'parent_cost_center',
|
'oldfieldname': 'parent_cost_center',
|
||||||
'oldfieldtype': 'Link',
|
'oldfieldtype': 'Link',
|
||||||
@@ -175,14 +167,12 @@
|
|||||||
'doctype': 'DocField',
|
'doctype': 'DocField',
|
||||||
'fieldname': 'company_name',
|
'fieldname': 'company_name',
|
||||||
'fieldtype': 'Link',
|
'fieldtype': 'Link',
|
||||||
'idx': 4,
|
|
||||||
'label': 'Company',
|
'label': 'Company',
|
||||||
'oldfieldname': 'company_name',
|
'oldfieldname': 'company_name',
|
||||||
'oldfieldtype': 'Link',
|
'oldfieldtype': 'Link',
|
||||||
'options': 'Company',
|
'options': 'Company',
|
||||||
'permlevel': 0,
|
'permlevel': 0,
|
||||||
'reqd': 1,
|
'reqd': 1,
|
||||||
'search_index': 0,
|
|
||||||
'trigger': 'Client'
|
'trigger': 'Client'
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -191,7 +181,6 @@
|
|||||||
'doctype': 'DocField',
|
'doctype': 'DocField',
|
||||||
'fieldname': 'company_abbr',
|
'fieldname': 'company_abbr',
|
||||||
'fieldtype': 'Data',
|
'fieldtype': 'Data',
|
||||||
'idx': 5,
|
|
||||||
'label': 'Company Abbr',
|
'label': 'Company Abbr',
|
||||||
'oldfieldname': 'company_abbr',
|
'oldfieldname': 'company_abbr',
|
||||||
'oldfieldtype': 'Data',
|
'oldfieldtype': 'Data',
|
||||||
@@ -204,8 +193,7 @@
|
|||||||
'doctype': 'DocField',
|
'doctype': 'DocField',
|
||||||
'fieldname': 'group_or_ledger',
|
'fieldname': 'group_or_ledger',
|
||||||
'fieldtype': 'Select',
|
'fieldtype': 'Select',
|
||||||
'hidden': 1,
|
'hidden': 0,
|
||||||
'idx': 6,
|
|
||||||
'label': 'Group or Ledger',
|
'label': 'Group or Ledger',
|
||||||
'no_copy': 1,
|
'no_copy': 1,
|
||||||
'oldfieldname': 'group_or_ledger',
|
'oldfieldname': 'group_or_ledger',
|
||||||
@@ -223,13 +211,11 @@
|
|||||||
'doctype': 'DocField',
|
'doctype': 'DocField',
|
||||||
'fieldname': 'distribution_id',
|
'fieldname': 'distribution_id',
|
||||||
'fieldtype': 'Link',
|
'fieldtype': 'Link',
|
||||||
'idx': 7,
|
|
||||||
'label': 'Distribution Id',
|
'label': 'Distribution Id',
|
||||||
'oldfieldname': 'distribution_id',
|
'oldfieldname': 'distribution_id',
|
||||||
'oldfieldtype': 'Link',
|
'oldfieldtype': 'Link',
|
||||||
'options': 'Budget Distribution',
|
'options': 'Budget Distribution',
|
||||||
'permlevel': 0,
|
'permlevel': 0
|
||||||
'search_index': 0
|
|
||||||
},
|
},
|
||||||
|
|
||||||
# DocField
|
# DocField
|
||||||
@@ -237,7 +223,6 @@
|
|||||||
'doctype': 'DocField',
|
'doctype': 'DocField',
|
||||||
'fieldname': 'budget_details',
|
'fieldname': 'budget_details',
|
||||||
'fieldtype': 'Table',
|
'fieldtype': 'Table',
|
||||||
'idx': 8,
|
|
||||||
'label': 'Budget Details',
|
'label': 'Budget Details',
|
||||||
'oldfieldname': 'budget_details',
|
'oldfieldname': 'budget_details',
|
||||||
'oldfieldtype': 'Table',
|
'oldfieldtype': 'Table',
|
||||||
@@ -251,7 +236,6 @@
|
|||||||
'fieldname': 'lft',
|
'fieldname': 'lft',
|
||||||
'fieldtype': 'Int',
|
'fieldtype': 'Int',
|
||||||
'hidden': 1,
|
'hidden': 1,
|
||||||
'idx': 9,
|
|
||||||
'in_filter': 1,
|
'in_filter': 1,
|
||||||
'label': 'lft',
|
'label': 'lft',
|
||||||
'no_copy': 1,
|
'no_copy': 1,
|
||||||
@@ -269,7 +253,6 @@
|
|||||||
'fieldname': 'rgt',
|
'fieldname': 'rgt',
|
||||||
'fieldtype': 'Int',
|
'fieldtype': 'Int',
|
||||||
'hidden': 1,
|
'hidden': 1,
|
||||||
'idx': 10,
|
|
||||||
'in_filter': 1,
|
'in_filter': 1,
|
||||||
'label': 'rgt',
|
'label': 'rgt',
|
||||||
'no_copy': 1,
|
'no_copy': 1,
|
||||||
@@ -286,13 +269,13 @@
|
|||||||
{
|
{
|
||||||
'doctype': 'DocField',
|
'doctype': 'DocField',
|
||||||
'fieldname': 'old_parent',
|
'fieldname': 'old_parent',
|
||||||
'fieldtype': 'Data',
|
'fieldtype': 'Link',
|
||||||
'hidden': 1,
|
'hidden': 1,
|
||||||
'idx': 11,
|
|
||||||
'label': 'old_parent',
|
'label': 'old_parent',
|
||||||
'no_copy': 1,
|
'no_copy': 1,
|
||||||
'oldfieldname': 'old_parent',
|
'oldfieldname': 'old_parent',
|
||||||
'oldfieldtype': 'Data',
|
'oldfieldtype': 'Data',
|
||||||
|
'options': 'Cost Center',
|
||||||
'permlevel': 0,
|
'permlevel': 0,
|
||||||
'print_hide': 1,
|
'print_hide': 1,
|
||||||
'report_hide': 1
|
'report_hide': 1
|
||||||
|
|||||||
@@ -191,6 +191,7 @@ class DocType:
|
|||||||
else:
|
else:
|
||||||
self.entries.append(le)
|
self.entries.append(le)
|
||||||
|
|
||||||
|
|
||||||
# Save GL Entries
|
# Save GL Entries
|
||||||
# ----------------
|
# ----------------
|
||||||
def save_entries(self, cancel, adv_adj, update_outstanding):
|
def save_entries(self, cancel, adv_adj, update_outstanding):
|
||||||
@@ -200,7 +201,6 @@ class DocType:
|
|||||||
tmp=le.debit
|
tmp=le.debit
|
||||||
le.debit, le.credit = abs(flt(le.credit)), abs(flt(tmp))
|
le.debit, le.credit = abs(flt(le.credit)), abs(flt(tmp))
|
||||||
|
|
||||||
|
|
||||||
le_obj = get_obj(doc=le)
|
le_obj = get_obj(doc=le)
|
||||||
# validate except on_cancel
|
# validate except on_cancel
|
||||||
if not cancel:
|
if not cancel:
|
||||||
@@ -214,9 +214,11 @@ class DocType:
|
|||||||
self.td += flt(le.debit)
|
self.td += flt(le.debit)
|
||||||
self.tc += flt(le.credit)
|
self.tc += flt(le.credit)
|
||||||
|
|
||||||
|
|
||||||
# Make Multiple Entries
|
# Make Multiple Entries
|
||||||
# ---------------------
|
# ---------------------
|
||||||
def make_gl_entries(self, doc, doclist, cancel=0, adv_adj = 0, use_mapper='', merge_entries = 1, update_outstanding='Yes'):
|
def make_gl_entries(self, doc, doclist, cancel=0, adv_adj = 0, use_mapper='', merge_entries = 1, update_outstanding='Yes'):
|
||||||
|
self.entries = []
|
||||||
# get entries
|
# get entries
|
||||||
le_map_list = sql("select * from `tabGL Mapper Detail` where parent = %s", use_mapper or doc.doctype, as_dict=1)
|
le_map_list = sql("select * from `tabGL Mapper Detail` where parent = %s", use_mapper or doc.doctype, as_dict=1)
|
||||||
self.td, self.tc = 0.0, 0.0
|
self.td, self.tc = 0.0, 0.0
|
||||||
@@ -330,6 +332,7 @@ class DocType:
|
|||||||
msgprint("Allocation amount cannot be greater than advance amount")
|
msgprint("Allocation amount cannot be greater than advance amount")
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
|
|
||||||
# Add extra row in jv detail for unadjusted amount
|
# Add extra row in jv detail for unadjusted amount
|
||||||
#--------------------------------------------------
|
#--------------------------------------------------
|
||||||
def add_extra_entry(self,jv_obj,jv,jv_detail_no, allocate, account_head, doctype, dr_or_cr, against_document_no):
|
def add_extra_entry(self,jv_obj,jv,jv_detail_no, allocate, account_head, doctype, dr_or_cr, against_document_no):
|
||||||
@@ -359,15 +362,92 @@ class DocType:
|
|||||||
# 2. check if amount is same
|
# 2. check if amount is same
|
||||||
# 3. check if is_advance is 'Yes'
|
# 3. check if is_advance is 'Yes'
|
||||||
# 4. check if jv is submitted
|
# 4. check if jv is submitted
|
||||||
ret = sql("select t2.%s from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 where t1.name = t2.parent and (t2.against_voucher = '' or t2.against_voucher is null) and (t2.against_invoice = '' or t2.against_invoice is null) and t2.account = '%s' and t1.name = '%s' and t2.name = '%s' and t2.is_advance = 'Yes' and t1.docstatus=1 and t2.%s = %s" % ( dr_or_cr, account_head, d.journal_voucher, d.jv_detail_no, dr_or_cr, d.advance_amount))
|
ret = sql("select t2.%s from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 where t1.name = t2.parent and ifnull(t2.against_voucher, '') = '' and ifnull(t2.against_invoice, '') = '' and t2.account = '%s' and t1.name = '%s' and t2.name = '%s' and t2.is_advance = 'Yes' and t1.docstatus=1 and t2.%s = %s" % (dr_or_cr, account_head, d.journal_voucher, d.jv_detail_no, dr_or_cr, d.advance_amount))
|
||||||
if (not ret):
|
if (not ret):
|
||||||
msgprint("Please click on 'Get Advances Paid' button as the advance entries have been changed.")
|
msgprint("Please click on 'Get Advances Paid' button as the advance entries have been changed.")
|
||||||
raise Exception
|
raise Exception
|
||||||
return
|
return
|
||||||
|
|
||||||
##############################################################################
|
|
||||||
# Repair Outstanding Amount
|
######################################################################################################################
|
||||||
##############################################################################
|
|
||||||
|
#------------------------------------------
|
||||||
|
def reconcile_against_document(self, args):
|
||||||
|
"""
|
||||||
|
Cancel JV, Update aginst document, split if required and resubmit jv
|
||||||
|
"""
|
||||||
|
|
||||||
|
for d in args:
|
||||||
|
self.check_if_jv_modified(d)
|
||||||
|
|
||||||
|
against_fld = {
|
||||||
|
'Journal Voucher' : 'against_jv',
|
||||||
|
'Receivable Voucher' : 'against_invoice',
|
||||||
|
'Payable Voucher' : 'against_voucher'
|
||||||
|
}
|
||||||
|
|
||||||
|
d['against_fld'] = against_fld[d['against_voucher_type']]
|
||||||
|
|
||||||
|
# cancel JV
|
||||||
|
jv_obj = get_obj('Journal Voucher', d['voucher_no'], with_children=1)
|
||||||
|
self.make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel =1, adv_adj =1)
|
||||||
|
|
||||||
|
# update ref in JV Detail
|
||||||
|
self.update_against_doc(d, jv_obj)
|
||||||
|
|
||||||
|
# re-submit JV
|
||||||
|
jv_obj = get_obj('Journal Voucher', d['voucher_no'], with_children =1)
|
||||||
|
self.make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel = 0, adv_adj =1)
|
||||||
|
|
||||||
|
#------------------------------------------
|
||||||
|
def update_against_doc(self, d, jv_obj):
|
||||||
|
"""
|
||||||
|
Updates against document, if partial amount splits into rows
|
||||||
|
"""
|
||||||
|
|
||||||
|
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 = 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', 1)
|
||||||
|
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)
|
||||||
|
|
||||||
|
#------------------------------------------
|
||||||
|
def check_if_jv_modified(self, args):
|
||||||
|
"""
|
||||||
|
check if there is already a voucher reference
|
||||||
|
check if amount is same
|
||||||
|
check if jv is submitted
|
||||||
|
"""
|
||||||
|
ret = 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)
|
||||||
|
|
||||||
|
######################################################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Repair Outstanding Amount
|
||||||
|
#---------------------------------
|
||||||
def repair_voucher_outstanding(self, voucher_obj):
|
def repair_voucher_outstanding(self, voucher_obj):
|
||||||
msg = []
|
msg = []
|
||||||
|
|
||||||
|
|||||||
@@ -185,7 +185,6 @@ class DocType:
|
|||||||
|
|
||||||
bal = flt(sql("select sum(debit)-sum(credit) from `tabGL Entry` where against_voucher=%s and against_voucher_type=%s and ifnull(is_cancelled,'No') = 'No'", (self.doc.against_voucher, self.doc.against_voucher_type))[0][0] or 0.0)
|
bal = flt(sql("select sum(debit)-sum(credit) from `tabGL Entry` where against_voucher=%s and against_voucher_type=%s and ifnull(is_cancelled,'No') = 'No'", (self.doc.against_voucher, self.doc.against_voucher_type))[0][0] or 0.0)
|
||||||
tds = 0
|
tds = 0
|
||||||
|
|
||||||
if self.doc.against_voucher_type=='Payable Voucher':
|
if self.doc.against_voucher_type=='Payable Voucher':
|
||||||
# amount to debit
|
# amount to debit
|
||||||
bal = -bal
|
bal = -bal
|
||||||
@@ -200,7 +199,7 @@ class DocType:
|
|||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
# Update outstanding amt on against voucher
|
# Update outstanding amt on against voucher
|
||||||
sql("update `tab%s` set outstanding_amount=%s where name='%s'"% (self.doc.against_voucher_type,bal,self.doc.against_voucher))
|
sql("update `tab%s` set outstanding_amount=%s where name='%s'" % (self.doc.against_voucher_type, bal, self.doc.against_voucher))
|
||||||
|
|
||||||
|
|
||||||
# Total outstanding can not be greater than credit limit for any time for any customer
|
# Total outstanding can not be greater than credit limit for any time for any customer
|
||||||
|
|||||||
Reference in New Issue
Block a user