Merge pull request #4108 from nabinhait/payment_reco
[fix] Payment Reconciliation in multi-currency
This commit is contained in:
commit
3c54e9779b
@ -74,6 +74,24 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
|
|||||||
doc: me.frm.doc,
|
doc: me.frm.doc,
|
||||||
method: 'get_unreconciled_entries',
|
method: 'get_unreconciled_entries',
|
||||||
callback: function(r, rt) {
|
callback: function(r, rt) {
|
||||||
|
me.set_invoice_options();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
reconcile: function() {
|
||||||
|
var me = this;
|
||||||
|
return this.frm.call({
|
||||||
|
doc: me.frm.doc,
|
||||||
|
method: 'reconcile',
|
||||||
|
callback: function(r, rt) {
|
||||||
|
me.set_invoice_options();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
set_invoice_options: function() {
|
||||||
var invoices = [];
|
var invoices = [];
|
||||||
|
|
||||||
$.each(me.frm.doc.invoices || [], function(i, row) {
|
$.each(me.frm.doc.invoices || [], function(i, row) {
|
||||||
@ -90,17 +108,6 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
|
|||||||
|
|
||||||
refresh_field("payments");
|
refresh_field("payments");
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
reconcile: function() {
|
|
||||||
var me = this;
|
|
||||||
return this.frm.call({
|
|
||||||
doc: me.frm.doc,
|
|
||||||
method: 'reconcile'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,11 +3,8 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
|
|
||||||
from frappe.utils import flt
|
from frappe.utils import flt
|
||||||
|
|
||||||
from frappe import msgprint, _
|
from frappe import msgprint, _
|
||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
class PaymentReconciliation(Document):
|
class PaymentReconciliation(Document):
|
||||||
@ -17,7 +14,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_in_account_currency" if self.party_type == "Customer" \
|
||||||
|
else "debit_in_account_currency"
|
||||||
|
|
||||||
cond = self.check_condition(dr_or_cr)
|
cond = self.check_condition(dr_or_cr)
|
||||||
|
|
||||||
@ -68,7 +66,7 @@ class PaymentReconciliation(Document):
|
|||||||
def get_invoice_entries(self):
|
def get_invoice_entries(self):
|
||||||
#Fetch JVs, Sales and Purchase Invoices for 'invoices' to reconcile against
|
#Fetch JVs, Sales and Purchase Invoices for '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_in_account_currency" if self.party_type == "Customer" else "credit_in_account_currency"
|
||||||
cond = self.check_condition(dr_or_cr)
|
cond = self.check_condition(dr_or_cr)
|
||||||
|
|
||||||
invoice_list = frappe.db.sql("""
|
invoice_list = frappe.db.sql("""
|
||||||
@ -106,13 +104,15 @@ class PaymentReconciliation(Document):
|
|||||||
and account = %(account)s and {0} > 0
|
and account = %(account)s and {0} > 0
|
||||||
and against_voucher_type = %(against_voucher_type)s
|
and against_voucher_type = %(against_voucher_type)s
|
||||||
and ifnull(against_voucher, '') = %(against_voucher)s
|
and ifnull(against_voucher, '') = %(against_voucher)s
|
||||||
""".format("credit" if self.party_type == "Customer" else "debit"), {
|
""".format("credit_in_account_currency" if self.party_type == "Customer"
|
||||||
|
else "debit_in_account_currency"), {
|
||||||
"party_type": self.party_type,
|
"party_type": self.party_type,
|
||||||
"party": self.party,
|
"party": self.party,
|
||||||
"account": self.receivable_payable_account,
|
"account": self.receivable_payable_account,
|
||||||
"against_voucher_type": d.voucher_type,
|
"against_voucher_type": d.voucher_type,
|
||||||
"against_voucher": d.voucher_no
|
"against_voucher": d.voucher_no
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
payment_amount = payment_amount[0][0] if payment_amount else 0
|
payment_amount = payment_amount[0][0] if payment_amount else 0
|
||||||
|
|
||||||
@ -147,7 +147,8 @@ class PaymentReconciliation(Document):
|
|||||||
|
|
||||||
self.get_invoice_entries()
|
self.get_invoice_entries()
|
||||||
self.validate_invoice()
|
self.validate_invoice()
|
||||||
dr_or_cr = "credit" if self.party_type == "Customer" else "debit"
|
dr_or_cr = "credit_in_account_currency" if self.party_type == "Customer" \
|
||||||
|
else "debit_in_account_currency"
|
||||||
lst = []
|
lst = []
|
||||||
for e in self.get('payments'):
|
for e in self.get('payments'):
|
||||||
if e.invoice_number and e.allocated_amount:
|
if e.invoice_number and e.allocated_amount:
|
||||||
|
@ -198,6 +198,8 @@ def update_against_doc(d, jv_obj):
|
|||||||
"""
|
"""
|
||||||
jv_detail = jv_obj.get("accounts", {"name": d["voucher_detail_no"]})[0]
|
jv_detail = jv_obj.get("accounts", {"name": d["voucher_detail_no"]})[0]
|
||||||
jv_detail.set(d["dr_or_cr"], d["allocated_amt"])
|
jv_detail.set(d["dr_or_cr"], d["allocated_amt"])
|
||||||
|
jv_detail.set('debit' if d['dr_or_cr']=='debit_in_account_currency' else 'credit',
|
||||||
|
d["allocated_amt"]*flt(jv_detail.exchange_rate))
|
||||||
|
|
||||||
original_reference_type = jv_detail.reference_type
|
original_reference_type = jv_detail.reference_type
|
||||||
original_reference_name = jv_detail.reference_name
|
original_reference_name = jv_detail.reference_name
|
||||||
@ -211,6 +213,9 @@ def update_against_doc(d, jv_obj):
|
|||||||
from `tabJournal Entry Account` where name = %s
|
from `tabJournal Entry Account` where name = %s
|
||||||
""", d['voucher_detail_no'], as_dict=True)
|
""", d['voucher_detail_no'], as_dict=True)
|
||||||
|
|
||||||
|
amount_in_account_currency = flt(d['unadjusted_amt']) - flt(d['allocated_amt'])
|
||||||
|
amount_in_company_currency = amount_in_account_currency * flt(jvd[0]['exchange_rate'])
|
||||||
|
|
||||||
# new entry with balance amount
|
# new entry with balance amount
|
||||||
ch = jv_obj.append("accounts")
|
ch = jv_obj.append("accounts")
|
||||||
ch.account = d['account']
|
ch.account = d['account']
|
||||||
@ -220,8 +225,14 @@ def update_against_doc(d, jv_obj):
|
|||||||
ch.party = d["party"]
|
ch.party = d["party"]
|
||||||
ch.cost_center = cstr(jvd[0]["cost_center"])
|
ch.cost_center = cstr(jvd[0]["cost_center"])
|
||||||
ch.balance = flt(jvd[0]["balance"])
|
ch.balance = flt(jvd[0]["balance"])
|
||||||
ch.set(d['dr_or_cr'], flt(d['unadjusted_amt']) - flt(d['allocated_amt']))
|
|
||||||
ch.set(d['dr_or_cr']== 'debit' and 'credit' or 'debit', 0)
|
ch.set(d['dr_or_cr'], amount_in_account_currency)
|
||||||
|
ch.set('debit' if d['dr_or_cr']=='debit_in_account_currency' else 'credit', amount_in_company_currency)
|
||||||
|
|
||||||
|
ch.set('credit_in_account_currency' if d['dr_or_cr']== 'debit_in_account_currency'
|
||||||
|
else 'debit_in_account_currency', 0)
|
||||||
|
ch.set('credit' if d['dr_or_cr']== 'debit_in_account_currency' else 'debit', 0)
|
||||||
|
|
||||||
ch.against_account = cstr(jvd[0]["against_account"])
|
ch.against_account = cstr(jvd[0]["against_account"])
|
||||||
ch.reference_type = original_reference_type
|
ch.reference_type = original_reference_type
|
||||||
ch.reference_name = original_reference_name
|
ch.reference_name = original_reference_name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user