Fixes in Payment Reconciliation
This commit is contained in:
parent
d5a08ea449
commit
e368091627
@ -18,12 +18,8 @@ class PaymentReconciliation(Document):
|
|||||||
def get_jv_entries(self):
|
def get_jv_entries(self):
|
||||||
self.check_mandatory_to_fetch()
|
self.check_mandatory_to_fetch()
|
||||||
dr_or_cr = "credit" if self.party_type == "Customer" else "debit"
|
dr_or_cr = "credit" if self.party_type == "Customer" else "debit"
|
||||||
if self.party_type=="Customer":
|
|
||||||
amount_query = "ifnull(t2.credit, 0) - ifnull(t2.debit, 0)"
|
|
||||||
else:
|
|
||||||
amount_query = "ifnull(t2.debit, 0) - ifnull(t2.credit, 0)"
|
|
||||||
|
|
||||||
cond = self.check_condition(amount_query)
|
cond = self.check_condition(dr_or_cr)
|
||||||
|
|
||||||
bank_account_condition = "t2.against_account like %(bank_cash_account)s" \
|
bank_account_condition = "t2.against_account like %(bank_cash_account)s" \
|
||||||
if self.bank_cash_account else "1=1"
|
if self.bank_cash_account else "1=1"
|
||||||
@ -31,14 +27,12 @@ class PaymentReconciliation(Document):
|
|||||||
jv_entries = frappe.db.sql("""
|
jv_entries = frappe.db.sql("""
|
||||||
select
|
select
|
||||||
t1.name as voucher_no, t1.posting_date, t1.remark, t2.account,
|
t1.name as voucher_no, t1.posting_date, t1.remark, t2.account,
|
||||||
t2.name as voucher_detail_no, {amount_query} as payment_amount, t2.is_advance
|
t2.name as voucher_detail_no, {dr_or_cr} as payment_amount, t2.is_advance
|
||||||
from
|
from
|
||||||
`tabJournal Voucher` t1, `tabJournal Voucher Detail` t2
|
`tabJournal Voucher` t1, `tabJournal Voucher Detail` t2
|
||||||
where
|
where
|
||||||
t1.name = t2.parent and t1.docstatus = 1 and t2.docstatus = 1
|
t1.name = t2.parent and t1.docstatus = 1 and t2.docstatus = 1
|
||||||
and t2.account = %(party_account)s and {amount_query} > 0
|
and t2.account = %(party_account)s and {dr_or_cr} > 0
|
||||||
and ifnull((select ifnull(sum(ifnull(credit, 0) - ifnull(debit, 0)), 0) from `tabJournal Voucher Detail`
|
|
||||||
where parent=t1.name and account=t2.account and docstatus=1 group by account), 0) > 0
|
|
||||||
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, '')='' {cond}
|
and ifnull(t2.against_jv, '')='' {cond}
|
||||||
and (CASE
|
and (CASE
|
||||||
@ -50,7 +44,6 @@ class PaymentReconciliation(Document):
|
|||||||
"dr_or_cr": dr_or_cr,
|
"dr_or_cr": dr_or_cr,
|
||||||
"cond": cond,
|
"cond": cond,
|
||||||
"bank_account_condition": bank_account_condition,
|
"bank_account_condition": bank_account_condition,
|
||||||
"amount_query": amount_query
|
|
||||||
}), {
|
}), {
|
||||||
"party_account": self.party_account,
|
"party_account": self.party_account,
|
||||||
"bank_cash_account": "%%%s%%" % self.bank_cash_account
|
"bank_cash_account": "%%%s%%" % self.bank_cash_account
|
||||||
@ -73,40 +66,33 @@ class PaymentReconciliation(Document):
|
|||||||
#Fetch JVs, Sales and Purchase Invoices for 'payment_reconciliation_invoices' to reconcile against
|
#Fetch JVs, Sales and Purchase Invoices for 'payment_reconciliation_invoices' to reconcile against
|
||||||
non_reconciled_invoices = []
|
non_reconciled_invoices = []
|
||||||
dr_or_cr = "debit" if self.party_type == "Customer" else "credit"
|
dr_or_cr = "debit" if self.party_type == "Customer" else "credit"
|
||||||
if self.party_type=="Customer":
|
cond = self.check_condition(dr_or_cr)
|
||||||
amount_query = "ifnull(debit, 0) - ifnull(credit, 0)"
|
|
||||||
else:
|
|
||||||
amount_query = "ifnull(credit, 0) - ifnull(debit, 0)"
|
|
||||||
|
|
||||||
cond = self.check_condition(amount_query)
|
|
||||||
|
|
||||||
invoice_list = frappe.db.sql("""
|
invoice_list = frappe.db.sql("""
|
||||||
select
|
select
|
||||||
voucher_no, voucher_type, posting_date,
|
voucher_no, voucher_type, posting_date,
|
||||||
ifnull(sum({amount_query}), 0) as invoice_amount
|
ifnull(sum({dr_or_cr}), 0) as invoice_amount
|
||||||
from
|
from
|
||||||
`tabGL Entry`
|
`tabGL Entry`
|
||||||
where
|
where
|
||||||
account = %s and {amount_query} > 0 {cond}
|
account = %s and {dr_or_cr} > 0 {cond}
|
||||||
group by voucher_type, voucher_no
|
group by voucher_type, voucher_no
|
||||||
""".format(**{
|
""".format(**{
|
||||||
"cond": cond,
|
"cond": cond,
|
||||||
"amount_query": amount_query
|
"dr_or_cr": dr_or_cr
|
||||||
}), (self.party_account), as_dict=True)
|
}), (self.party_account), as_dict=True)
|
||||||
|
|
||||||
for d in invoice_list:
|
for d in invoice_list:
|
||||||
payment_amount = frappe.db.sql("""
|
payment_amount = frappe.db.sql("""
|
||||||
select
|
select
|
||||||
ifnull(sum(ifnull({amount_query}, 0)), 0)
|
ifnull(sum(ifnull({0}, 0)), 0)
|
||||||
from
|
from
|
||||||
`tabGL Entry`
|
`tabGL Entry`
|
||||||
where
|
where
|
||||||
account = %s and {amount_query} < 0
|
account = %s and {0} > 0
|
||||||
and against_voucher_type = %s and ifnull(against_voucher, '') = %s
|
and against_voucher_type = %s and ifnull(against_voucher, '') = %s
|
||||||
""".format(**{
|
""".format("credit" if self.party_type == "Customer" else "debit"),
|
||||||
"cond": cond,
|
(self.party_account, d.voucher_type, d.voucher_no))
|
||||||
"amount_query": amount_query
|
|
||||||
}), (self.party_account, d.voucher_type, d.voucher_no))
|
|
||||||
|
|
||||||
payment_amount = -1*payment_amount[0][0] if payment_amount else 0
|
payment_amount = -1*payment_amount[0][0] if payment_amount else 0
|
||||||
|
|
||||||
@ -189,13 +175,13 @@ class PaymentReconciliation(Document):
|
|||||||
if not invoices_to_reconcile:
|
if not invoices_to_reconcile:
|
||||||
frappe.throw(_("Please select Invoice Type and Invoice Number in atleast one row"))
|
frappe.throw(_("Please select Invoice Type and Invoice Number in atleast one row"))
|
||||||
|
|
||||||
def check_condition(self, amount_query):
|
def check_condition(self, dr_or_cr):
|
||||||
cond = self.from_date and " and posting_date >= '" + self.from_date + "'" or ""
|
cond = self.from_date and " and posting_date >= '" + self.from_date + "'" or ""
|
||||||
cond += self.to_date and " and posting_date <= '" + self.to_date + "'" or ""
|
cond += self.to_date and " and posting_date <= '" + self.to_date + "'" or ""
|
||||||
|
|
||||||
if self.minimum_amount:
|
if self.minimum_amount:
|
||||||
cond += " and {0} >= %s".format(amount_query) % self.minimum_amount
|
cond += " and {0} >= %s".format(dr_or_cr) % self.minimum_amount
|
||||||
if self.maximum_amount:
|
if self.maximum_amount:
|
||||||
cond += " and {0} <= %s".format(amount_query) % self.maximum_amount
|
cond += " and {0} <= %s".format(dr_or_cr) % self.maximum_amount
|
||||||
|
|
||||||
return cond
|
return cond
|
Loading…
x
Reference in New Issue
Block a user