Codacy corrections + sql queries
This commit is contained in:
@@ -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):
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
};
|
||||||
@@ -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"]]
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
@@ -18,9 +17,9 @@ class BankTransaction(Document):
|
|||||||
if allocated_amount:
|
if allocated_amount:
|
||||||
frappe.db.set_value(self.doctype, self.name, "allocated_amount", flt(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))
|
frappe.db.set_value(self.doctype, self.name, "unallocated_amount", abs(flt(self.credit) - flt(self.debit)) - flt(allocated_amount))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
frappe.db.set_value(self.doctype, self.name, "allocated_amount", 0)
|
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)))
|
frappe.db.set_value(self.doctype, self.name, "unallocated_amount", abs(flt(self.credit) - flt(self.debit)))
|
||||||
|
|
||||||
self.reload()
|
self.reload()
|
||||||
@@ -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"];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
@@ -34,7 +33,7 @@ def reconcile(bank_transaction, payment_doctype, payment_name):
|
|||||||
|
|
||||||
def add_payment_to_transaction(transaction, payment_entry, gl_entry):
|
def add_payment_to_transaction(transaction, payment_entry, gl_entry):
|
||||||
transaction.append("payment_entries", {
|
transaction.append("payment_entries", {
|
||||||
"payment_document": payment_entry.doctype,
|
"payment_document": payment_entry.doctype,
|
||||||
"payment_entry": payment_entry.name,
|
"payment_entry": payment_entry.name,
|
||||||
"allocated_amount": gl_entry.credit if gl_entry.credit > 0 else gl_entry.debit
|
"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
|
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))
|
||||||
@@ -87,7 +86,7 @@ def clear_sales_invoice(amount_cleared, amount_to_be_cleared, payment_entry, tra
|
|||||||
def get_linked_payments(bank_transaction):
|
def get_linked_payments(bank_transaction):
|
||||||
transaction = frappe.get_doc("Bank Transaction", bank_transaction)
|
transaction = frappe.get_doc("Bank Transaction", bank_transaction)
|
||||||
bank_account = frappe.db.get_value("Bank Account", transaction.bank_account, "account")
|
bank_account = frappe.db.get_value("Bank Account", transaction.bank_account, "account")
|
||||||
|
|
||||||
# Get all payment entries with a matching amount
|
# Get all payment entries with a matching amount
|
||||||
amount_matching = check_matching_amount(bank_account, transaction)
|
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"
|
payment_type = "Receive" if transaction.credit > 0 else "Pay"
|
||||||
account_from_to = "paid_to" if transaction.credit > 0 else "paid_from"
|
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"
|
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)],
|
"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)]])
|
["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("""
|
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,7 +161,10 @@ 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):
|
||||||
bank_transactions = frappe.db.sql("""
|
if not transaction.description :
|
||||||
|
return []
|
||||||
|
|
||||||
|
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
|
||||||
FROM
|
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}
|
payment_by_ratio = {x["payment_entry"]: x["ratio"] for x in description_matching}
|
||||||
|
|
||||||
if payments:
|
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]])
|
"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"]])
|
return sorted(reference_payment_list, key=lambda x: payment_by_ratio[x["name"]])
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -34,7 +33,7 @@ class PlaidConnector():
|
|||||||
def get_access_token(self, public_token):
|
def get_access_token(self, public_token):
|
||||||
if public_token is None:
|
if public_token is None:
|
||||||
frappe.log_error(_("Public token is missing for this bank"), _("Plaid public token error"))
|
frappe.log_error(_("Public token is missing for this bank"), _("Plaid public token error"))
|
||||||
|
|
||||||
response = self.client.Item.public_token.exchange(public_token)
|
response = self.client.Item.public_token.exchange(public_token)
|
||||||
access_token = response['access_token']
|
access_token = response['access_token']
|
||||||
|
|
||||||
@@ -68,10 +67,10 @@ class PlaidConnector():
|
|||||||
account_ids = [account_id]
|
account_ids = [account_id]
|
||||||
|
|
||||||
response = self.client.Transactions.get(self.access_token, start_date=start_date, end_date=end_date, account_ids=account_ids)
|
response = self.client.Transactions.get(self.access_token, start_date=start_date, end_date=end_date, account_ids=account_ids)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
response = self.client.Transactions.get(self.access_token, start_date=start_date, end_date=end_date)
|
response = self.client.Transactions.get(self.access_token, start_date=start_date, end_date=end_date)
|
||||||
|
|
||||||
transactions = response['transactions']
|
transactions = response['transactions']
|
||||||
|
|
||||||
while len(transactions) < response['total_transactions']:
|
while len(transactions) < response['total_transactions']:
|
||||||
|
|||||||
@@ -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');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -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())
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
Reference in New Issue
Block a user