Skip to content

Commit

Permalink
[Backport staging] Correcciones de conciliación bancaria (#62)
Browse files Browse the repository at this point in the history
* trans: columns names in table

* trans: table row

* trans: table row

* trans: table row

* trans: table row

* fix: apply frappe#29098

* fix: apply frappe#29366

* fix: apply frappe#28996

* trans: fix

* trans: action in bank transaction tool

* trans: fix
  • Loading branch information
fproldan authored Jan 31, 2022
1 parent 106f3ef commit 46e7082
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ frappe.ui.form.on("Bank Reconciliation Tool", {
frm.set_query("bank_account", function () {
return {
filters: {
company: ["in", frm.doc.company],
company: frm.doc.company,
'is_company_account': 1
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ def reconcile_vouchers(bank_transaction_name, vouchers):
# updated clear date of all the vouchers based on the bank transaction
vouchers = json.loads(vouchers)
transaction = frappe.get_doc("Bank Transaction", bank_transaction_name)
company_account = frappe.db.get_value('Bank Account', transaction.bank_account, 'account')

if transaction.unallocated_amount == 0:
frappe.throw(_("This bank transaction is already fully reconciled"))
total_amount = 0
Expand All @@ -229,7 +231,7 @@ def reconcile_vouchers(bank_transaction_name, vouchers):
total_amount += get_paid_amount(frappe._dict({
'payment_document': voucher['payment_doctype'],
'payment_entry': voucher['payment_name'],
}), transaction.currency)
}), transaction.currency, company_account)

if total_amount > transaction.unallocated_amount:
frappe.throw(_("The Sum Total of Amounts of All Selected Vouchers Should be Less than the Unallocated Amount of the Bank Transaction"))
Expand Down Expand Up @@ -264,7 +266,7 @@ def get_linked_payments(bank_transaction_name, document_types = None):
return matching

def check_matching(bank_account, company, transaction, document_types):
# combine all types of vocuhers
# combine all types of vouchers
subquery = get_queries(bank_account, company, transaction, document_types)
filters = {
"amount": transaction.unallocated_amount,
Expand Down Expand Up @@ -345,6 +347,10 @@ def get_pe_matching_query(amount_condition, account_from_to, transaction):

def get_je_matching_query(amount_condition, transaction):
# get matching journal entry query

# We have mapping at the bank level
# So one bank could have both types of bank accounts like asset and liability
# So cr_or_dr should be judged only on basis of withdrawal and deposit and not account type
cr_or_dr = "credit" if transaction.withdrawal > 0 else "debit"
return f"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,13 @@ frappe.ui.form.on("Bank Statement Import", {
if (frm.doc.import_type === "Insert New Records") {
message =
successful_records.length > 1
? __(
"Successfully imported {0} records out of {1}. Click on Export Errored Rows, fix the errors and import again.",
message_args
)
: __(
"Successfully imported {0} record out of {1}. Click on Export Errored Rows, fix the errors and import again.",
message_args
);
? __("Successfully imported {0} records out of {1}. Click on Export Errored Rows, fix the errors and import again.", message_args)
: __("Successfully imported {0} record out of {1}. Click on Export Errored Rows, fix the errors and import again.", message_args);
} else {
message =
successful_records.length > 1
? __(
"Successfully updated {0} records out of {1}. Click on Export Errored Rows, fix the errors and import again.",
message_args
)
: __(
"Successfully updated {0} record out of {1}. Click on Export Errored Rows, fix the errors and import again.",
message_args
);
? __("Successfully updated {0} records out of {1}. Click on Export Errored Rows, fix the errors and import again.", message_args)
: __("Successfully updated {0} record out of {1}. Click on Export Errored Rows, fix the errors and import again.", message_args);
}
}
frm.dashboard.set_headline(message);
Expand Down Expand Up @@ -453,25 +441,9 @@ frappe.ui.form.on("Bank Statement Import", {
let html = "";
if (log.success) {
if (frm.doc.import_type === "Insert New Records") {
html = __(
"Successfully imported {0}", [
`<span class="underline">${frappe.utils.get_form_link(
frm.doc.reference_doctype,
log.docname,
true
)}<span>`,
]
);
html = __("Successfully imported {0}", [`<span class="underline">${frappe.utils.get_form_link(frm.doc.reference_doctype,log.docname,true)}<span>`,]);
} else {
html = __(
"Successfully updated {0}", [
`<span class="underline">${frappe.utils.get_form_link(
frm.doc.reference_doctype,
log.docname,
true
)}<span>`,
]
);
html = __("Successfully updated {0}", [`<span class="underline">${frappe.utils.get_form_link(frm.doc.reference_doctype, log.docname, true)}<span>`,]);
}
} else {
let messages = log.messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from openpyxl.utils import get_column_letter
from six import string_types

INVALID_VALUES = ("", None)


class BankStatementImport(DataImport):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -83,6 +85,20 @@ def start_import(self):

return False


def parse_data_from_template(raw_data):
data = []

for i, row in enumerate(raw_data):
if all(v in INVALID_VALUES for v in row):
# empty row
continue

data.append(row)

return data


@frappe.whitelist()
def get_preview_from_template(data_import, import_file=None, google_sheets_url=None):
return frappe.get_doc("Bank Statement Import", data_import).get_preview_from_template(
Expand All @@ -107,7 +123,8 @@ def start_import(data_import, bank_account, import_file_path, google_sheets_url,
file = import_file_path if import_file_path else google_sheets_url

import_file = ImportFile("Bank Transaction", file = file, import_type="Insert New Records")
data = import_file.raw_data

data = parse_data_from_template(import_file.raw_data)

if import_file_path:
add_bank_account(data, bank_account)
Expand Down
4 changes: 2 additions & 2 deletions erpnext/accounts/doctype/bank_transaction/bank_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def get_total_allocated_amount(payment_entry):
AND
bt.docstatus = 1""", (payment_entry.payment_document, payment_entry.payment_entry), as_dict=True)

def get_paid_amount(payment_entry, currency):
def get_paid_amount(payment_entry, currency, bank_account):
if payment_entry.payment_document in ["Payment Entry", "Sales Invoice", "Purchase Invoice"]:

paid_amount_field = "paid_amount"
Expand All @@ -117,7 +117,7 @@ def get_paid_amount(payment_entry, currency):
payment_entry.payment_entry, paid_amount_field)

elif payment_entry.payment_document == "Journal Entry":
return frappe.db.get_value(payment_entry.payment_document, payment_entry.payment_entry, "total_credit")
return frappe.db.get_value('Journal Entry Account', {'parent': payment_entry.payment_entry, 'account': bank_account}, "sum(credit_in_account_currency)")

elif payment_entry.payment_document == "Expense Claim":
return frappe.db.get_value(payment_entry.payment_document, payment_entry.payment_entry, "total_amount_reimbursed")
Expand Down
22 changes: 11 additions & 11 deletions erpnext/public/js/bank_reconciliation_tool/data_table_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,28 @@ erpnext.accounts.bank_reconciliation.DataTableManager = class DataTableManager {
get_dt_columns() {
this.columns = [
{
name: "Date",
name: __("Date"),
editable: false,
width: 100,
},

{
name: "Party Type",
name: __("Party Type"),
editable: false,
width: 95,
},
{
name: "Party",
name: __("Party"),
editable: false,
width: 100,
},
{
name: "Description",
name: __("Description"),
editable: false,
width: 350,
},
{
name: "Deposit",
name: __("Deposit"),
editable: false,
width: 100,
format: (value) =>
Expand All @@ -60,7 +60,7 @@ erpnext.accounts.bank_reconciliation.DataTableManager = class DataTableManager {
"</span>",
},
{
name: "Withdrawal",
name: __("Withdrawal"),
editable: false,
width: 100,
format: (value) =>
Expand All @@ -69,7 +69,7 @@ erpnext.accounts.bank_reconciliation.DataTableManager = class DataTableManager {
"</span>",
},
{
name: "Unallocated Amount",
name: __("Unallocated Amount"),
editable: false,
width: 100,
format: (value) =>
Expand All @@ -78,12 +78,12 @@ erpnext.accounts.bank_reconciliation.DataTableManager = class DataTableManager {
"</span>",
},
{
name: "Reference Number",
name: __("Reference Number"),
editable: false,
width: 140,
},
{
name: "Actions",
name: __("Actions"),
editable: false,
sortable: false,
focusable: false,
Expand All @@ -109,8 +109,8 @@ erpnext.accounts.bank_reconciliation.DataTableManager = class DataTableManager {
format_row(row) {
return [
row["date"],
row["party_type"],
row["party"],
__(row["party_type"]),
__(row["party"]),
row["description"],
row["deposit"],
row["withdrawal"],
Expand Down
Loading

0 comments on commit 46e7082

Please sign in to comment.