Codacy corrections + sql queries

This commit is contained in:
Charles-Henri Decultot
2018-12-12 17:45:22 +00:00
parent 57c6b49d1a
commit 6a4dae3a9d
15 changed files with 32 additions and 43 deletions

View File

@@ -3,7 +3,6 @@
# For license information, please see license.txt # For license information, please see license.txt
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe
from frappe.model.document import Document from frappe.model.document import Document
class AccountSubtype(Document): class AccountSubtype(Document):

View File

@@ -3,7 +3,6 @@
# See license.txt # See license.txt
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe
import unittest import unittest
class TestAccountSubtype(unittest.TestCase): class TestAccountSubtype(unittest.TestCase):

View File

@@ -3,7 +3,6 @@
# For license information, please see license.txt # For license information, please see license.txt
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe
from frappe.model.document import Document from frappe.model.document import Document
class AccountType(Document): class AccountType(Document):

View File

@@ -3,7 +3,6 @@
# See license.txt # See license.txt
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe
import unittest import unittest
class TestAccountType(unittest.TestCase): class TestAccountType(unittest.TestCase):

View File

@@ -12,19 +12,19 @@ frappe.ui.form.on('Bank', {
let add_fields_to_mapping_table = function (frm) { let add_fields_to_mapping_table = function (frm) {
let options = [] let options = [];
frappe.model.with_doctype("Bank Transaction", function() { 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 => { meta.fields.forEach(value => {
if (!["Section Break", "Column Break"].includes(value.fieldtype)) { if (!["Section Break", "Column Break"].includes(value.fieldtype)) {
options.push(value.fieldname); options.push(value.fieldname);
} }
}) })
}) });
frappe.meta.get_docfield("Bank Transaction Mapping", "bank_transaction_field", frappe.meta.get_docfield("Bank Transaction Mapping", "bank_transaction_field",
frm.doc.name).options = options; frm.doc.name).options = options;
frm.fields_dict.bank_transaction_mapping.grid.refresh(); frm.fields_dict.bank_transaction_mapping.grid.refresh();
} };

View File

