coa: payment to invoice matching tool fixes

This commit is contained in:
Nabin Hait 2014-03-27 17:19:32 +05:30
parent becf75d791
commit 4090c78c3f
3 changed files with 28 additions and 51 deletions

View File

@ -1,9 +1,6 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
// Booking Entry Id
// --------------------
cur_frm.add_fetch("account", "company", "company") cur_frm.add_fetch("account", "company", "company")
cur_frm.cscript.onload_post_render = function(doc) { cur_frm.cscript.onload_post_render = function(doc) {
@ -25,26 +22,15 @@ cur_frm.fields_dict.voucher_no.get_query = function(doc) {
else { else {
return { return {
doctype: doc.voucher_type, doctype: doc.voucher_type,
query: "accounts.doctype.payment_to_invoice_matching_tool.payment_to_invoice_matching_tool.gl_entry_details", query: "erpnext.accounts.doctype.payment_to_invoice_matching_tool.payment_to_invoice_matching_tool.gl_entry_details",
filters: { filters: {
"dt": doc.voucher_type, "dt": doc.voucher_type,
"acc": doc.account, "acc": doc.account
"account_type": doc.account_type
} }
} }
} }
} }
cur_frm.cscript.voucher_no =function(doc, cdt, cdn) { cur_frm.cscript.voucher_no = function(doc, cdt, cdn) {
return get_server_fields('get_voucher_details', '', '', doc, cdt, cdn, 1) return get_server_fields('get_voucher_details', '', '', doc, cdt, cdn, 1)
} }
cur_frm.cscript.account = function(doc, cdt, cdn) {
return frappe.call({
doc: this.frm.doc,
method: "set_account_type",
callback: function(r) {
if(!r.exc) refresh_field("account_type");
}
});
}

View File

@ -7,33 +7,24 @@ import frappe
from frappe.utils import flt from frappe.utils import flt
from frappe.model.doc import addchild from frappe.model.doc import addchild
from frappe.model.bean import getlist from frappe.model.bean import getlist
from frappe import msgprint from frappe import msgprint, _
class DocType: class DocType:
def __init__(self, doc, doclist): def __init__(self, doc, doclist):
self.doc = doc self.doc = doc
self.doclist = doclist self.doclist = doclist
def set_account_type(self):
self.doc.account_type = ""
if self.doc.account:
root_type = frappe.db.get_value("Account", self.doc.account, "root_type")
self.doc.account_type = "debit" if root_type in ["Asset", "Income"] else "credit"
def get_voucher_details(self): def get_voucher_details(self):
total_amount = frappe.db.sql("""select sum(%s) from `tabGL Entry` total_amount = frappe.db.sql("""select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
from `tabGL Entry`
where voucher_type = %s and voucher_no = %s where voucher_type = %s and voucher_no = %s
and account = %s""" % and account = %s""", (self.doc.voucher_type, self.doc.voucher_no, self.doc.account))
(self.doc.account_type, '%s', '%s', '%s'),
(self.doc.voucher_type, self.doc.voucher_no, self.doc.account))
total_amount = total_amount and flt(total_amount[0][0]) or 0 total_amount = total_amount and flt(total_amount[0][0]) or 0
reconciled_payment = frappe.db.sql(""" reconciled_payment = frappe.db.sql("""
select sum(ifnull(%s, 0)) - sum(ifnull(%s, 0)) from `tabGL Entry` where select abs(sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))) from `tabGL Entry` where
against_voucher = %s and voucher_no != %s against_voucher = %s and voucher_no != %s
and account = %s""" % and account = %s""", (self.doc.voucher_no, self.doc.voucher_no, self.doc.account))
((self.doc.account_type == 'debit' and 'credit' or 'debit'), self.doc.account_type,
'%s', '%s', '%s'), (self.doc.voucher_no, self.doc.voucher_no, self.doc.account))
reconciled_payment = reconciled_payment and flt(reconciled_payment[0][0]) or 0 reconciled_payment = reconciled_payment and flt(reconciled_payment[0][0]) or 0
ret = { ret = {
@ -55,25 +46,26 @@ class DocType:
def get_gl_entries(self): def get_gl_entries(self):
self.validate_mandatory() self.validate_mandatory()
dc = self.doc.account_type == 'debit' and 'credit' or 'debit'
cond = self.doc.from_date and " and t1.posting_date >= '" + self.doc.from_date + "'" or "" cond = self.doc.from_date and " and t1.posting_date >= '" + self.doc.from_date + "'" or ""
cond += self.doc.to_date and " and t1.posting_date <= '" + self.doc.to_date + "'"or "" cond += self.doc.to_date and " and t1.posting_date <= '" + self.doc.to_date + "'"or ""
cond += self.doc.amt_greater_than and \ if self.doc.amt_greater_than:
' and t2.' + dc+' >= ' + self.doc.amt_greater_than or '' cond += ' and abs(ifnull(t2.debit, 0) - ifnull(t2.credit, 0)) >= ' + \
cond += self.doc.amt_less_than and \ self.doc.amt_greater_than
' and t2.' + dc+' <= ' + self.doc.amt_less_than or '' if self.doc.amt_less_than:
cond += ' and abs(ifnull(t2.debit, 0) - ifnull(t2.credit, 0)) >= ' + \
self.doc.amt_less_than
gle = frappe.db.sql(""" gle = frappe.db.sql("""
select t1.name as voucher_no, t1.posting_date, t1.total_debit as total_amt, select t1.name as voucher_no, t1.posting_date, t1.total_debit as total_amt,
sum(ifnull(t2.credit, 0)) - sum(ifnull(t2.debit, 0)) as amt_due, t1.remark, abs(sum(ifnull(t2.credit, 0)) - sum(ifnull(t2.debit, 0))) as amt_due, t1.remark,
t2.against_account, t2.name as voucher_detail_no t2.against_account, t2.name as voucher_detail_no
from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2
where t1.name = t2.parent and t1.docstatus = 1 and t2.account = %s where t1.name = t2.parent and t1.docstatus = 1 and t2.account = %s
and ifnull(t2.against_voucher, '')='' and ifnull(t2.against_invoice, '')='' and ifnull(t2.against_voucher, '')='' and ifnull(t2.against_invoice, '')=''
and ifnull(t2.against_jv, '')='' and t2.%s > 0 %s group by t1.name, t2.name """ % and ifnull(t2.against_jv, '')='' and t1.name != %s %s group by t1.name, t2.name """ %
('%s', dc, cond), self.doc.account, as_dict=1) ('%s', '%s', cond), (self.doc.account, self.doc.voucher_no), as_dict=1)
return gle return gle
@ -83,8 +75,7 @@ class DocType:
'Payment to Invoice Matching Tool Detail', self.doclist) 'Payment to Invoice Matching Tool Detail', self.doclist)
ch.voucher_no = d.get('voucher_no') ch.voucher_no = d.get('voucher_no')
ch.posting_date = d.get('posting_date') ch.posting_date = d.get('posting_date')
ch.amt_due = self.doc.account_type == 'debit' and flt(d.get('amt_due')) \ ch.amt_due = flt(d.get('amt_due'))
or -1*flt(d.get('amt_due'))
ch.total_amt = flt(d.get('total_amt')) ch.total_amt = flt(d.get('total_amt'))
ch.against_account = d.get('against_account') ch.against_account = d.get('against_account')
ch.remarks = d.get('remark') ch.remarks = d.get('remark')
@ -103,7 +94,7 @@ class DocType:
""" """
if not self.doc.voucher_no or not frappe.db.sql("""select name from `tab%s` if not self.doc.voucher_no or not frappe.db.sql("""select name from `tab%s`
where name = %s""" % (self.doc.voucher_type, '%s'), self.doc.voucher_no): where name = %s""" % (self.doc.voucher_type, '%s'), self.doc.voucher_no):
msgprint("Please select valid Voucher No to proceed", raise_exception=1) frappe.throw(_("Please select valid Voucher No to proceed"))
lst = [] lst = []
for d in getlist(self.doclist, 'ir_payment_details'): for d in getlist(self.doclist, 'ir_payment_details'):
@ -115,7 +106,7 @@ class DocType:
'against_voucher' : self.doc.voucher_no, 'against_voucher' : self.doc.voucher_no,
'account' : self.doc.account, 'account' : self.doc.account,
'is_advance' : 'No', 'is_advance' : 'No',
'dr_or_cr' : self.doc.account_type=='debit' and 'credit' or 'debit', # 'dr_or_cr' : self.doc.account_type=='debit' and 'credit' or 'debit',
'unadjusted_amt' : flt(d.amt_due), 'unadjusted_amt' : flt(d.amt_due),
'allocated_amt' : flt(d.amt_to_be_reconciled) 'allocated_amt' : flt(d.amt_to_be_reconciled)
} }
@ -131,15 +122,13 @@ class DocType:
def gl_entry_details(doctype, txt, searchfield, start, page_len, filters): def gl_entry_details(doctype, txt, searchfield, start, page_len, filters):
from erpnext.controllers.queries import get_match_cond from erpnext.controllers.queries import get_match_cond
return frappe.db.sql("""select gle.voucher_no, gle.posting_date, return frappe.db.sql("""select gle.voucher_no, gle.posting_date,
gle.%(account_type)s from `tabGL Entry` gle gle.debit, gle.credit from `tabGL Entry` gle
where gle.account = '%(acc)s' where gle.account = '%(acc)s'
and gle.voucher_type = '%(dt)s' and gle.voucher_type = '%(dt)s'
and gle.voucher_no like '%(txt)s' and gle.voucher_no like '%(txt)s'
and (ifnull(gle.against_voucher, '') = '' and (ifnull(gle.against_voucher, '') = ''
or ifnull(gle.against_voucher, '') = gle.voucher_no ) or ifnull(gle.against_voucher, '') = gle.voucher_no )
and ifnull(gle.%(account_type)s, 0) > 0
and (select ifnull(abs(sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))), 0) and (select ifnull(abs(sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))), 0)
from `tabGL Entry` from `tabGL Entry`
where account = '%(acc)s' where account = '%(acc)s'
@ -154,7 +143,6 @@ def gl_entry_details(doctype, txt, searchfield, start, page_len, filters):
limit %(start)s, %(page_len)s""" % { limit %(start)s, %(page_len)s""" % {
"dt":filters["dt"], "dt":filters["dt"],
"acc":filters["acc"], "acc":filters["acc"],
"account_type": filters['account_type'],
'mcond':get_match_cond(doctype), 'mcond':get_match_cond(doctype),
'txt': "%%%s%%" % txt, 'txt': "%%%s%%" % txt,
"start": start, "start": start,

View File

@ -162,6 +162,8 @@ def create_party_account(party, party_type, company):
if not frappe.db.exists("Account", (party + " - " + company_details.abbr)): if not frappe.db.exists("Account", (party + " - " + company_details.abbr)):
parent_account = company_details.receivables_group \ parent_account = company_details.receivables_group \
if party_type=="Customer" else company_details.payables_group if party_type=="Customer" else company_details.payables_group
if not parent_account:
frappe.throw(_("Please enter Account Receivable/Payable group in company master"))
# create # create
account = frappe.bean({ account = frappe.bean({
@ -172,7 +174,8 @@ def create_party_account(party, party_type, company):
'company': company, 'company': company,
'master_type': party_type, 'master_type': party_type,
'master_name': party, 'master_name': party,
"freeze_account": "No" "freeze_account": "No",
"report_type": "Balance Sheet"
}).insert(ignore_permissions=True) }).insert(ignore_permissions=True)
frappe.msgprint(_("Account Created") + ": " + account.doc.name) frappe.msgprint(_("Account Created") + ": " + account.doc.name)