From 6a4dae3a9d826f834a7d6b15bcd5c2c68b9a13f5 Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Wed, 12 Dec 2018 17:45:22 +0000 Subject: [PATCH] Codacy corrections + sql queries --- .../account_subtype/account_subtype.py | 1 - .../account_subtype/test_account_subtype.py | 1 - .../doctype/account_type/account_type.py | 1 - .../doctype/account_type/test_account_type.py | 1 - erpnext/accounts/doctype/bank/bank.js | 8 ++--- .../bank_transaction/bank_transaction.js | 2 +- .../bank_transaction/bank_transaction.py | 5 ++- .../bank_transaction/bank_transaction_list.js | 2 +- .../bank_transaction_mapping.py | 1 - .../bank_transaction_payments.py | 1 - .../bank_reconciliation.py | 34 ++++++++++--------- .../doctype/plaid_settings/plaid_connector.py | 7 ++-- .../doctype/plaid_settings/plaid_settings.js | 6 +--- .../doctype/plaid_settings/plaid_settings.py | 4 +-- .../plaid_settings/test_plaid_settings.py | 1 - 15 files changed, 32 insertions(+), 43 deletions(-) diff --git a/erpnext/accounts/doctype/account_subtype/account_subtype.py b/erpnext/accounts/doctype/account_subtype/account_subtype.py index 27e61d81cbd..46c45cc733e 100644 --- a/erpnext/accounts/doctype/account_subtype/account_subtype.py +++ b/erpnext/accounts/doctype/account_subtype/account_subtype.py @@ -3,7 +3,6 @@ # For license information, please see license.txt from __future__ import unicode_literals -import frappe from frappe.model.document import Document class AccountSubtype(Document): diff --git a/erpnext/accounts/doctype/account_subtype/test_account_subtype.py b/erpnext/accounts/doctype/account_subtype/test_account_subtype.py index 92f29bdf03e..c37b5b9db7d 100644 --- a/erpnext/accounts/doctype/account_subtype/test_account_subtype.py +++ b/erpnext/accounts/doctype/account_subtype/test_account_subtype.py @@ -3,7 +3,6 @@ # See license.txt from __future__ import unicode_literals -import frappe import unittest class TestAccountSubtype(unittest.TestCase): diff --git a/erpnext/accounts/doctype/account_type/account_type.py b/erpnext/accounts/doctype/account_type/account_type.py index 5d9d6a9472e..3e6429318b0 100644 --- a/erpnext/accounts/doctype/account_type/account_type.py +++ b/erpnext/accounts/doctype/account_type/account_type.py @@ -3,7 +3,6 @@ # For license information, please see license.txt from __future__ import unicode_literals -import frappe from frappe.model.document import Document class AccountType(Document): diff --git a/erpnext/accounts/doctype/account_type/test_account_type.py b/erpnext/accounts/doctype/account_type/test_account_type.py index 3f7e25c67a8..824c2f66ae3 100644 --- a/erpnext/accounts/doctype/account_type/test_account_type.py +++ b/erpnext/accounts/doctype/account_type/test_account_type.py @@ -3,7 +3,6 @@ # See license.txt from __future__ import unicode_literals -import frappe import unittest class TestAccountType(unittest.TestCase): diff --git a/erpnext/accounts/doctype/bank/bank.js b/erpnext/accounts/doctype/bank/bank.js index 50334861b7b..6c76b0f85ea 100644 --- a/erpnext/accounts/doctype/bank/bank.js +++ b/erpnext/accounts/doctype/bank/bank.js @@ -12,19 +12,19 @@ frappe.ui.form.on('Bank', { let add_fields_to_mapping_table = function (frm) { - let options = [] + let options = []; frappe.model.with_doctype("Bank Transaction", function() { - let meta = frappe.get_meta("Bank Transaction") + let meta = frappe.get_meta("Bank Transaction"); meta.fields.forEach(value => { if (!["Section Break", "Column Break"].includes(value.fieldtype)) { options.push(value.fieldname); } }) - }) + }); frappe.meta.get_docfield("Bank Transaction Mapping", "bank_transaction_field", frm.doc.name).options = options; frm.fields_dict.bank_transaction_mapping.grid.refresh(); -} \ No newline at end of file +}; \ No newline at end of file diff --git a/erpnext/accounts/doctype/bank_transaction/bank_transaction.js b/erpnext/accounts/doctype/bank_transaction/bank_transaction.js index 511e6871d56..cf041cd3c77 100644 --- a/erpnext/accounts/doctype/bank_transaction/bank_transaction.js +++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction.js @@ -3,7 +3,7 @@ frappe.ui.form.on('Bank Transaction', { onload: function(frm) { - frm.set_query('payment_document', 'payment_entries', function(doc, cdt, cdn) { + frm.set_query('payment_document', 'payment_entries', function() { return { "filters": { "name": ["in", ["Payment Entry", "Journal Entry", "Sales Invoice", "Purchase Invoice", "Expense Claim"]] diff --git a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py index 80bf643a717..d8b5f00f6ee 100644 --- a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py +++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals import frappe -from frappe import _ from frappe.model.document import Document from frappe.utils import flt @@ -18,9 +17,9 @@ class BankTransaction(Document): if allocated_amount: frappe.db.set_value(self.doctype, self.name, "allocated_amount", flt(allocated_amount)) frappe.db.set_value(self.doctype, self.name, "unallocated_amount", abs(flt(self.credit) - flt(self.debit)) - flt(allocated_amount)) - + else: frappe.db.set_value(self.doctype, self.name, "allocated_amount", 0) frappe.db.set_value(self.doctype, self.name, "unallocated_amount", abs(flt(self.credit) - flt(self.debit))) - + self.reload() \ No newline at end of file diff --git a/erpnext/accounts/doctype/bank_transaction/bank_transaction_list.js b/erpnext/accounts/doctype/bank_transaction/bank_transaction_list.js index ece3cd7e435..db8f297597b 100644 --- a/erpnext/accounts/doctype/bank_transaction/bank_transaction_list.js +++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction_list.js @@ -5,7 +5,7 @@ frappe.listview_settings['Bank Transaction'] = { add_fields: ["unallocated_amount"], get_indicator: function(doc) { if(flt(doc.unallocated_amount)>0) { - return [__("Unreconciled"), "orange", "unallocated_amount,>,0"] + return [__("Unreconciled"), "orange", "unallocated_amount,>,0"]; } else if(flt(doc.unallocated_amount)==0) { return [__("Reconciled"), "green", "unallocated_amount,=,0"]; } diff --git a/erpnext/accounts/doctype/bank_transaction_mapping/bank_transaction_mapping.py b/erpnext/accounts/doctype/bank_transaction_mapping/bank_transaction_mapping.py index 70b7ed8f71e..95a5bc33883 100644 --- a/erpnext/accounts/doctype/bank_transaction_mapping/bank_transaction_mapping.py +++ b/erpnext/accounts/doctype/bank_transaction_mapping/bank_transaction_mapping.py @@ -3,7 +3,6 @@ # For license information, please see license.txt from __future__ import unicode_literals -import frappe from frappe.model.document import Document class BankTransactionMapping(Document): diff --git a/erpnext/accounts/doctype/bank_transaction_payments/bank_transaction_payments.py b/erpnext/accounts/doctype/bank_transaction_payments/bank_transaction_payments.py index 88ac38fde53..d6d7c109cf5 100644 --- a/erpnext/accounts/doctype/bank_transaction_payments/bank_transaction_payments.py +++ b/erpnext/accounts/doctype/bank_transaction_payments/bank_transaction_payments.py @@ -3,7 +3,6 @@ # For license information, please see license.txt from __future__ import unicode_literals -import frappe from frappe.model.document import Document class BankTransactionPayments(Document): diff --git a/erpnext/accounts/page/bank_reconciliation/bank_reconciliation.py b/erpnext/accounts/page/bank_reconciliation/bank_reconciliation.py index 85d8cd3ebf7..5c99429ed12 100644 --- a/erpnext/accounts/page/bank_reconciliation/bank_reconciliation.py +++ b/erpnext/accounts/page/bank_reconciliation/bank_reconciliation.py @@ -6,7 +6,6 @@ from __future__ import unicode_literals import frappe from frappe import _ import difflib -from operator import itemgetter from frappe.utils import flt from six import iteritems @@ -34,7 +33,7 @@ def reconcile(bank_transaction, payment_doctype, payment_name): def add_payment_to_transaction(transaction, payment_entry, gl_entry): transaction.append("payment_entries", { - "payment_document": payment_entry.doctype, + "payment_document": payment_entry.doctype, "payment_entry": payment_entry.name, "allocated_amount": gl_entry.credit if gl_entry.credit > 0 else gl_entry.debit }) @@ -49,12 +48,12 @@ def clear_payment_entry(transaction, payment_entry, gl_entry): LEFT JOIN `tabBank Transaction` as bt on btp.parent=bt.name WHERE - btp.payment_document = '%s' + btp.payment_document = %s AND - btp.payment_entry = '%s' + btp.payment_entry = %s AND bt.docstatus = 1 - """ % (payment_entry.doctype, payment_entry.name), as_dict=True) + """, (payment_entry.doctype, payment_entry.name), as_dict=True) amount_cleared = (flt(linked_bank_transactions[0].credit) - flt(linked_bank_transactions[0].debit)) amount_to_be_cleared = (flt(gl_entry.debit) - flt(gl_entry.credit)) @@ -87,7 +86,7 @@ def clear_sales_invoice(amount_cleared, amount_to_be_cleared, payment_entry, tra def get_linked_payments(bank_transaction): transaction = frappe.get_doc("Bank Transaction", bank_transaction) bank_account = frappe.db.get_value("Bank Account", transaction.bank_account, "account") - + # Get all payment entries with a matching amount amount_matching = check_matching_amount(bank_account, transaction) @@ -110,7 +109,7 @@ def check_matching_amount(bank_account, transaction): payment_type = "Receive" if transaction.credit > 0 else "Pay" account_from_to = "paid_to" if transaction.credit > 0 else "paid_from" currency_field = "paid_to_account_currency as currency" if transaction.credit > 0 else "paid_from_account_currency as currency" - payment_entries = frappe.get_all("Payment Entry", fields=["'Payment Entry' as doctype", "name", "paid_amount", "payment_type", "reference_no", "reference_date", + payment_entries = frappe.get_all("Payment Entry", fields=["'Payment Entry' as doctype", "name", "paid_amount", "payment_type", "reference_no", "reference_date", "party", "party_type", "posting_date", "{0}".format(currency_field)], filters=[["paid_amount", "like", "{0}%".format(amount)], ["docstatus", "=", "1"], ["payment_type", "=", payment_type], ["ifnull(clearance_date, '')", "=", ""], ["{0}".format(account_from_to), "=", "{0}".format(bank_account)]]) @@ -118,7 +117,7 @@ def check_matching_amount(bank_account, transaction): journal_entries = frappe.db.sql(""" SELECT 'Journal Entry' as doctype, je.name, je.posting_date, je.cheque_no as reference_no, - je.pay_to_recd_from as party, je.cheque_date as reference_date, %s as paid_amount + je.pay_to_recd_from as party, je.cheque_date as reference_date, {0} as paid_amount FROM `tabJournal Entry Account` as jea JOIN @@ -128,12 +127,12 @@ def check_matching_amount(bank_account, transaction): WHERE (je.clearance_date is null or je.clearance_date='0000-00-00') AND - jea.account = '%s' + jea.account = %s AND - %s like '%s' + {0} like %s AND je.docstatus = 1 - """ % (payment_field, bank_account, payment_field, amount), as_dict=True) + """.format(payment_field), (bank_account, amount), as_dict=True) sales_invoices = frappe.db.sql(""" SELECT @@ -148,12 +147,12 @@ def check_matching_amount(bank_account, transaction): WHERE (sip.clearance_date is null or sip.clearance_date='0000-00-00') AND - sip.account = '%s' + sip.account = %s AND - sip.amount like '%s' + sip.amount like %s AND si.docstatus = 1 - """ % (bank_account, amount), as_dict=True) + """, (bank_account, amount), as_dict=True) for data in [payment_entries, journal_entries, sales_invoices]: if data: @@ -162,7 +161,10 @@ def check_matching_amount(bank_account, transaction): return payments def get_matching_descriptions_data(bank_account, transaction): - bank_transactions = frappe.db.sql(""" + if not transaction.description : + return [] + + bank_transactions = frappe.db.sql(""" SELECT bt.name, bt.description, bt.date, btp.payment_document, btp.payment_entry FROM @@ -237,7 +239,7 @@ def get_matching_transactions_payments(description_matching): payment_by_ratio = {x["payment_entry"]: x["ratio"] for x in description_matching} if payments: - reference_payment_list = frappe.get_all("Payment Entry", fields=["name", "paid_amount", "payment_type", "reference_no", "reference_date", + reference_payment_list = frappe.get_all("Payment Entry", fields=["name", "paid_amount", "payment_type", "reference_no", "reference_date", "party", "party_type", "posting_date", "paid_to_account_currency"], filters=[["name", "in", payments]]) return sorted(reference_payment_list, key=lambda x: payment_by_ratio[x["name"]]) diff --git a/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_connector.py b/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_connector.py index f4eb97b32ef..fbb0ebc2c80 100644 --- a/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_connector.py +++ b/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_connector.py @@ -5,7 +5,6 @@ from __future__ import unicode_literals import frappe from frappe import _ -import json import requests from plaid import Client from plaid.errors import APIError, ItemError @@ -34,7 +33,7 @@ class PlaidConnector(): def get_access_token(self, public_token): if public_token is None: frappe.log_error(_("Public token is missing for this bank"), _("Plaid public token error")) - + response = self.client.Item.public_token.exchange(public_token) access_token = response['access_token'] @@ -68,10 +67,10 @@ class PlaidConnector(): account_ids = [account_id] response = self.client.Transactions.get(self.access_token, start_date=start_date, end_date=end_date, account_ids=account_ids) - + else: response = self.client.Transactions.get(self.access_token, start_date=start_date, end_date=end_date) - + transactions = response['transactions'] while len(transactions) < response['total_transactions']: diff --git a/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.js b/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.js index 44a261946cf..9f0442dade8 100644 --- a/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.js +++ b/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.js @@ -2,11 +2,7 @@ // For license information, please see license.txt frappe.ui.form.on('Plaid Settings', { - refresh: function(frm) { - - }, - - connect_btn: function(frm) { + connect_btn: function() { frappe.set_route('bank-reconciliation'); } }); \ No newline at end of file diff --git a/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.py b/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.py index 85aa9fa4671..0cf315fecec 100644 --- a/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.py +++ b/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.py @@ -83,7 +83,7 @@ def add_bank_accounts(response, bank, company): result.append(new_account.name) - except frappe.UniqueValidationError as e: + except frappe.UniqueValidationError: frappe.msgprint(_("Bank account {0} already exists and could not be created again").format(new_account.account_name)) except Exception: frappe.throw(frappe.get_traceback()) @@ -99,7 +99,7 @@ def add_account_type(account_type): "doctype": "Account Type", "account_type": account_type }).insert() - except: + except Exception: frappe.throw(frappe.get_traceback()) diff --git a/erpnext/erpnext_integrations/doctype/plaid_settings/test_plaid_settings.py b/erpnext/erpnext_integrations/doctype/plaid_settings/test_plaid_settings.py index fdf285632ee..c227f19ebee 100644 --- a/erpnext/erpnext_integrations/doctype/plaid_settings/test_plaid_settings.py +++ b/erpnext/erpnext_integrations/doctype/plaid_settings/test_plaid_settings.py @@ -3,7 +3,6 @@ # See license.txt from __future__ import unicode_literals -import frappe import unittest class TestPlaidSettings(unittest.TestCase):