@@ -3,7 +3,7 @@
frappe.ui.form.on('Bank Transaction', { frappe.ui.form.on('Bank Transaction', {
onload: function(frm) { onload: function(frm) {
frm.set_query('payment_document', 'payment_entries', function(doc, cdt, cdn) { frm.set_query('payment_document', 'payment_entries', function() {
return { return {
"filters": { "filters": {
"name": ["in", ["Payment Entry", "Journal Entry", "Sales Invoice", "Purchase Invoice", "Expense Claim"]] "name": ["in", ["Payment Entry", "Journal Entry", "Sales Invoice", "Purchase Invoice", "Expense Claim"]]

View File

@@ -4,7 +4,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe import _
from frappe.model.document import Document from frappe.model.document import Document
from frappe.utils import flt from frappe.utils import flt

View File

@@ -5,7 +5,7 @@ frappe.listview_settings['Bank Transaction'] = {
add_fields: ["unallocated_amount"], add_fields: ["unallocated_amount"],
get_indicator: function(doc) { get_indicator: function(doc) {
if(flt(doc.unallocated_amount)>0) { 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) { } else if(flt(doc.unallocated_amount)==0) {
return [__("Reconciled"), "green", "unallocated_amount,=,0"]; return [__("Reconciled"), "green", "unallocated_amount,=,0"];
} }

View File

@@ -3,7 +3,6 @@
# For license information, please see license.txt # For license information, please see license.txt
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe
from frappe.model.document import Document from frappe.model.document import Document
class BankTransactionMapping(Document): class BankTransactionMapping(Document):

View File

@@ -3,7 +3,6 @@
# For license information, please see license.txt # For license information, please see license.txt
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe
from frappe.model.document import Document from frappe.model.document import Document
class BankTransactionPayments(Document): class BankTransactionPayments(Document):

View File

@@ -6,7 +6,6 @@ from __future__ import unicode_literals
import frappe import frappe
from frappe import _ from frappe import _
import difflib import difflib
from operator import itemgetter
from frappe.utils import flt from frappe.utils import flt
from six import iteritems from six import iteritems
@@ -49,12 +48,12 @@ def clear_payment_entry(transaction, payment_entry, gl_entry):
LEFT JOIN LEFT JOIN
`tabBank Transaction` as bt on btp.parent=bt.name `tabBank Transaction` as bt on btp.parent=bt.name
WHERE WHERE
btp.payment_document = '%s' btp.payment_document = %s
AND AND
btp.payment_entry = '%s' btp.payment_entry = %s
AND AND
bt.docstatus = 1 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_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)) amount_to_be_cleared = (flt(gl_entry.debit) - flt(gl_entry.credit))
@@ -118,7 +117,7 @@ def check_matching_amount(bank_account, transaction):
journal_entries = frappe.db.sql(""" journal_entries = frappe.db.sql("""
SELECT SELECT
'Journal Entry' as doctype, je.name, je.posting_date, je.cheque_no as reference_no, '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 FROM
`tabJournal Entry Account` as jea `tabJournal Entry Account` as jea
JOIN JOIN
@@ -128,12 +127,12 @@ def check_matching_amount(bank_account, transaction):
WHERE WHERE
(je.clearance_date is null or je.clearance_date='0000-00-00') (je.clearance_date is null or je.clearance_date='0000-00-00')
AND AND
jea.account = '%s' jea.account = %s
AND AND
%s like '%s' {0} like %s
AND AND
je.docstatus = 1 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(""" sales_invoices = frappe.db.sql("""
SELECT SELECT
@@ -148,12 +147,12 @@ def check_matching_amount(bank_account, transaction):
WHERE WHERE
(sip.clearance_date is null or sip.clearance_date='0000-00-00') (sip.clearance_date is null or sip.clearance_date='0000-00-00')
AND AND
sip.account = '%s' sip.account = %s
AND AND
sip.amount like '%s' sip.amount like %s
AND AND
si.docstatus = 1 si.docstatus = 1
""" % (bank_account, amount), as_dict=True) """, (bank_account, amount), as_dict=True)
for data in [payment_entries, journal_entries, sales_invoices]: for data in [payment_entries, journal_entries, sales_invoices]:
if data: if data:
@@ -162,6 +161,9 @@ def check_matching_amount(bank_account, transaction):
return payments return payments
def get_matching_descriptions_data(bank_account, transaction): def get_matching_descriptions_data(bank_account, transaction):
if not transaction.description :
return []
bank_transactions = frappe.db.sql(""" bank_transactions = frappe.db.sql("""
SELECT SELECT
bt.name, bt.description, bt.date, btp.payment_document, btp.payment_entry bt.name, bt.description, bt.date, btp.payment_document, btp.payment_entry

View File

@@ -5,7 +5,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe import _ from frappe import _
import json
import requests import requests
from plaid import Client from plaid import Client
from plaid.errors import APIError, ItemError from plaid.errors import APIError, ItemError

View File

@@ -2,11 +2,7 @@
// For license information, please see license.txt // For license information, please see license.txt
frappe.ui.form.on('Plaid Settings', { frappe.ui.form.on('Plaid Settings', {
refresh: function(frm) { connect_btn: function() {
},
connect_btn: function(frm) {
frappe.set_route('bank-reconciliation'); frappe.set_route('bank-reconciliation');
} }
}); });

View File

@@ -83,7 +83,7 @@ def add_bank_accounts(response, bank, company):
result.append(new_account.name) 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)) frappe.msgprint(_("Bank account {0} already exists and could not be created again").format(new_account.account_name))
except Exception: except Exception:
frappe.throw(frappe.get_traceback()) frappe.throw(frappe.get_traceback())
@@ -99,7 +99,7 @@ def add_account_type(account_type):
"doctype": "Account Type", "doctype": "Account Type",
"account_type": account_type "account_type": account_type
}).insert() }).insert()
except: except Exception:
frappe.throw(frappe.get_traceback()) frappe.throw(frappe.get_traceback())

View File

@@ -3,7 +3,6 @@
# See license.txt # See license.txt
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe
import unittest import unittest
class TestPlaidSettings(unittest.TestCase): class TestPlaidSettings(unittest.TestCase):