fix: Linter and incorrect cost center in test records
This commit is contained in:
parent
18495ed624
commit
772f6ffd21
@ -23,7 +23,6 @@ from erpnext.controllers.accounts_controller import AccountsController
|
|||||||
|
|
||||||
|
|
||||||
class Dunning(AccountsController):
|
class Dunning(AccountsController):
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.validate_same_currency()
|
self.validate_same_currency()
|
||||||
self.validate_overdue_payments()
|
self.validate_overdue_payments()
|
||||||
@ -37,7 +36,11 @@ class Dunning(AccountsController):
|
|||||||
for row in self.overdue_payments:
|
for row in self.overdue_payments:
|
||||||
invoice_currency = frappe.get_value("Sales Invoice", row.sales_invoice, "currency")
|
invoice_currency = frappe.get_value("Sales Invoice", row.sales_invoice, "currency")
|
||||||
if invoice_currency != self.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):
|
def validate_overdue_payments(self):
|
||||||
daily_interest = self.rate_of_interest / 100 / 365
|
daily_interest = self.rate_of_interest / 100 / 365
|
||||||
@ -55,12 +58,13 @@ class Dunning(AccountsController):
|
|||||||
|
|
||||||
def set_dunning_level(self):
|
def set_dunning_level(self):
|
||||||
for row in self.overdue_payments:
|
for row in self.overdue_payments:
|
||||||
past_dunnings = frappe.get_all("Overdue Payment",
|
past_dunnings = frappe.get_all(
|
||||||
|
"Overdue Payment",
|
||||||
filters={
|
filters={
|
||||||
"payment_schedule": row.payment_schedule,
|
"payment_schedule": row.payment_schedule,
|
||||||
"parent": ("!=", row.parent),
|
"parent": ("!=", row.parent),
|
||||||
"docstatus": 1
|
"docstatus": 1,
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
row.dunning_level = len(past_dunnings) + 1
|
row.dunning_level = len(past_dunnings) + 1
|
||||||
|
|
||||||
@ -72,21 +76,26 @@ def resolve_dunning(doc, state):
|
|||||||
"""
|
"""
|
||||||
for reference in doc.references:
|
for reference in doc.references:
|
||||||
if reference.reference_doctype == "Sales Invoice" and reference.outstanding_amount <= 0:
|
if reference.reference_doctype == "Sales Invoice" and reference.outstanding_amount <= 0:
|
||||||
unresolved_dunnings = frappe.get_all("Dunning",
|
unresolved_dunnings = frappe.get_all(
|
||||||
|
"Dunning",
|
||||||
filters={
|
filters={
|
||||||
"sales_invoice": reference.reference_name,
|
"sales_invoice": reference.reference_name,
|
||||||
"status": ("!=", "Resolved"),
|
"status": ("!=", "Resolved"),
|
||||||
"docstatus": ("!=", 2),
|
"docstatus": ("!=", 2),
|
||||||
},
|
},
|
||||||
pluck="name"
|
pluck="name",
|
||||||
)
|
)
|
||||||
|
|
||||||
for dunning_name in unresolved_dunnings:
|
for dunning_name in unresolved_dunnings:
|
||||||
resolve = True
|
resolve = True
|
||||||
dunning = frappe.get_doc("Dunning", dunning_name)
|
dunning = frappe.get_doc("Dunning", dunning_name)
|
||||||
for overdue_payment in dunning.overdue_payments:
|
for overdue_payment in dunning.overdue_payments:
|
||||||
outstanding_inv = frappe.get_value("Sales Invoice", overdue_payment.sales_invoice, "outstanding_amount")
|
outstanding_inv = frappe.get_value(
|
||||||
outstanding_ps = frappe.get_value("Payment Schedule", overdue_payment.payment_schedule, "outstanding")
|
"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:
|
if outstanding_ps > 0 and outstanding_inv > 0:
|
||||||
resolve = False
|
resolve = False
|
||||||
|
|
||||||
@ -95,7 +104,6 @@ def resolve_dunning(doc, state):
|
|||||||
dunning.save()
|
dunning.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_dunning_letter_text(dunning_type, doc, language=None):
|
def get_dunning_letter_text(dunning_type, doc, language=None):
|
||||||
if isinstance(doc, str):
|
if isinstance(doc, str):
|
||||||
|
@ -112,7 +112,9 @@ def create_dunning_type(title, fee, interest, is_default):
|
|||||||
|
|
||||||
|
|
||||||
def get_income_account(company):
|
def get_income_account(company):
|
||||||
return frappe.get_value("Company", company, "default_income_account") or frappe.get_all(
|
return (
|
||||||
|
frappe.get_value("Company", company, "default_income_account")
|
||||||
|
or frappe.get_all(
|
||||||
"Account",
|
"Account",
|
||||||
filters={"is_group": 0, "company": company},
|
filters={"is_group": 0, "company": company},
|
||||||
or_filters={
|
or_filters={
|
||||||
@ -122,3 +124,4 @@ def get_income_account(company):
|
|||||||
limit=1,
|
limit=1,
|
||||||
pluck="name",
|
pluck="name",
|
||||||
)[0]
|
)[0]
|
||||||
|
)
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"income_account": "Sales - _TC",
|
"income_account": "Sales - _TC",
|
||||||
"cost_center": "_Test Cost Center"
|
"cost_center": "_Test Cost Center - _TC"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Dunning Type",
|
"doctype": "Dunning Type",
|
||||||
@ -31,6 +31,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"income_account": "Sales - _TC",
|
"income_account": "Sales - _TC",
|
||||||
"cost_center": "_Test Cost Center"
|
"cost_center": "_Test Cost Center - _TC"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -1850,22 +1850,28 @@ def get_payment_entry(
|
|||||||
else:
|
else:
|
||||||
if dt == "Dunning":
|
if dt == "Dunning":
|
||||||
for overdue_payment in doc.overdue_payments:
|
for overdue_payment in doc.overdue_payments:
|
||||||
pe.append("references", {
|
pe.append(
|
||||||
|
"references",
|
||||||
|
{
|
||||||
"reference_doctype": "Sales Invoice",
|
"reference_doctype": "Sales Invoice",
|
||||||
"reference_name": overdue_payment.sales_invoice,
|
"reference_name": overdue_payment.sales_invoice,
|
||||||
"payment_term": overdue_payment.payment_term,
|
"payment_term": overdue_payment.payment_term,
|
||||||
"due_date": overdue_payment.due_date,
|
"due_date": overdue_payment.due_date,
|
||||||
"total_amount": overdue_payment.outstanding,
|
"total_amount": overdue_payment.outstanding,
|
||||||
"outstanding_amount": overdue_payment.outstanding,
|
"outstanding_amount": overdue_payment.outstanding,
|
||||||
"allocated_amount": overdue_payment.outstanding
|
"allocated_amount": overdue_payment.outstanding,
|
||||||
})
|
},
|
||||||
|
)
|
||||||
|
|
||||||
pe.append("deductions", {
|
pe.append(
|
||||||
|
"deductions",
|
||||||
|
{
|
||||||
"account": doc.income_account,
|
"account": doc.income_account,
|
||||||
"cost_center": doc.cost_center,
|
"cost_center": doc.cost_center,
|
||||||
"amount": -1 * doc.dunning_amount,
|
"amount": -1 * doc.dunning_amount,
|
||||||
"description": _("Interest and/or dunning fee")
|
"description": _("Interest and/or dunning fee"),
|
||||||
})
|
},
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
pe.append(
|
pe.append(
|
||||||
"references",
|
"references",
|
||||||
@ -1957,8 +1963,10 @@ def set_party_account_currency(dt, party_account, doc):
|
|||||||
|
|
||||||
def set_payment_type(dt, doc):
|
def set_payment_type(dt, doc):
|
||||||
if (
|
if (
|
||||||
dt == "Sales Order" or (dt == "Sales Invoice" and doc.outstanding_amount > 0)
|
(dt == "Sales Order" or (dt == "Sales Invoice" and doc.outstanding_amount > 0))
|
||||||
) or (dt == "Purchase Invoice" and doc.outstanding_amount < 0) or dt == "Dunning":
|
or (dt == "Purchase Invoice" and doc.outstanding_amount < 0)
|
||||||
|
or dt == "Dunning"
|
||||||
|
):
|
||||||
payment_type = "Receive"
|
payment_type = "Receive"
|
||||||
else:
|
else:
|
||||||
payment_type = "Pay"
|
payment_type = "Pay"
|
||||||
|
@ -622,7 +622,9 @@ class SalesInvoice(SellingController):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if not self.account_for_change_amount:
|
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
|
from erpnext.stock.get_item_details import get_pos_profile, get_pos_profile_item_details
|
||||||
|
|
||||||
@ -1907,17 +1909,17 @@ def get_bank_cash_account(mode_of_payment, company):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_maintenance_schedule(source_name, target_doc=None):
|
def make_maintenance_schedule(source_name, target_doc=None):
|
||||||
doclist = get_mapped_doc("Sales Invoice", source_name, {
|
doclist = get_mapped_doc(
|
||||||
"Sales Invoice": {
|
"Sales Invoice",
|
||||||
"doctype": "Maintenance Schedule",
|
source_name,
|
||||||
"validation": {
|
{
|
||||||
"docstatus": ["=", 1]
|
"Sales Invoice": {"doctype": "Maintenance Schedule", "validation": {"docstatus": ["=", 1]}},
|
||||||
}
|
|
||||||
},
|
|
||||||
"Sales Invoice Item": {
|
"Sales Invoice Item": {
|
||||||
"doctype": "Maintenance Schedule Item",
|
"doctype": "Maintenance Schedule Item",
|
||||||
},
|
},
|
||||||
}, target_doc)
|
},
|
||||||
|
target_doc,
|
||||||
|
)
|
||||||
|
|
||||||
return doclist
|
return doclist
|
||||||
|
|
||||||
@ -2523,9 +2525,7 @@ def create_dunning(source_name, target_doc=None, ignore_permissions=False):
|
|||||||
target.income_account = dunning_type.income_account
|
target.income_account = dunning_type.income_account
|
||||||
target.cost_center = dunning_type.cost_center
|
target.cost_center = dunning_type.cost_center
|
||||||
letter_text = get_dunning_letter_text(
|
letter_text = get_dunning_letter_text(
|
||||||
dunning_type=dunning_type.name,
|
dunning_type=dunning_type.name, doc=target.as_dict(), language=source.language
|
||||||
doc=target.as_dict(),
|
|
||||||
language=source.language
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if letter_text:
|
if letter_text:
|
||||||
@ -2542,26 +2542,19 @@ def create_dunning(source_name, target_doc=None, ignore_permissions=False):
|
|||||||
table_maps={
|
table_maps={
|
||||||
"Sales Invoice": {
|
"Sales Invoice": {
|
||||||
"doctype": "Dunning",
|
"doctype": "Dunning",
|
||||||
"field_map": {
|
"field_map": {"customer_address": "customer_address", "parent": "sales_invoice"},
|
||||||
"customer_address": "customer_address",
|
|
||||||
"parent": "sales_invoice"
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
"Payment Schedule": {
|
"Payment Schedule": {
|
||||||
"doctype": "Overdue Payment",
|
"doctype": "Overdue Payment",
|
||||||
"field_map": {
|
"field_map": {"name": "payment_schedule", "parent": "sales_invoice"},
|
||||||
"name": "payment_schedule",
|
|
||||||
"parent": "sales_invoice"
|
|
||||||
},
|
|
||||||
"condition": lambda doc: doc.outstanding > 0 and getdate(doc.due_date) < getdate(),
|
"condition": lambda doc: doc.outstanding > 0 and getdate(doc.due_date) < getdate(),
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
postprocess=postprocess_dunning,
|
postprocess=postprocess_dunning,
|
||||||
ignore_permissions=ignore_permissions
|
ignore_permissions=ignore_permissions,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def check_if_return_invoice_linked_with_payment_entry(self):
|
def check_if_return_invoice_linked_with_payment_entry(self):
|
||||||
# If a Return invoice is linked with payment entry along with other invoices,
|
# 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
|
# the cancellation of the Return causes allocated amount to be greater than paid
|
||||||
|
@ -18,7 +18,8 @@ def execute():
|
|||||||
# something's already here, doesn't need patching
|
# something's already here, doesn't need patching
|
||||||
continue
|
continue
|
||||||
|
|
||||||
payment_schedules = frappe.get_all("Payment Schedule",
|
payment_schedules = frappe.get_all(
|
||||||
|
"Payment Schedule",
|
||||||
filters={"parent": dunning.sales_invoice},
|
filters={"parent": dunning.sales_invoice},
|
||||||
fields=[
|
fields=[
|
||||||
"parent as sales_invoice",
|
"parent as sales_invoice",
|
||||||
@ -30,8 +31,8 @@ def execute():
|
|||||||
# at the time of creating this dunning, the full amount was outstanding
|
# at the time of creating this dunning, the full amount was outstanding
|
||||||
"payment_amount as outstanding",
|
"payment_amount as outstanding",
|
||||||
"'0' as paid_amount",
|
"'0' as paid_amount",
|
||||||
"discounted_amount"
|
"discounted_amount",
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
dunning.extend("overdue_payments", payment_schedules)
|
dunning.extend("overdue_payments", payment_schedules)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user