Py3 and matching corrections

This commit is contained in:
Charles-Henri Decultot
2019-04-19 10:09:06 +02:00
parent 332b4171c0
commit e86d21ea15
4 changed files with 20 additions and 13 deletions

View File

@@ -6,6 +6,7 @@ from __future__ import unicode_literals
import frappe import frappe
from frappe.model.document import Document from frappe.model.document import Document
from frappe.utils import flt from frappe.utils import flt
from six.moves import reduce
class BankTransaction(Document): class BankTransaction(Document):
def after_insert(self): def after_insert(self):

View File

@@ -7,6 +7,7 @@ import frappe
import json import json
from frappe.utils import getdate from frappe.utils import getdate
from frappe.utils.dateutils import parse_date from frappe.utils.dateutils import parse_date
from six import iteritems
@frappe.whitelist() @frappe.whitelist()
def upload_bank_statement(): def upload_bank_statement():
@@ -17,11 +18,11 @@ def upload_bank_statement():
from frappe.utils.file_manager import get_uploaded_content from frappe.utils.file_manager import get_uploaded_content
fname, fcontent = 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 from frappe.utils.csvutils import read_csv_content
rows = read_csv_content(fcontent, False) 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 from frappe.utils.xlsxutils import read_xlsx_file_from_attached_file
rows = read_xlsx_file_from_attached_file(fcontent=fcontent) 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: if all(item is None for item in d) is True:
continue continue
fields = {} fields = {}
for key, value in header_map.iteritems(): for key, value in iteritems(header_map):
fields.update({key: d[int(value)-1]}) fields.update({key: d[int(value)-1]})

View File

@@ -32,7 +32,6 @@ erpnext.accounts.bankReconciliation = class BankReconciliation {
fieldname: 'company', fieldname: 'company',
options: "Company", options: "Company",
onchange: function() { onchange: function() {
console.log(this.value)
if (this.value) { if (this.value) {
me.company = this.value; me.company = this.value;
} else { } else {

View File

@@ -83,7 +83,7 @@ def get_linked_payments(bank_transaction):
amount_matching = check_matching_amount(bank_account[0].account, bank_account[0].company, 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 # 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: if amount_matching:
return check_amount_vs_description(amount_matching, description_matching) return check_amount_vs_description(amount_matching, description_matching)
@@ -207,7 +207,7 @@ def check_matching_amount(bank_account, company, transaction):
return payments return payments
def get_matching_descriptions_data(bank_account, transaction): def get_matching_descriptions_data(company, transaction):
if not transaction.description : if not transaction.description :
return [] return []
@@ -243,17 +243,23 @@ def get_matching_descriptions_data(bank_account, transaction):
data = [] data = []
company_currency = get_company_currency(company)
for key, value in iteritems(links): for key, value in iteritems(links):
if key == "Payment Entry": 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": 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": 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": 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"])) 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 == "Purchase Invoice": if key == "Expense Claim":
data.append(frappe.get_all("Expense Claim", filters=[["name", "in", value]], fields=["'Expense Claim' as doctype", "posting_date", "employee_name as party"])) 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 return data
@@ -269,7 +275,7 @@ def check_amount_vs_description(amount_matching, description_matching):
continue continue
if hasattr(am_match, "reference_no") and hasattr(des_match, "reference_no"): 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: if am_match not in result:
result.append(am_match) result.append(am_match)
if result: if result: