fix: Multi currency payment reconciliation (#22738)

* fix: Multi currency payment reconciliation

* fix: Hide currency link fields
This commit is contained in:
Deepesh Garg 2020-07-22 17:59:37 +05:30 committed by GitHub
parent f098221550
commit c7eadfceb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 110 additions and 185 deletions

View File

@ -73,6 +73,10 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
}; };
} }
}); });
this.frm.set_value('party_type', '');
this.frm.set_value('party', '');
this.frm.set_value('receivable_payable_account', '');
}, },
refresh: function() { refresh: function() {

View File

@ -48,7 +48,8 @@ class PaymentReconciliation(Document):
select select
"Journal Entry" as reference_type, t1.name as reference_name, "Journal Entry" as reference_type, t1.name as reference_name,
t1.posting_date, t1.remark as remarks, t2.name as reference_row, t1.posting_date, t1.remark as remarks, t2.name as reference_row,
{dr_or_cr} as amount, t2.is_advance {dr_or_cr} as amount, t2.is_advance,
t2.account_currency as currency
from from
`tabJournal Entry` t1, `tabJournal Entry Account` t2 `tabJournal Entry` t1, `tabJournal Entry Account` t2
where where
@ -88,7 +89,8 @@ class PaymentReconciliation(Document):
if self.party_type == 'Customer' else "Purchase Invoice") if self.party_type == 'Customer' else "Purchase Invoice")
return frappe.db.sql(""" SELECT `tab{doc}`.name as reference_name, %(voucher_type)s as reference_type, return frappe.db.sql(""" SELECT `tab{doc}`.name as reference_name, %(voucher_type)s as reference_type,
(sum(`tabGL Entry`.{dr_or_cr}) - sum(`tabGL Entry`.{reconciled_dr_or_cr})) as amount (sum(`tabGL Entry`.{dr_or_cr}) - sum(`tabGL Entry`.{reconciled_dr_or_cr})) as amount,
account_currency as currency
FROM `tab{doc}`, `tabGL Entry` FROM `tab{doc}`, `tabGL Entry`
WHERE WHERE
(`tab{doc}`.name = `tabGL Entry`.against_voucher or `tab{doc}`.name = `tabGL Entry`.voucher_no) (`tab{doc}`.name = `tabGL Entry`.against_voucher or `tab{doc}`.name = `tabGL Entry`.voucher_no)
@ -141,6 +143,7 @@ class PaymentReconciliation(Document):
ent.invoice_number = e.get('voucher_no') ent.invoice_number = e.get('voucher_no')
ent.invoice_date = e.get('posting_date') ent.invoice_date = e.get('posting_date')
ent.amount = flt(e.get('invoice_amount')) ent.amount = flt(e.get('invoice_amount'))
ent.currency = e.get('currency')
ent.outstanding_amount = e.get('outstanding_amount') ent.outstanding_amount = e.get('outstanding_amount')
def reconcile(self, args): def reconcile(self, args):
@ -269,11 +272,14 @@ def reconcile_dr_cr_note(dr_cr_notes, company):
reconcile_dr_or_cr = ('debit_in_account_currency' reconcile_dr_or_cr = ('debit_in_account_currency'
if d.dr_or_cr == 'credit_in_account_currency' else 'credit_in_account_currency') if d.dr_or_cr == 'credit_in_account_currency' else 'credit_in_account_currency')
company_currency = erpnext.get_company_currency(company)
jv = frappe.get_doc({ jv = frappe.get_doc({
"doctype": "Journal Entry", "doctype": "Journal Entry",
"voucher_type": voucher_type, "voucher_type": voucher_type,
"posting_date": today(), "posting_date": today(),
"company": company, "company": company,
"multi_currency": 1 if d.currency != company_currency else 0,
"accounts": [ "accounts": [
{ {
'account': d.account, 'account': d.account,

View File

@ -1,183 +1,80 @@
{ {
"allow_copy": 0, "actions": [],
"allow_import": 0, "creation": "2014-07-09 16:14:23.672922",
"allow_rename": 0, "doctype": "DocType",
"beta": 0, "editable_grid": 1,
"creation": "2014-07-09 16:14:23.672922", "engine": "InnoDB",
"custom": 0, "field_order": [
"docstatus": 0, "invoice_type",
"doctype": "DocType", "invoice_number",
"document_type": "", "invoice_date",
"editable_grid": 1, "col_break1",
"amount",
"outstanding_amount",
"currency"
],
"fields": [ "fields": [
{ {
"allow_on_submit": 0, "fieldname": "invoice_type",
"bold": 0, "fieldtype": "Select",
"collapsible": 0, "in_list_view": 1,
"fieldname": "invoice_type", "label": "Invoice Type",
"fieldtype": "Select", "options": "Sales Invoice\nPurchase Invoice\nJournal Entry",
"hidden": 0, "read_only": 1
"ignore_user_permissions": 0, },
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Invoice Type",
"length": 0,
"no_copy": 0,
"options": "Sales Invoice\nPurchase Invoice\nJournal Entry",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "fieldname": "invoice_number",
"bold": 0, "fieldtype": "Dynamic Link",
"collapsible": 0, "in_list_view": 1,
"fieldname": "invoice_number", "label": "Invoice Number",
"fieldtype": "Dynamic Link", "options": "invoice_type",
"hidden": 0, "read_only": 1
"ignore_user_permissions": 0, },
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Invoice Number",
"length": 0,
"no_copy": 0,
"options": "invoice_type",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "fieldname": "invoice_date",
"bold": 0, "fieldtype": "Date",
"collapsible": 0, "in_list_view": 1,
"fieldname": "invoice_date", "label": "Invoice Date",
"fieldtype": "Date", "read_only": 1
"hidden": 0, },
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Invoice Date",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "fieldname": "col_break1",
"bold": 0, "fieldtype": "Column Break"
"collapsible": 0, },
"fieldname": "col_break1",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "fieldname": "amount",
"bold": 0, "fieldtype": "Currency",
"collapsible": 0, "in_list_view": 1,
"fieldname": "amount", "label": "Amount",
"fieldtype": "Currency", "options": "currency",
"hidden": 0, "read_only": 1
"ignore_user_permissions": 0, },
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Amount",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "fieldname": "outstanding_amount",
"bold": 0, "fieldtype": "Currency",
"collapsible": 0, "in_list_view": 1,
"fieldname": "outstanding_amount", "label": "Outstanding Amount",
"fieldtype": "Currency", "options": "currency",
"hidden": 0, "read_only": 1
"ignore_user_permissions": 0, },
"ignore_xss_filter": 0, {
"in_filter": 0, "fieldname": "currency",
"in_list_view": 1, "fieldtype": "Link",
"label": "Outstanding Amount", "hidden": 1,
"length": 0, "label": "Currency",
"no_copy": 0, "options": "Currency"
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
} }
], ],
"hide_heading": 0, "istable": 1,
"hide_toolbar": 0, "links": [],
"idx": 0, "modified": "2020-07-19 18:12:27.964073",
"image_view": 0, "modified_by": "Administrator",
"in_create": 0, "module": "Accounts",
"name": "Payment Reconciliation Invoice",
"is_submittable": 0, "owner": "Administrator",
"issingle": 0, "permissions": [],
"istable": 1, "quick_entry": 1,
"max_attachments": 0, "sort_field": "modified",
"modified": "2016-07-11 03:28:03.588476", "sort_order": "DESC",
"modified_by": "Administrator", "track_changes": 1
"module": "Accounts",
"name": "Payment Reconciliation Invoice",
"name_case": "",
"owner": "Administrator",
"permissions": [],
"quick_entry": 1,
"read_only": 0,
"read_only_onload": 0,
"sort_field": "modified",
"sort_order": "DESC",
"track_seen": 0
} }

View File

@ -1,7 +1,9 @@
{ {
"actions": [],
"creation": "2014-07-09 16:13:35.452759", "creation": "2014-07-09 16:13:35.452759",
"doctype": "DocType", "doctype": "DocType",
"editable_grid": 1, "editable_grid": 1,
"engine": "InnoDB",
"field_order": [ "field_order": [
"reference_type", "reference_type",
"reference_name", "reference_name",
@ -16,7 +18,8 @@
"difference_account", "difference_account",
"difference_amount", "difference_amount",
"sec_break1", "sec_break1",
"remark" "remark",
"currency"
], ],
"fields": [ "fields": [
{ {
@ -73,6 +76,7 @@
"fieldtype": "Currency", "fieldtype": "Currency",
"in_list_view": 1, "in_list_view": 1,
"label": "Amount", "label": "Amount",
"options": "currency",
"read_only": 1 "read_only": 1
}, },
{ {
@ -81,6 +85,7 @@
"fieldtype": "Currency", "fieldtype": "Currency",
"in_list_view": 1, "in_list_view": 1,
"label": "Allocated amount", "label": "Allocated amount",
"options": "currency",
"reqd": 1 "reqd": 1
}, },
{ {
@ -106,16 +111,25 @@
"fieldname": "difference_amount", "fieldname": "difference_amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"label": "Difference Amount", "label": "Difference Amount",
"options": "currency",
"print_hide": 1, "print_hide": 1,
"read_only": 1 "read_only": 1
}, },
{ {
"fieldname": "section_break_10", "fieldname": "section_break_10",
"fieldtype": "Section Break" "fieldtype": "Section Break"
},
{
"fieldname": "currency",
"fieldtype": "Link",
"hidden": 1,
"label": "Currency",
"options": "Currency"
} }
], ],
"istable": 1, "istable": 1,
"modified": "2019-06-24 00:08:11.150796", "links": [],
"modified": "2020-07-19 18:12:41.682347",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Payment Reconciliation Payment", "name": "Payment Reconciliation Payment",

View File

@ -795,7 +795,7 @@
"idx": 1, "idx": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2020-03-11 12:24:41.749986", "modified": "2020-07-18 12:24:41.749986",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Sales Invoice Item", "name": "Sales Invoice Item",

View File

@ -676,7 +676,8 @@ def get_outstanding_invoices(party_type, party, account, condition=None, filters
invoice_list = frappe.db.sql(""" invoice_list = frappe.db.sql("""
select select
voucher_no, voucher_type, posting_date, due_date, voucher_no, voucher_type, posting_date, due_date,
ifnull(sum({dr_or_cr}), 0) as invoice_amount ifnull(sum({dr_or_cr}), 0) as invoice_amount,
account_currency as currency
from from
`tabGL Entry` `tabGL Entry`
where where
@ -733,7 +734,8 @@ def get_outstanding_invoices(party_type, party, account, condition=None, filters
'invoice_amount': flt(d.invoice_amount), 'invoice_amount': flt(d.invoice_amount),
'payment_amount': payment_amount, 'payment_amount': payment_amount,
'outstanding_amount': outstanding_amount, 'outstanding_amount': outstanding_amount,
'due_date': d.due_date 'due_date': d.due_date,
'currency': d.currency
}) })
) )

View File

@ -1014,6 +1014,7 @@ def get_advance_journal_entries(party_type, party, party_account, amount_field,
def get_advance_payment_entries(party_type, party, party_account, order_doctype, def get_advance_payment_entries(party_type, party, party_account, order_doctype,
order_list=None, include_unallocated=True, against_all_orders=False, limit=None): order_list=None, include_unallocated=True, against_all_orders=False, limit=None):
party_account_field = "paid_from" if party_type == "Customer" else "paid_to" party_account_field = "paid_from" if party_type == "Customer" else "paid_to"
currency_field = "paid_from_account_currency" if party_type == "Customer" else "paid_to_account_currency"
payment_type = "Receive" if party_type == "Customer" else "Pay" payment_type = "Receive" if party_type == "Customer" else "Pay"
payment_entries_against_order, unallocated_payment_entries = [], [] payment_entries_against_order, unallocated_payment_entries = [], []
limit_cond = "limit %s" % limit if limit else "" limit_cond = "limit %s" % limit if limit else ""
@ -1030,14 +1031,15 @@ def get_advance_payment_entries(party_type, party, party_account, order_doctype,
select select
"Payment Entry" as reference_type, t1.name as reference_name, "Payment Entry" as reference_type, t1.name as reference_name,
t1.remarks, t2.allocated_amount as amount, t2.name as reference_row, t1.remarks, t2.allocated_amount as amount, t2.name as reference_row,
t2.reference_name as against_order, t1.posting_date t2.reference_name as against_order, t1.posting_date,
t1.{0} as currency
from `tabPayment Entry` t1, `tabPayment Entry Reference` t2 from `tabPayment Entry` t1, `tabPayment Entry Reference` t2
where where
t1.name = t2.parent and t1.{0} = %s and t1.payment_type = %s t1.name = t2.parent and t1.{1} = %s and t1.payment_type = %s
and t1.party_type = %s and t1.party = %s and t1.docstatus = 1 and t1.party_type = %s and t1.party = %s and t1.docstatus = 1
and t2.reference_doctype = %s {1} and t2.reference_doctype = %s {2}
order by t1.posting_date {2} order by t1.posting_date {3}
""".format(party_account_field, reference_condition, limit_cond), """.format(currency_field, party_account_field, reference_condition, limit_cond),
[party_account, payment_type, party_type, party, [party_account, payment_type, party_type, party,
order_doctype] + order_list, as_dict=1) order_doctype] + order_list, as_dict=1)