Dunning cleanup (#22898)
* fix: Dunning cleanup * fix: Added dashboard for Dunning
This commit is contained in:
parent
101fe2b769
commit
48163e31c5
@ -44,6 +44,19 @@ frappe.ui.form.on("Dunning", {
|
||||
);
|
||||
frm.page.set_inner_btn_group_as_primary(__("Create"));
|
||||
}
|
||||
|
||||
if(frm.doc.docstatus > 0) {
|
||||
frm.add_custom_button(__('Ledger'), function() {
|
||||
frappe.route_options = {
|
||||
"voucher_no": frm.doc.name,
|
||||
"from_date": frm.doc.posting_date,
|
||||
"to_date": frm.doc.posting_date,
|
||||
"company": frm.doc.company,
|
||||
"show_cancelled_entries": frm.doc.docstatus === 2
|
||||
};
|
||||
frappe.set_route("query-report", "General Ledger");
|
||||
}, __('View'));
|
||||
}
|
||||
},
|
||||
overdue_days: function (frm) {
|
||||
frappe.db.get_value(
|
||||
@ -125,9 +138,9 @@ frappe.ui.form.on("Dunning", {
|
||||
},
|
||||
calculate_interest_and_amount: function (frm) {
|
||||
const interest_per_year = frm.doc.outstanding_amount * frm.doc.rate_of_interest / 100;
|
||||
const interest_amount = interest_per_year / 365 * frm.doc.overdue_days || 0;
|
||||
const dunning_amount = interest_amount + frm.doc.dunning_fee;
|
||||
const grand_total = frm.doc.outstanding_amount + dunning_amount;
|
||||
const interest_amount = flt((interest_per_year * cint(frm.doc.overdue_days)) / 365 || 0, precision('interest_amount'));
|
||||
const dunning_amount = flt(interest_amount + frm.doc.dunning_fee, precision('dunning_amount'));
|
||||
const grand_total = flt(frm.doc.outstanding_amount + dunning_amount, precision('grand_total'));
|
||||
frm.set_value("interest_amount", interest_amount);
|
||||
frm.set_value("dunning_amount", dunning_amount);
|
||||
frm.set_value("grand_total", grand_total);
|
||||
|
@ -29,10 +29,10 @@
|
||||
"company_address_display",
|
||||
"section_break_6",
|
||||
"dunning_type",
|
||||
"interest_amount",
|
||||
"dunning_fee",
|
||||
"column_break_8",
|
||||
"rate_of_interest",
|
||||
"dunning_fee",
|
||||
"interest_amount",
|
||||
"section_break_12",
|
||||
"dunning_amount",
|
||||
"grand_total",
|
||||
@ -215,7 +215,7 @@
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fetch_from": "dunning_type.interest_rate",
|
||||
"fetch_from": "dunning_type.rate_of_interest",
|
||||
"fetch_if_empty": 1,
|
||||
"fieldname": "rate_of_interest",
|
||||
"fieldtype": "Float",
|
||||
@ -315,7 +315,7 @@
|
||||
],
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2020-07-21 18:20:23.512151",
|
||||
"modified": "2020-08-03 18:55:43.683053",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Dunning",
|
||||
|
@ -6,7 +6,7 @@ from __future__ import unicode_literals
|
||||
import frappe
|
||||
import json
|
||||
from six import string_types
|
||||
from frappe.utils import getdate, get_datetime, rounded, flt
|
||||
from frappe.utils import getdate, get_datetime, rounded, flt, cint
|
||||
from erpnext.loan_management.doctype.loan_interest_accrual.loan_interest_accrual import days_in_year
|
||||
from erpnext.accounts.general_ledger import make_gl_entries, make_reverse_gl_entries
|
||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions
|
||||
@ -27,11 +27,11 @@ class Dunning(AccountsController):
|
||||
amounts = calculate_interest_and_amount(
|
||||
self.posting_date, self.outstanding_amount, self.rate_of_interest, self.dunning_fee, self.overdue_days)
|
||||
if self.interest_amount != amounts.get('interest_amount'):
|
||||
self.interest_amount = amounts.get('interest_amount')
|
||||
self.interest_amount = flt(amounts.get('interest_amount'), self.precision('interest_amount'))
|
||||
if self.dunning_amount != amounts.get('dunning_amount'):
|
||||
self.dunning_amount = amounts.get('dunning_amount')
|
||||
self.dunning_amount = flt(amounts.get('dunning_amount'), self.precision('dunning_amount'))
|
||||
if self.grand_total != amounts.get('grand_total'):
|
||||
self.grand_total = amounts.get('grand_total')
|
||||
self.grand_total = flt(amounts.get('grand_total'), self.precision('grand_total'))
|
||||
|
||||
def on_submit(self):
|
||||
self.make_gl_entries()
|
||||
@ -47,10 +47,13 @@ class Dunning(AccountsController):
|
||||
gl_entries = []
|
||||
invoice_fields = ["project", "cost_center", "debit_to", "party_account_currency", "conversion_rate", "cost_center"]
|
||||
inv = frappe.db.get_value("Sales Invoice", self.sales_invoice, invoice_fields, as_dict=1)
|
||||
|
||||
accounting_dimensions = get_accounting_dimensions()
|
||||
invoice_fields.extend(accounting_dimensions)
|
||||
|
||||
dunning_in_company_currency = flt(self.dunning_amount * inv.conversion_rate)
|
||||
default_cost_center = frappe.get_cached_value('Company', self.company, 'cost_center')
|
||||
|
||||
gl_entries.append(
|
||||
self.get_gl_dict({
|
||||
"account": inv.debit_to,
|
||||
@ -91,9 +94,8 @@ def resolve_dunning(doc, state):
|
||||
def calculate_interest_and_amount(posting_date, outstanding_amount, rate_of_interest, dunning_fee, overdue_days):
|
||||
interest_amount = 0
|
||||
if rate_of_interest:
|
||||
interest_per_year = rounded(flt(outstanding_amount) * flt(rate_of_interest))/100
|
||||
interest_amount = (
|
||||
interest_per_year / days_in_year(get_datetime(posting_date).year)) * int(overdue_days)
|
||||
interest_per_year = flt(outstanding_amount) * flt(rate_of_interest) / 100
|
||||
interest_amount = (interest_per_year * cint(overdue_days)) / 365
|
||||
grand_total = flt(outstanding_amount) + flt(interest_amount) + flt(dunning_fee)
|
||||
dunning_amount = flt(interest_amount) + flt(dunning_fee)
|
||||
return {
|
||||
|
17
erpnext/accounts/doctype/dunning/dunning_dashboard.py
Normal file
17
erpnext/accounts/doctype/dunning/dunning_dashboard.py
Normal file
@ -0,0 +1,17 @@
|
||||
from __future__ import unicode_literals
|
||||
from frappe import _
|
||||
|
||||
def get_data():
|
||||
return {
|
||||
'fieldname': 'dunning',
|
||||
'non_standard_fieldnames': {
|
||||
'Journal Entry': 'reference_name',
|
||||
'Payment Entry': 'reference_name'
|
||||
},
|
||||
'transactions': [
|
||||
{
|
||||
'label': _('Payment'),
|
||||
'items': ['Payment Entry', 'Journal Entry']
|
||||
}
|
||||
]
|
||||
}
|
@ -18,7 +18,7 @@ def get_data():
|
||||
'transactions': [
|
||||
{
|
||||
'label': _('Payment'),
|
||||
'items': ['Payment Entry', 'Payment Request', 'Journal Entry', 'Invoice Discounting']
|
||||
'items': ['Payment Entry', 'Payment Request', 'Journal Entry', 'Invoice Discounting', 'Dunning']
|
||||
},
|
||||
{
|
||||
'label': _('Reference'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user