Dunning cleanup beta (#22899)

* fix: Dunning cleanup

* fix: Added dashboard for Dunning
diff --git a/erpnext/accounts/doctype/dunning/dunning.js b/erpnext/accounts/doctype/dunning/dunning.js
index c563368..9909c6c 100644
--- a/erpnext/accounts/doctype/dunning/dunning.js
+++ b/erpnext/accounts/doctype/dunning/dunning.js
@@ -44,6 +44,19 @@
 			);
 			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 @@
 	},
 	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);
diff --git a/erpnext/accounts/doctype/dunning/dunning.json b/erpnext/accounts/doctype/dunning/dunning.json
index b3eddf5..d55bfd1 100644
--- a/erpnext/accounts/doctype/dunning/dunning.json
+++ b/erpnext/accounts/doctype/dunning/dunning.json
@@ -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",
diff --git a/erpnext/accounts/doctype/dunning/dunning.py b/erpnext/accounts/doctype/dunning/dunning.py
index 0be6a48..3e372af 100644
--- a/erpnext/accounts/doctype/dunning/dunning.py
+++ b/erpnext/accounts/doctype/dunning/dunning.py
@@ -6,7 +6,7 @@
 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 @@
 		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 @@
 		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 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 {
diff --git a/erpnext/accounts/doctype/dunning/dunning_dashboard.py b/erpnext/accounts/doctype/dunning/dunning_dashboard.py
new file mode 100644
index 0000000..19a73dd
--- /dev/null
+++ b/erpnext/accounts/doctype/dunning/dunning_dashboard.py
@@ -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']
+			}
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice_dashboard.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice_dashboard.py
index 4a8fcc0..f106928 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice_dashboard.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice_dashboard.py
@@ -18,7 +18,7 @@
 		'transactions': [
 			{
 				'label': _('Payment'),
-				'items': ['Payment Entry', 'Payment Request', 'Journal Entry', 'Invoice Discounting']
+				'items': ['Payment Entry', 'Payment Request', 'Journal Entry', 'Invoice Discounting', 'Dunning']
 			},
 			{
 				'label': _('Reference'),