From e86d21ea15a8e8da150c8ea2e933917dfe2e2c7b Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Fri, 19 Apr 2019 10:09:06 +0200 Subject: [PATCH] Py3 and matching corrections --- .../bank_transaction/bank_transaction.py | 1 + .../bank_transaction_upload.py | 7 +++--- .../bank_reconciliation.js | 1 - .../bank_reconciliation.py | 24 ++++++++++++------- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py index d8b5f00f6ee..0050ffc9df2 100644 --- a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py +++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py @@ -6,6 +6,7 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document from frappe.utils import flt +from six.moves import reduce class BankTransaction(Document): def after_insert(self): diff --git a/erpnext/accounts/doctype/bank_transaction/bank_transaction_upload.py b/erpnext/accounts/doctype/bank_transaction/bank_transaction_upload.py index d5d8c0e0465..8dd8d286729 100644 --- a/erpnext/accounts/doctype/bank_transaction/bank_transaction_upload.py +++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction_upload.py @@ -7,6 +7,7 @@ import frappe import json from frappe.utils import getdate from frappe.utils.dateutils import parse_date +from six import iteritems @frappe.whitelist() def upload_bank_statement(): @@ -17,11 +18,11 @@ def upload_bank_statement(): from frappe.utils.file_manager import get_uploaded_content fname, fcontent = get_uploaded_content() - if frappe.safe_encode(fname).lower().endswith("csv"): + if frappe.safe_encode(fname).lower().endswith("csv".encode('utf-8')): from frappe.utils.csvutils import read_csv_content rows = read_csv_content(fcontent, False) - elif frappe.safe_encode(fname).lower().endswith("xlsx"): + elif frappe.safe_encode(fname).lower().endswith("xlsx".encode('utf-8')): from frappe.utils.xlsxutils import read_xlsx_file_from_attached_file rows = read_xlsx_file_from_attached_file(fcontent=fcontent) @@ -40,7 +41,7 @@ def create_bank_entries(columns, data, bank_account): if all(item is None for item in d) is True: continue fields = {} - for key, value in header_map.iteritems(): + for key, value in iteritems(header_map): fields.update({key: d[int(value)-1]}) diff --git a/erpnext/accounts/page/bank_reconciliation/bank_reconciliation.js b/erpnext/accounts/page/bank_reconciliation/bank_reconciliation.js index 5cb4bba6a55..c64e28fc218 100644 --- a/erpnext/accounts/page/bank_reconciliation/bank_reconciliation.js +++ b/erpnext/accounts/page/bank_reconciliation/bank_reconciliation.js @@ -32,7 +32,6 @@ erpnext.accounts.bankReconciliation = class BankReconciliation { fieldname: 'company', options: "Company", onchange: function() { - console.log(this.value) if (this.value) { me.company = this.value; } else { diff --git a/erpnext/accounts/page/bank_reconciliation/bank_reconciliation.py b/erpnext/accounts/page/bank_reconciliation/bank_reconciliation.py index e39cf9ea950..1f96bade762 100644 --- a/erpnext/accounts/page/bank_reconciliation/bank_reconciliation.py +++ b/erpnext/accounts/page/bank_reconciliation/bank_reconciliation.py @@ -83,7 +83,7 @@ def get_linked_payments(bank_transaction): amount_matching = check_matching_amount(bank_account[0].account, bank_account[0].company, transaction) # Get some data from payment entries linked to a corresponding bank transaction - description_matching = get_matching_descriptions_data(bank_account[0].account, transaction) + description_matching = get_matching_descriptions_data(bank_account[0].company, transaction) if amount_matching: return check_amount_vs_description(amount_matching, description_matching) @@ -207,7 +207,7 @@ def check_matching_amount(bank_account, company, transaction): return payments -def get_matching_descriptions_data(bank_account, transaction): +def get_matching_descriptions_data(company, transaction): if not transaction.description : return [] @@ -243,17 +243,23 @@ def get_matching_descriptions_data(bank_account, transaction): data = [] + company_currency = get_company_currency(company) for key, value in iteritems(links): if key == "Payment Entry": - data.extend(frappe.get_all("Payment Entry", filters=[["name", "in", value]], fields=["'Payment Entry' as doctype", "posting_date", "party", "reference_no", "reference_date", "paid_amount"])) + data.extend(frappe.get_all("Payment Entry", filters=[["name", "in", value]], fields=["'Payment Entry' as doctype", "posting_date", "party", "reference_no", "reference_date", "paid_amount", "paid_to_account_currency as currency"])) if key == "Journal Entry": - data.extend(frappe.get_all("Journal Entry", filters=[["name", "in", value]], fields=["'Journal Entry' as doctype", "posting_date", "paid_to_recd_from as party", "cheque_no as reference_no", "cheque_date as reference_date"])) + journal_entries = frappe.get_all("Journal Entry", filters=[["name", "in", value]], fields=["name", "'Journal Entry' as doctype", "posting_date", "paid_to_recd_from as party", "cheque_no as reference_no", "cheque_date as reference_date", "total_credit as paid_amount"]) + for journal_entry in journal_entries: + journal_entry_accounts = frappe.get_all("Journal Entry Account", filters={"parenttype": journal_entry["doctype"], "parent": journal_entry["name"]}, fields=["account_currency"]) + journal_entry["currency"] = journal_entry_accounts[0]["account_currency"] if journal_entry_accounts else company_currency + data.extend(journal_entries) if key == "Sales Invoice": - data.extend(frappe.get_all("Sales Invoice", filters=[["name", "in", value]], fields=["'Sales Invoice' as doctype", "posting_date", "customer_name as party"])) + data.extend(frappe.get_all("Sales Invoice", filters=[["name", "in", value]], fields=["'Sales Invoice' as doctype", "posting_date", "customer_name as party", "paid_amount", "currency"])) if key == "Purchase Invoice": - data.append(frappe.get_all("Purchase Invoice", filters=[["name", "in", value]], fields=["'Purchase Invoice' as doctype", "posting_date", "supplier_name as party"])) - if key == "Purchase Invoice": - data.append(frappe.get_all("Expense Claim", filters=[["name", "in", value]], fields=["'Expense Claim' as doctype", "posting_date", "employee_name as party"])) + data.extend(frappe.get_all("Purchase Invoice", filters=[["name", "in", value]], fields=["'Purchase Invoice' as doctype", "posting_date", "supplier_name as party", "paid_amount", "currency"])) + if key == "Expense Claim": + expense_claims = frappe.get_all("Expense Claim", filters=[["name", "in", value]], fields=["'Expense Claim' as doctype", "posting_date", "employee_name as party", "total_amount_reimbursed as paid_amount"]) + data.extend([dict(x,**{"currency": company_currency}) for x in expense_claims]) return data @@ -269,7 +275,7 @@ def check_amount_vs_description(amount_matching, description_matching): continue if hasattr(am_match, "reference_no") and hasattr(des_match, "reference_no"): - if difflib.SequenceMatcher(lambda x: x == " ", am_match["reference_no"], des_match["reference_no"]) > 70: + if difflib.SequenceMatcher(lambda x: x == " ", am_match["reference_no"], des_match["reference_no"]).ratio() > 70: if am_match not in result: result.append(am_match) if result: