Skip to content

Commit

Permalink
Merge branch 'develop' into ss-test-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal authored May 2, 2022
2 parents d636fb0 + f8db6f0 commit 07274b5
Show file tree
Hide file tree
Showing 524 changed files with 544 additions and 27,999 deletions.
19 changes: 3 additions & 16 deletions erpnext/accounts/deferred_revenue.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,19 +539,11 @@ def make_gl_entries(
frappe.db.commit()
except Exception as e:
if frappe.flags.in_test:
traceback = frappe.get_traceback()
frappe.log_error(
title=_("Error while processing deferred accounting for Invoice {0}").format(doc.name),
message=traceback,
)
doc.log_error(f"Error while processing deferred accounting for Invoice {doc.name}")
raise e
else:
frappe.db.rollback()
traceback = frappe.get_traceback()
frappe.log_error(
title=_("Error while processing deferred accounting for Invoice {0}").format(doc.name),
message=traceback,
)
doc.log_error(f"Error while processing deferred accounting for Invoice {doc.name}")
frappe.flags.deferred_accounting_error = True


Expand Down Expand Up @@ -632,12 +624,7 @@ def book_revenue_via_journal_entry(
frappe.db.commit()
except Exception:
frappe.db.rollback()
traceback = frappe.get_traceback()
frappe.log_error(
title=_("Error while processing deferred accounting for Invoice {0}").format(doc.name),
message=traceback,
)

doc.log_error(f"Error while processing deferred accounting for Invoice {doc.name}")
frappe.flags.deferred_accounting_error = True


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def start_import(
except Exception:
frappe.db.rollback()
data_import.db_set("status", "Error")
frappe.log_error(title=data_import.name)
data_import.log_error("Bank Statement Import failed")
finally:
frappe.flags.in_import = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def create_bank_entries(columns, data, bank_account):
bank_transaction.submit()
success += 1
except Exception:
frappe.log_error(frappe.get_traceback())
bank_transaction.log_error("Bank entry creation failed")
errors += 1

return {"success": success, "errors": errors}
Expand Down
2 changes: 1 addition & 1 deletion erpnext/accounts/doctype/ledger_merge/ledger_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def start_merge(docname):
)
except Exception:
frappe.db.rollback()
frappe.log_error(title=ledger_merge.name)
ledger_merge.log_error("Ledger merge failed")
finally:
if successful_merges == total:
ledger_merge.db_set("status", "Success")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
# For license information, please see license.txt


import traceback
from json import dumps

import frappe
from frappe import _, scrub
from frappe.model.document import Document
Expand Down Expand Up @@ -247,11 +244,7 @@ def start_import(invoices):
except Exception:
errors += 1
frappe.db.rollback()
message = "\n".join(
["Data:", dumps(d, default=str, indent=4), "--" * 50, "\nException:", traceback.format_exc()]
)
frappe.log_error(title="Error while creating Opening Invoice", message=message)
frappe.db.commit()
doc.log_error("Opening invoice creation failed")
if errors:
frappe.msgprint(
_("You had {} errors while creating opening invoices. Check {} for more details").format(
Expand Down
8 changes: 2 additions & 6 deletions erpnext/accounts/doctype/payment_entry/payment_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ frappe.ui.form.on('Payment Entry', {
var doctypes = ["Purchase Order", "Purchase Invoice", "Journal Entry"];
} else if (frm.doc.party_type == "Employee") {
var doctypes = ["Expense Claim", "Journal Entry"];
} else if (frm.doc.party_type == "Student") {
var doctypes = ["Fees"];
} else {
var doctypes = ["Journal Entry"];
}
Expand Down Expand Up @@ -755,8 +753,7 @@ frappe.ui.form.on('Payment Entry', {
if(
(frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") ||
(frm.doc.payment_type=="Pay" && frm.doc.party_type=="Supplier") ||
(frm.doc.payment_type=="Pay" && frm.doc.party_type=="Employee") ||
(frm.doc.payment_type=="Receive" && frm.doc.party_type=="Student")
(frm.doc.payment_type=="Pay" && frm.doc.party_type=="Employee")
) {
if(total_positive_outstanding > total_negative_outstanding)
if (!frm.doc.paid_amount)
Expand Down Expand Up @@ -798,8 +795,7 @@ frappe.ui.form.on('Payment Entry', {
if (
(frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") ||
(frm.doc.payment_type=="Pay" && frm.doc.party_type=="Supplier") ||
(frm.doc.payment_type=="Pay" && frm.doc.party_type=="Employee") ||
(frm.doc.payment_type=="Receive" && frm.doc.party_type=="Student")
(frm.doc.payment_type=="Pay" && frm.doc.party_type=="Employee")
) {
if(total_positive_outstanding_including_order > paid_amount) {
var remaining_outstanding = total_positive_outstanding_including_order - paid_amount;
Expand Down
39 changes: 14 additions & 25 deletions erpnext/accounts/doctype/payment_entry/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ def set_missing_values(self):
if not self.party:
frappe.throw(_("Party is mandatory"))

_party_name = (
"title" if self.party_type in ("Student", "Shareholder") else self.party_type.lower() + "_name"
)
_party_name = "title" if self.party_type == "Shareholder" else self.party_type.lower() + "_name"
self.party_name = frappe.db.get_value(self.party_type, self.party, _party_name)

if self.party:
Expand Down Expand Up @@ -298,9 +296,7 @@ def validate_mandatory(self):
frappe.throw(_("{0} is mandatory").format(self.meta.get_label(field)))

def validate_reference_documents(self):
if self.party_type == "Student":
valid_reference_doctypes = "Fees"
elif self.party_type == "Customer":
if self.party_type == "Customer":
valid_reference_doctypes = ("Sales Order", "Sales Invoice", "Journal Entry", "Dunning")
elif self.party_type == "Supplier":
valid_reference_doctypes = ("Purchase Order", "Purchase Invoice", "Journal Entry")
Expand Down Expand Up @@ -338,8 +334,6 @@ def validate_reference_documents(self):
ref_party_account = (
get_party_account_based_on_invoice_discounting(d.reference_name) or ref_doc.debit_to
)
elif self.party_type == "Student":
ref_party_account = ref_doc.receivable_account
elif self.party_type == "Supplier":
ref_party_account = ref_doc.credit_to
elif self.party_type == "Employee":
Expand Down Expand Up @@ -1259,20 +1253,19 @@ def get_outstanding_reference_documents(args):

# Get all SO / PO which are not fully billed or against which full advance not paid
orders_to_be_billed = []
if args.get("party_type") != "Student":
orders_to_be_billed = get_orders_to_be_billed(
args.get("posting_date"),
args.get("party_type"),
args.get("party"),
args.get("company"),
party_account_currency,
company_currency,
filters=args,
)
orders_to_be_billed = get_orders_to_be_billed(
args.get("posting_date"),
args.get("party_type"),
args.get("party"),
args.get("company"),
party_account_currency,
company_currency,
filters=args,
)

# Get negative outstanding sales /purchase invoices
negative_outstanding_invoices = []
if args.get("party_type") not in ["Student", "Employee"] and not args.get("voucher_no"):
if args.get("party_type") != "Employee" and not args.get("voucher_no"):
negative_outstanding_invoices = get_negative_outstanding_invoices(
args.get("party_type"),
args.get("party"),
Expand Down Expand Up @@ -1496,9 +1489,7 @@ def get_party_details(company, party_type, party, date, cost_center=None):

account_currency = get_account_currency(party_account)
account_balance = get_balance_on(party_account, date, cost_center=cost_center)
_party_name = (
"title" if party_type in ("Student", "Shareholder") else party_type.lower() + "_name"
)
_party_name = "title" if party_type == "Shareholder" else party_type.lower() + "_name"
party_name = frappe.db.get_value(party_type, party, _party_name)
party_balance = get_balance_on(party_type=party_type, party=party, cost_center=cost_center)
if party_type in ["Customer", "Supplier"]:
Expand Down Expand Up @@ -1560,7 +1551,7 @@ def get_company_defaults(company):
def get_outstanding_on_journal_entry(name):
res = frappe.db.sql(
"SELECT "
'CASE WHEN party_type IN ("Customer", "Student") '
'CASE WHEN party_type IN ("Customer") '
"THEN ifnull(sum(debit_in_account_currency - credit_in_account_currency), 0) "
"ELSE ifnull(sum(credit_in_account_currency - debit_in_account_currency), 0) "
"END as outstanding_amount "
Expand Down Expand Up @@ -1917,8 +1908,6 @@ def set_party_type(dt):
party_type = "Supplier"
elif dt in ("Expense Claim", "Employee Advance", "Gratuity"):
party_type = "Employee"
elif dt == "Fees":
party_type = "Student"
return party_type


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
]
};
});

this.frm.set_query("cost_center", () => {
return {
"filters": {
"company": this.frm.doc.company,
"is_group": 0
}
}
});
}

refresh() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"invoice_limit",
"payment_limit",
"bank_cash_account",
"cost_center",
"sec_break1",
"invoices",
"column_break_15",
Expand Down Expand Up @@ -178,13 +179,19 @@
{
"fieldname": "column_break_11",
"fieldtype": "Column Break"
},
{
"fieldname": "cost_center",
"fieldtype": "Link",
"label": "Cost Center",
"options": "Cost Center"
}
],
"hide_toolbar": 1,
"icon": "icon-resize-horizontal",
"issingle": 1,
"links": [],
"modified": "2021-10-04 20:27:11.114194",
"modified": "2022-04-29 15:37:10.246831",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Reconciliation",
Expand All @@ -209,5 +216,6 @@
],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ def validate_allocation(self):
def get_conditions(self, get_invoices=False, get_payments=False, get_return_invoices=False):
condition = " and company = '{0}' ".format(self.company)

if self.get("cost_center") and (get_invoices or get_payments or get_return_invoices):
condition = " and cost_center = '{0}' ".format(self.cost_center)

if get_invoices:
condition += (
" and posting_date >= {0}".format(frappe.db.escape(self.from_invoice_date))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,96 @@
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt

# import frappe
import unittest

import frappe
from frappe.utils import add_days, getdate

from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice


class TestPaymentReconciliation(unittest.TestCase):
pass
@classmethod
def setUpClass(cls):
make_customer()
make_invoice_and_payment()

def test_payment_reconciliation(self):
payment_reco = frappe.get_doc("Payment Reconciliation")
payment_reco.company = "_Test Company"
payment_reco.party_type = "Customer"
payment_reco.party = "_Test Payment Reco Customer"
payment_reco.receivable_payable_account = "Debtors - _TC"
payment_reco.from_invoice_date = add_days(getdate(), -1)
payment_reco.to_invoice_date = getdate()
payment_reco.from_payment_date = add_days(getdate(), -1)
payment_reco.to_payment_date = getdate()
payment_reco.maximum_invoice_amount = 1000
payment_reco.maximum_payment_amount = 1000
payment_reco.invoice_limit = 10
payment_reco.payment_limit = 10
payment_reco.bank_cash_account = "_Test Bank - _TC"
payment_reco.cost_center = "_Test Cost Center - _TC"
payment_reco.get_unreconciled_entries()

self.assertEqual(len(payment_reco.get("invoices")), 1)
self.assertEqual(len(payment_reco.get("payments")), 1)

payment_entry = payment_reco.get("payments")[0].reference_name
invoice = payment_reco.get("invoices")[0].invoice_number

payment_reco.allocate_entries(
{
"payments": [payment_reco.get("payments")[0].as_dict()],
"invoices": [payment_reco.get("invoices")[0].as_dict()],
}
)
payment_reco.reconcile()

payment_entry_doc = frappe.get_doc("Payment Entry", payment_entry)
self.assertEqual(payment_entry_doc.get("references")[0].reference_name, invoice)


def make_customer():
if not frappe.db.get_value("Customer", "_Test Payment Reco Customer"):
frappe.get_doc(
{
"doctype": "Customer",
"customer_name": "_Test Payment Reco Customer",
"customer_type": "Individual",
"customer_group": "_Test Customer Group",
"territory": "_Test Territory",
}
).insert()


def make_invoice_and_payment():
si = create_sales_invoice(
customer="_Test Payment Reco Customer", qty=1, rate=690, do_not_save=True
)
si.cost_center = "_Test Cost Center - _TC"
si.save()
si.submit()

pe = frappe.get_doc(
{
"doctype": "Payment Entry",
"payment_type": "Receive",
"party_type": "Customer",
"party": "_Test Payment Reco Customer",
"company": "_Test Company",
"paid_from_account_currency": "INR",
"paid_to_account_currency": "INR",
"source_exchange_rate": 1,
"target_exchange_rate": 1,
"reference_no": "1",
"reference_date": getdate(),
"received_amount": 690,
"paid_amount": 690,
"paid_from": "Debtors - _TC",
"paid_to": "_Test Bank - _TC",
"cost_center": "_Test Cost Center - _TC",
}
)
pe.insert()
pe.submit()
4 changes: 1 addition & 3 deletions erpnext/accounts/doctype/subscription/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,7 @@ def process(data):
frappe.db.commit()
except frappe.ValidationError:
frappe.db.rollback()
frappe.db.begin()
frappe.log_error(frappe.get_traceback())
frappe.db.commit()
subscription.log_error("Subscription failed")


@frappe.whitelist()
Expand Down
2 changes: 1 addition & 1 deletion erpnext/accounts/report/general_ledger/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def set_account_currency(filters):
else:
account_currency = (
None
if filters.party_type in ["Employee", "Student", "Shareholder", "Member"]
if filters.party_type in ["Employee", "Shareholder", "Member"]
else frappe.db.get_value(filters.party_type, filters.party[0], "default_currency")
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ def execute(filters=None):
def get_data(filters, show_party_name):
if filters.get("party_type") in ("Customer", "Supplier", "Employee", "Member"):
party_name_field = "{0}_name".format(frappe.scrub(filters.get("party_type")))
elif filters.get("party_type") == "Student":
party_name_field = "first_name"
elif filters.get("party_type") == "Shareholder":
party_name_field = "title"
else:
Expand Down
Loading

0 comments on commit 07274b5

Please sign in to comment.