fix: Linter and incorrect cost center in test records
diff --git a/erpnext/accounts/doctype/dunning/dunning.py b/erpnext/accounts/doctype/dunning/dunning.py
index 719f369..e0d75d3 100644
--- a/erpnext/accounts/doctype/dunning/dunning.py
+++ b/erpnext/accounts/doctype/dunning/dunning.py
@@ -23,7 +23,6 @@
class Dunning(AccountsController):
-
def validate(self):
self.validate_same_currency()
self.validate_overdue_payments()
@@ -37,7 +36,11 @@
for row in self.overdue_payments:
invoice_currency = frappe.get_value("Sales Invoice", row.sales_invoice, "currency")
if invoice_currency != self.currency:
- frappe.throw(_("The currency of invoice {} ({}) is different from the currency of this dunning ({}).").format(row.sales_invoice, invoice_currency, self.currency))
+ frappe.throw(
+ _(
+ "The currency of invoice {} ({}) is different from the currency of this dunning ({})."
+ ).format(row.sales_invoice, invoice_currency, self.currency)
+ )
def validate_overdue_payments(self):
daily_interest = self.rate_of_interest / 100 / 365
@@ -55,12 +58,13 @@
def set_dunning_level(self):
for row in self.overdue_payments:
- past_dunnings = frappe.get_all("Overdue Payment",
+ past_dunnings = frappe.get_all(
+ "Overdue Payment",
filters={
"payment_schedule": row.payment_schedule,
"parent": ("!=", row.parent),
- "docstatus": 1
- }
+ "docstatus": 1,
+ },
)
row.dunning_level = len(past_dunnings) + 1
@@ -72,21 +76,26 @@
"""
for reference in doc.references:
if reference.reference_doctype == "Sales Invoice" and reference.outstanding_amount <= 0:
- unresolved_dunnings = frappe.get_all("Dunning",
+ unresolved_dunnings = frappe.get_all(
+ "Dunning",
filters={
"sales_invoice": reference.reference_name,
"status": ("!=", "Resolved"),
"docstatus": ("!=", 2),
},
- pluck="name"
+ pluck="name",
)
for dunning_name in unresolved_dunnings:
resolve = True
dunning = frappe.get_doc("Dunning", dunning_name)
for overdue_payment in dunning.overdue_payments:
- outstanding_inv = frappe.get_value("Sales Invoice", overdue_payment.sales_invoice, "outstanding_amount")
- outstanding_ps = frappe.get_value("Payment Schedule", overdue_payment.payment_schedule, "outstanding")
+ outstanding_inv = frappe.get_value(
+ "Sales Invoice", overdue_payment.sales_invoice, "outstanding_amount"
+ )
+ outstanding_ps = frappe.get_value(
+ "Payment Schedule", overdue_payment.payment_schedule, "outstanding"
+ )
if outstanding_ps > 0 and outstanding_inv > 0:
resolve = False
@@ -95,7 +104,6 @@
dunning.save()
-
@frappe.whitelist()
def get_dunning_letter_text(dunning_type, doc, language=None):
if isinstance(doc, str):
diff --git a/erpnext/accounts/doctype/dunning/test_dunning.py b/erpnext/accounts/doctype/dunning/test_dunning.py
index 6125bd2..be8c533 100644
--- a/erpnext/accounts/doctype/dunning/test_dunning.py
+++ b/erpnext/accounts/doctype/dunning/test_dunning.py
@@ -112,13 +112,16 @@
def get_income_account(company):
- return frappe.get_value("Company", company, "default_income_account") or frappe.get_all(
- "Account",
- filters={"is_group": 0, "company": company},
- or_filters={
- "report_type": "Profit and Loss",
- "account_type": ("in", ("Income Account", "Temporary")),
- },
- limit=1,
- pluck="name",
- )[0]
+ return (
+ frappe.get_value("Company", company, "default_income_account")
+ or frappe.get_all(
+ "Account",
+ filters={"is_group": 0, "company": company},
+ or_filters={
+ "report_type": "Profit and Loss",
+ "account_type": ("in", ("Income Account", "Temporary")),
+ },
+ limit=1,
+ pluck="name",
+ )[0]
+ )
diff --git a/erpnext/accounts/doctype/dunning_type/test_records.json b/erpnext/accounts/doctype/dunning_type/test_records.json
index cb589bf..7f28aab 100644
--- a/erpnext/accounts/doctype/dunning_type/test_records.json
+++ b/erpnext/accounts/doctype/dunning_type/test_records.json
@@ -14,7 +14,7 @@
}
],
"income_account": "Sales - _TC",
- "cost_center": "_Test Cost Center"
+ "cost_center": "_Test Cost Center - _TC"
},
{
"doctype": "Dunning Type",
@@ -31,6 +31,6 @@
}
],
"income_account": "Sales - _TC",
- "cost_center": "_Test Cost Center"
+ "cost_center": "_Test Cost Center - _TC"
}
]
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 090308f..2bd703f 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -1850,22 +1850,28 @@
else:
if dt == "Dunning":
for overdue_payment in doc.overdue_payments:
- pe.append("references", {
- "reference_doctype": "Sales Invoice",
- "reference_name": overdue_payment.sales_invoice,
- "payment_term": overdue_payment.payment_term,
- "due_date": overdue_payment.due_date,
- "total_amount": overdue_payment.outstanding,
- "outstanding_amount": overdue_payment.outstanding,
- "allocated_amount": overdue_payment.outstanding
- })
+ pe.append(
+ "references",
+ {
+ "reference_doctype": "Sales Invoice",
+ "reference_name": overdue_payment.sales_invoice,
+ "payment_term": overdue_payment.payment_term,
+ "due_date": overdue_payment.due_date,
+ "total_amount": overdue_payment.outstanding,
+ "outstanding_amount": overdue_payment.outstanding,
+ "allocated_amount": overdue_payment.outstanding,
+ },
+ )
- pe.append("deductions", {
- "account": doc.income_account,
- "cost_center": doc.cost_center,
- "amount": -1 * doc.dunning_amount,
- "description": _("Interest and/or dunning fee")
- })
+ pe.append(
+ "deductions",
+ {
+ "account": doc.income_account,
+ "cost_center": doc.cost_center,
+ "amount": -1 * doc.dunning_amount,
+ "description": _("Interest and/or dunning fee"),
+ },
+ )
else:
pe.append(
"references",
@@ -1957,8 +1963,10 @@
def set_payment_type(dt, doc):
if (
- dt == "Sales Order" or (dt == "Sales Invoice" and doc.outstanding_amount > 0)
- ) or (dt == "Purchase Invoice" and doc.outstanding_amount < 0) or dt == "Dunning":
+ (dt == "Sales Order" or (dt == "Sales Invoice" and doc.outstanding_amount > 0))
+ or (dt == "Purchase Invoice" and doc.outstanding_amount < 0)
+ or dt == "Dunning"
+ ):
payment_type = "Receive"
else:
payment_type = "Pay"
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index b2cd4a6..e3a159b 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -622,7 +622,9 @@
return
if not self.account_for_change_amount:
- self.account_for_change_amount = frappe.get_cached_value('Company', self.company, 'default_cash_account')
+ self.account_for_change_amount = frappe.get_cached_value(
+ "Company", self.company, "default_cash_account"
+ )
from erpnext.stock.get_item_details import get_pos_profile, get_pos_profile_item_details
@@ -1907,17 +1909,17 @@
@frappe.whitelist()
def make_maintenance_schedule(source_name, target_doc=None):
- doclist = get_mapped_doc("Sales Invoice", source_name, {
- "Sales Invoice": {
- "doctype": "Maintenance Schedule",
- "validation": {
- "docstatus": ["=", 1]
- }
+ doclist = get_mapped_doc(
+ "Sales Invoice",
+ source_name,
+ {
+ "Sales Invoice": {"doctype": "Maintenance Schedule", "validation": {"docstatus": ["=", 1]}},
+ "Sales Invoice Item": {
+ "doctype": "Maintenance Schedule Item",
+ },
},
- "Sales Invoice Item": {
- "doctype": "Maintenance Schedule Item",
- },
- }, target_doc)
+ target_doc,
+ )
return doclist
@@ -2523,9 +2525,7 @@
target.income_account = dunning_type.income_account
target.cost_center = dunning_type.cost_center
letter_text = get_dunning_letter_text(
- dunning_type=dunning_type.name,
- doc=target.as_dict(),
- language=source.language
+ dunning_type=dunning_type.name, doc=target.as_dict(), language=source.language
)
if letter_text:
@@ -2542,26 +2542,19 @@
table_maps={
"Sales Invoice": {
"doctype": "Dunning",
- "field_map": {
- "customer_address": "customer_address",
- "parent": "sales_invoice"
- },
+ "field_map": {"customer_address": "customer_address", "parent": "sales_invoice"},
},
"Payment Schedule": {
"doctype": "Overdue Payment",
- "field_map": {
- "name": "payment_schedule",
- "parent": "sales_invoice"
- },
+ "field_map": {"name": "payment_schedule", "parent": "sales_invoice"},
"condition": lambda doc: doc.outstanding > 0 and getdate(doc.due_date) < getdate(),
- }
+ },
},
postprocess=postprocess_dunning,
- ignore_permissions=ignore_permissions
+ ignore_permissions=ignore_permissions,
)
-
def check_if_return_invoice_linked_with_payment_entry(self):
# If a Return invoice is linked with payment entry along with other invoices,
# the cancellation of the Return causes allocated amount to be greater than paid
diff --git a/erpnext/patches/v14_0/single_to_multi_dunning.py b/erpnext/patches/v14_0/single_to_multi_dunning.py
index 90966aa..7a8e591 100644
--- a/erpnext/patches/v14_0/single_to_multi_dunning.py
+++ b/erpnext/patches/v14_0/single_to_multi_dunning.py
@@ -18,7 +18,8 @@
# something's already here, doesn't need patching
continue
- payment_schedules = frappe.get_all("Payment Schedule",
+ payment_schedules = frappe.get_all(
+ "Payment Schedule",
filters={"parent": dunning.sales_invoice},
fields=[
"parent as sales_invoice",
@@ -30,8 +31,8 @@
# at the time of creating this dunning, the full amount was outstanding
"payment_amount as outstanding",
"'0' as paid_amount",
- "discounted_amount"
- ]
+ "discounted_amount",
+ ],
)
dunning.extend("overdue_payments", payment_schedules)