Merge pull request #18149 from deepeshgarg007/trial_balance_dimensions

fix: Add filters for accounting dimensions in trial balance report
diff --git a/erpnext/accounts/doctype/accounting_period/accounting_period.py b/erpnext/accounts/doctype/accounting_period/accounting_period.py
index f7190b7..de45f3a 100644
--- a/erpnext/accounts/doctype/accounting_period/accounting_period.py
+++ b/erpnext/accounts/doctype/accounting_period/accounting_period.py
@@ -5,6 +5,7 @@
 from __future__ import unicode_literals
 import frappe
 from frappe.model.document import Document
+from frappe import _
 
 class AccountingPeriod(Document):
 	def validate(self):
@@ -16,7 +17,7 @@
 	def autoname(self):
 		company_abbr = frappe.get_cached_value('Company',  self.company,  "abbr")
 		self.name = " - ".join([self.period_name, company_abbr])
-	
+
 	def validate_overlap(self):
 		existing_accounting_period = frappe.db.sql("""select name from `tabAccounting Period`
 			where (
@@ -33,7 +34,7 @@
 			}, as_dict=True)
 
 		if len(existing_accounting_period) > 0:
-			frappe.throw("Accounting Period overlaps with {0}".format(existing_accounting_period[0].get("name")))
+			frappe.throw(_("Accounting Period overlaps with {0}".format(existing_accounting_period[0].get("name"))))
 
 	def get_doctypes_for_closing(self):
 		docs_for_closing = []
diff --git a/erpnext/accounts/doctype/bank_statement_transaction_entry/bank_statement_transaction_entry.py b/erpnext/accounts/doctype/bank_statement_transaction_entry/bank_statement_transaction_entry.py
index 101b9f2..1318cf1 100644
--- a/erpnext/accounts/doctype/bank_statement_transaction_entry/bank_statement_transaction_entry.py
+++ b/erpnext/accounts/doctype/bank_statement_transaction_entry/bank_statement_transaction_entry.py
@@ -48,7 +48,7 @@
 
 	def get_statement_headers(self):
 		if not self.bank_settings:
-			frappe.throw("Bank Data mapper doesn't exist")
+			frappe.throw(_("Bank Data mapper doesn't exist"))
 		mapper_doc = frappe.get_doc("Bank Statement Settings", self.bank_settings)
 		headers = {entry.mapped_header:entry.stmt_header for entry in mapper_doc.header_items}
 		return headers
@@ -57,7 +57,7 @@
 		if self.bank_statement is None: return
 		filename = self.bank_statement.split("/")[-1]
 		if (len(self.new_transaction_items + self.reconciled_transaction_items) > 0):
-			frappe.throw("Transactions already retreived from the statement")
+			frappe.throw(_("Transactions already retreived from the statement"))
 
 		date_format = frappe.get_value("Bank Statement Settings", self.bank_settings, "date_format")
 		if (date_format is None):
@@ -314,7 +314,7 @@
 			try:
 				reconcile_against_document(lst)
 			except:
-				frappe.throw("Exception occurred while reconciling {0}".format(payment.reference_name))
+				frappe.throw(_("Exception occurred while reconciling {0}".format(payment.reference_name)))
 
 	def submit_payment_entries(self):
 		for payment in self.new_transaction_items:
@@ -414,7 +414,7 @@
 	elif (filename.lower().endswith("xls")):
 		rows = get_rows_from_xls_file(filename)
 	else:
-		frappe.throw("Only .csv and .xlsx files are supported currently")
+		frappe.throw(_("Only .csv and .xlsx files are supported currently"))
 
 	stmt_headers = headers.values()
 	for row in rows:
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js
index b7f383f..b6c48c8 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.js
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js
@@ -228,6 +228,10 @@
 				frappe.model.validate_missing(jvd, "account");
 				var party_account_field = jvd.reference_type==="Sales Invoice" ? "debit_to": "credit_to";
 				out.filters.push([jvd.reference_type, party_account_field, "=", jvd.account]);
+
+				if (in_list(['Debit Note', 'Credit Note'], doc.voucher_type)) {
+					out.filters.push([jvd.reference_type, "is_return", "=", 1]);
+				}
 			}
 
 			if(in_list(["Sales Order", "Purchase Order"], jvd.reference_type)) {
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index d082b60..3132c93 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -331,7 +331,8 @@
 		for reference_name, total in iteritems(self.reference_totals):
 			reference_type = self.reference_types[reference_name]
 
-			if reference_type in ("Sales Invoice", "Purchase Invoice"):
+			if (reference_type in ("Sales Invoice", "Purchase Invoice") and
+				self.voucher_type not in ['Debit Note', 'Credit Note']):
 				invoice = frappe.db.get_value(reference_type, reference_name,
 					["docstatus", "outstanding_amount"], as_dict=1)
 
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 92803a6..ea76126 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -535,6 +535,20 @@
 			"amount": self.total_allocated_amount * (tax_details['tax']['rate'] / 100)
 		}
 
+	def set_gain_or_loss(self, account_details=None):
+		if not self.difference_amount:
+			self.set_difference_amount()
+
+		row = {
+			'amount': self.difference_amount
+		}
+
+		if account_details:
+			row.update(account_details)
+
+		self.append('deductions', row)
+		self.set_unallocated_amount()
+
 @frappe.whitelist()
 def get_outstanding_reference_documents(args):
 
diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js
index 4c24a9f..d3992d5 100644
--- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js
+++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js
@@ -16,6 +16,20 @@
 			})[0].outstanding_amount;
 
 			frappe.model.set_value(cdt, cdn, "allocated_amount", Math.min(invoice_amount, row.amount));
+
+			frm.call({
+				doc: frm.doc,
+				method: 'get_difference_amount',
+				args: {
+					child_row: row
+				},
+				callback: function(r, rt) {
+					if(r.message) {
+						frappe.model.set_value(cdt, cdn,
+							"difference_amount", r.message);
+					}
+				}
+			});
 		}
 	}
 });
@@ -104,6 +118,91 @@
 
 	reconcile: function() {
 		var me = this;
+		var show_dialog = me.frm.doc.payments.filter(d => d.difference_amount && !d.difference_account);
+
+		if (show_dialog && show_dialog.length) {
+
+			this.data = [];
+			const dialog = new frappe.ui.Dialog({
+				title: __("Select Difference Account"),
+				fields: [
+					{
+						fieldname: "payments", fieldtype: "Table", label: __("Payments"),
+						data: this.data, in_place_edit: true,
+						get_data: () => {
+							return this.data;
+						},
+						fields: [{
+							fieldtype:'Data',
+							fieldname:"docname",
+							in_list_view: 1,
+							hidden: 1
+						}, {
+							fieldtype:'Data',
+							fieldname:"reference_name",
+							label: __("Voucher No"),
+							in_list_view: 1,
+							read_only: 1
+						}, {
+							fieldtype:'Link',
+							options: 'Account',
+							in_list_view: 1,
+							label: __("Difference Account"),
+							fieldname: 'difference_account',
+							reqd: 1,
+							get_query: function() {
+								return {
+									filters: {
+										company: me.frm.doc.company,
+										is_group: 0
+									}
+								}
+							}
+						}, {
+							fieldtype:'Currency',
+							in_list_view: 1,
+							label: __("Difference Amount"),
+							fieldname: 'difference_amount',
+							read_only: 1
+						}]
+					},
+				],
+				primary_action: function() {
+					const args = dialog.get_values()["payments"];
+
+					args.forEach(d => {
+						frappe.model.set_value("Payment Reconciliation Payment", d.docname,
+							"difference_account", d.difference_account);
+					});
+
+					me.reconcile_payment_entries();
+					dialog.hide();
+				},
+				primary_action_label: __('Reconcile Entries')
+			});
+
+			this.frm.doc.payments.forEach(d => {
+				if (d.difference_amount && !d.difference_account) {
+					dialog.fields_dict.payments.df.data.push({
+						'docname': d.name,
+						'reference_name': d.reference_name,
+						'difference_amount': d.difference_amount,
+						'difference_account': d.difference_account,
+					});
+				}
+			});
+
+			this.data = dialog.fields_dict.payments.df.data;
+			dialog.fields_dict.payments.grid.refresh();
+			dialog.show();
+		} else {
+			this.reconcile_payment_entries();
+		}
+	},
+
+	reconcile_payment_entries: function() {
+		var me = this;
+
 		return this.frm.call({
 			doc: me.frm.doc,
 			method: 'reconcile',
diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
index a625494..b74eed5 100644
--- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
+++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
@@ -3,10 +3,11 @@
 
 from __future__ import unicode_literals
 import frappe, erpnext
-from frappe.utils import flt
+from frappe.utils import flt, today
 from frappe import msgprint, _
 from frappe.model.document import Document
-from erpnext.accounts.utils import get_outstanding_invoices
+from erpnext.accounts.utils import (get_outstanding_invoices,
+	update_reference_in_payment_entry, reconcile_against_document)
 from erpnext.controllers.accounts_controller import get_advance_payment_entries
 
 class PaymentReconciliation(Document):
@@ -20,7 +21,10 @@
 		payment_entries = self.get_payment_entries()
 		journal_entries = self.get_jv_entries()
 
-		self.add_payment_entries(payment_entries + journal_entries)
+		if self.party_type in ["Customer", "Supplier"]:
+			dr_or_cr_notes = self.get_dr_or_cr_notes()
+
+		self.add_payment_entries(payment_entries + journal_entries + dr_or_cr_notes)
 
 	def get_payment_entries(self):
 		order_doctype = "Sales Order" if self.party_type=="Customer" else "Purchase Order"
@@ -71,6 +75,34 @@
 
 		return list(journal_entries)
 
+	def get_dr_or_cr_notes(self):
+		dr_or_cr = ("credit_in_account_currency"
+			if erpnext.get_party_account_type(self.party_type) == 'Receivable' else "debit_in_account_currency")
+
+		reconciled_dr_or_cr =  ("debit_in_account_currency"
+			if dr_or_cr == "credit_in_account_currency" else "credit_in_account_currency")
+
+		voucher_type = ('Sales Invoice'
+			if self.party_type == 'Customer' else "Purchase Invoice")
+
+		return frappe.db.sql(""" SELECT `tab{doc}`.name as reference_name, %(voucher_type)s as reference_type,
+				(sum(`tabGL Entry`.{dr_or_cr}) - sum(`tabGL Entry`.{reconciled_dr_or_cr})) as amount
+			FROM `tab{doc}`, `tabGL Entry`
+			WHERE
+				(`tab{doc}`.name = `tabGL Entry`.against_voucher or `tab{doc}`.name = `tabGL Entry`.voucher_no)
+				and `tab{doc}`.is_return = 1 and `tabGL Entry`.against_voucher_type = %(voucher_type)s
+				and `tab{doc}`.docstatus = 1 and `tabGL Entry`.party = %(party)s
+				and `tabGL Entry`.party_type = %(party_type)s and `tabGL Entry`.account = %(account)s
+			GROUP BY `tabSales Invoice`.name
+			Having
+				amount > 0
+		""".format(doc=voucher_type, dr_or_cr=dr_or_cr, reconciled_dr_or_cr=reconciled_dr_or_cr), {
+			'party': self.party,
+			'party_type': self.party_type,
+			'voucher_type': voucher_type,
+			'account': self.receivable_payable_account
+		}, as_dict=1)
+
 	def add_payment_entries(self, entries):
 		self.set('payments', [])
 		for e in entries:
@@ -114,36 +146,67 @@
 			if erpnext.get_party_account_type(self.party_type) == 'Receivable' else "debit_in_account_currency")
 
 		lst = []
+		dr_or_cr_notes = []
 		for e in self.get('payments'):
+			reconciled_entry = []
 			if e.invoice_number and e.allocated_amount:
-				lst.append(frappe._dict({
-					'voucher_type': e.reference_type,
-					'voucher_no' : e.reference_name,
-					'voucher_detail_no' : e.reference_row,
-					'against_voucher_type' : e.invoice_type,
-					'against_voucher'  : e.invoice_number,
-					'account' : self.receivable_payable_account,
-					'party_type': self.party_type,
-					'party': self.party,
-					'is_advance' : e.is_advance,
-					'dr_or_cr' : dr_or_cr,
-					'unadjusted_amount' : flt(e.amount),
-					'allocated_amount' : flt(e.allocated_amount)
-				}))
+				if e.reference_type in ['Sales Invoice', 'Purchase Invoice']:
+					reconciled_entry = dr_or_cr_notes
+				else:
+					reconciled_entry = lst
+
+				reconciled_entry.append(self.get_payment_details(e, dr_or_cr))
 
 		if lst:
-			from erpnext.accounts.utils import reconcile_against_document
 			reconcile_against_document(lst)
 
-			msgprint(_("Successfully Reconciled"))
-			self.get_unreconciled_entries()
+		if dr_or_cr_notes:
+			reconcile_dr_cr_note(dr_or_cr_notes)
+
+		msgprint(_("Successfully Reconciled"))
+		self.get_unreconciled_entries()
+
+	def get_payment_details(self, row, dr_or_cr):
+		return frappe._dict({
+			'voucher_type': row.reference_type,
+			'voucher_no' : row.reference_name,
+			'voucher_detail_no' : row.reference_row,
+			'against_voucher_type' : row.invoice_type,
+			'against_voucher'  : row.invoice_number,
+			'account' : self.receivable_payable_account,
+			'party_type': self.party_type,
+			'party': self.party,
+			'is_advance' : row.is_advance,
+			'dr_or_cr' : dr_or_cr,
+			'unadjusted_amount' : flt(row.amount),
+			'allocated_amount' : flt(row.allocated_amount),
+			'difference_amount': row.difference_amount,
+			'difference_account': row.difference_account
+		})
+
+	def get_difference_amount(self, child_row):
+		if child_row.get("reference_type") != 'Payment Entry': return
+
+		child_row = frappe._dict(child_row)
+
+		if child_row.invoice_number and " | " in child_row.invoice_number:
+			child_row.invoice_type, child_row.invoice_number = child_row.invoice_number.split(" | ")
+
+		dr_or_cr = ("credit_in_account_currency"
+			if erpnext.get_party_account_type(self.party_type) == 'Receivable' else "debit_in_account_currency")
+
+		row = self.get_payment_details(child_row, dr_or_cr)
+
+		doc = frappe.get_doc(row.voucher_type, row.voucher_no)
+		update_reference_in_payment_entry(row, doc, do_not_save=True)
+
+		return doc.difference_amount
 
 	def check_mandatory_to_fetch(self):
 		for fieldname in ["company", "party_type", "party", "receivable_payable_account"]:
 			if not self.get(fieldname):
 				frappe.throw(_("Please select {0} first").format(self.meta.get_label(fieldname)))
 
-
 	def validate_invoice(self):
 		if not self.get("invoices"):
 			frappe.throw(_("No records found in the Invoice table"))
@@ -188,3 +251,41 @@
 			cond += " and `{0}` <= {1}".format(dr_or_cr, flt(self.maximum_amount))
 
 		return cond
+
+def reconcile_dr_cr_note(dr_cr_notes):
+	for d in dr_cr_notes:
+		voucher_type = ('Credit Note'
+			if d.voucher_type == 'Sales Invoice' else 'Debit Note')
+
+		dr_or_cr = ('credit_in_account_currency'
+			if d.reference_type == 'Sales Invoice' else 'debit_in_account_currency')
+
+		reconcile_dr_or_cr = ('debit_in_account_currency'
+			if dr_or_cr == 'credit_in_account_currency' else 'credit_in_account_currency')
+
+		jv = frappe.get_doc({
+			"doctype": "Journal Entry",
+			"voucher_type": voucher_type,
+			"posting_date": today(),
+			"accounts": [
+				{
+					'account': d.account,
+					'party': d.party,
+					'party_type': d.party_type,
+					reconcile_dr_or_cr: (abs(d.allocated_amount)
+						if abs(d.unadjusted_amount) > abs(d.allocated_amount) else abs(d.unadjusted_amount)),
+					'reference_type': d.against_voucher_type,
+					'reference_name': d.against_voucher
+				},
+				{
+					'account': d.account,
+					'party': d.party,
+					'party_type': d.party_type,
+					dr_or_cr: abs(d.allocated_amount),
+					'reference_type': d.voucher_type,
+					'reference_name': d.voucher_no
+				}
+			]
+		})
+
+		jv.submit()
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/payment_reconciliation_payment/payment_reconciliation_payment.json b/erpnext/accounts/doctype/payment_reconciliation_payment/payment_reconciliation_payment.json
index 814257c..018bfd0 100644
--- a/erpnext/accounts/doctype/payment_reconciliation_payment/payment_reconciliation_payment.json
+++ b/erpnext/accounts/doctype/payment_reconciliation_payment/payment_reconciliation_payment.json
@@ -1,389 +1,127 @@
 {
- "allow_copy": 0, 
- "allow_events_in_timeline": 0, 
- "allow_guest_to_view": 0, 
- "allow_import": 0, 
- "allow_rename": 0, 
- "beta": 0, 
- "creation": "2014-07-09 16:13:35.452759", 
- "custom": 0, 
- "docstatus": 0, 
- "doctype": "DocType", 
- "document_type": "", 
- "editable_grid": 1, 
+ "creation": "2014-07-09 16:13:35.452759",
+ "doctype": "DocType",
+ "editable_grid": 1,
+ "field_order": [
+  "reference_type",
+  "reference_name",
+  "posting_date",
+  "is_advance",
+  "reference_row",
+  "col_break1",
+  "invoice_number",
+  "amount",
+  "allocated_amount",
+  "section_break_10",
+  "difference_account",
+  "difference_amount",
+  "sec_break1",
+  "remark"
+ ],
  "fields": [
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "reference_type", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Reference Type", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "DocType", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "reference_type",
+   "fieldtype": "Link",
+   "label": "Reference Type",
+   "options": "DocType",
+   "read_only": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 3, 
-   "fieldname": "reference_name", 
-   "fieldtype": "Dynamic Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Reference Name", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "reference_type", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "columns": 2,
+   "fieldname": "reference_name",
+   "fieldtype": "Dynamic Link",
+   "in_list_view": 1,
+   "label": "Reference Name",
+   "options": "reference_type",
+   "read_only": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "posting_date", 
-   "fieldtype": "Date", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Posting Date", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "posting_date",
+   "fieldtype": "Date",
+   "label": "Posting Date",
+   "read_only": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "is_advance", 
-   "fieldtype": "Data", 
-   "hidden": 1, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Is Advance", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "is_advance",
+   "fieldtype": "Data",
+   "hidden": 1,
+   "label": "Is Advance",
+   "read_only": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "reference_row", 
-   "fieldtype": "Data", 
-   "hidden": 1, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Reference Row", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "reference_row",
+   "fieldtype": "Data",
+   "hidden": 1,
+   "label": "Reference Row",
+   "read_only": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "col_break1", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "col_break1",
+   "fieldtype": "Column Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 3, 
-   "fieldname": "invoice_number", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Invoice Number", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "columns": 2,
+   "fieldname": "invoice_number",
+   "fieldtype": "Select",
+   "in_list_view": 1,
+   "label": "Invoice Number",
+   "reqd": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 2, 
-   "fieldname": "amount", 
-   "fieldtype": "Currency", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Amount", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "columns": 2,
+   "fieldname": "amount",
+   "fieldtype": "Currency",
+   "in_list_view": 1,
+   "label": "Amount",
+   "read_only": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 2, 
-   "fieldname": "allocated_amount", 
-   "fieldtype": "Currency", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Allocated amount", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "columns": 2,
+   "fieldname": "allocated_amount",
+   "fieldtype": "Currency",
+   "in_list_view": 1,
+   "label": "Allocated amount",
+   "reqd": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "sec_break1", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "sec_break1",
+   "fieldtype": "Section Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "remark", 
-   "fieldtype": "Small Text", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Remark", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
+   "fieldname": "remark",
+   "fieldtype": "Small Text",
+   "in_list_view": 1,
+   "label": "Remark",
+   "read_only": 1
+  },
+  {
+   "columns": 2,
+   "fieldname": "difference_account",
+   "fieldtype": "Link",
+   "in_list_view": 1,
+   "label": "Difference Account",
+   "options": "Account"
+  },
+  {
+   "fieldname": "difference_amount",
+   "fieldtype": "Currency",
+   "label": "Difference Amount",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "section_break_10",
+   "fieldtype": "Section Break"
   }
- ], 
- "has_web_view": 0, 
- "hide_heading": 0, 
- "hide_toolbar": 0, 
- "idx": 0, 
- "image_view": 0, 
- "in_create": 0, 
- "is_submittable": 0, 
- "issingle": 0, 
- "istable": 1, 
- "max_attachments": 0, 
- "menu_index": 0, 
- "modified": "2019-01-07 16:52:07.567027", 
- "modified_by": "Administrator", 
- "module": "Accounts", 
- "name": "Payment Reconciliation Payment", 
- "name_case": "", 
- "owner": "Administrator", 
- "permissions": [], 
- "quick_entry": 1, 
- "read_only": 0, 
- "read_only_onload": 0, 
- "show_name_in_global_search": 0, 
- "sort_field": "modified", 
- "sort_order": "DESC", 
- "track_changes": 0, 
- "track_seen": 0, 
- "track_views": 0
+ ],
+ "istable": 1,
+ "modified": "2019-06-24 00:08:11.150796",
+ "modified_by": "Administrator",
+ "module": "Accounts",
+ "name": "Payment Reconciliation Payment",
+ "owner": "Administrator",
+ "permissions": [],
+ "quick_entry": 1,
+ "sort_field": "modified",
+ "sort_order": "DESC"
 }
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
index dd4f51c..f4b656d 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
@@ -157,7 +157,7 @@
 	can_change_release_date: function(date) {
 		const diff = frappe.datetime.get_diff(date, frappe.datetime.nowdate());
 		if (diff < 0) {
-			frappe.throw('New release date should be in the future');
+			frappe.throw(__('New release date should be in the future'));
 			return false;
 		} else {
 			return true;
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 1bd833b..a6f6ace 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -105,7 +105,7 @@
 
 	def validate_release_date(self):
 		if self.release_date and getdate(nowdate()) >= getdate(self.release_date):
-			frappe.msgprint('Release date must be in the future', raise_exception=True)
+			frappe.throw(_('Release date must be in the future'))
 
 	def validate_cash(self):
 		if not self.cash_bank_account and flt(self.paid_amount):
diff --git a/erpnext/accounts/doctype/subscription_plan/subscription_plan.py b/erpnext/accounts/doctype/subscription_plan/subscription_plan.py
index d3fef60..625979b 100644
--- a/erpnext/accounts/doctype/subscription_plan/subscription_plan.py
+++ b/erpnext/accounts/doctype/subscription_plan/subscription_plan.py
@@ -4,6 +4,7 @@
 
 from __future__ import unicode_literals
 import frappe
+from frappe import _
 from frappe.model.document import Document
 from erpnext.utilities.product import get_price
 
@@ -13,7 +14,7 @@
 
 	def validate_interval_count(self):
 		if self.billing_interval_count < 1:
-			frappe.throw('Billing Interval Count cannot be less than 1')
+			frappe.throw(_('Billing Interval Count cannot be less than 1'))
 
 @frappe.whitelist()
 def get_plan_rate(plan, quantity=1, customer=None):
@@ -26,7 +27,7 @@
 			customer_group = frappe.db.get_value("Customer", customer, "customer_group")
 		else:
 			customer_group = None
-		
+
 		price = get_price(item_code=plan.item, price_list=plan.price_list, customer_group=customer_group, company=None, qty=quantity)
 		if not price:
 			return 0
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
index 4cba978..2973748 100755
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
@@ -599,9 +599,12 @@
 
 		rows = []
 		for d in data:
+			values = d[self.ageing_col_idx_start : self.ageing_col_idx_start+5]
+			precision = cint(frappe.db.get_default("float_precision")) or 2
+			formatted_values = [frappe.utils.rounded(val, precision) for val in values]
 			rows.append(
 				{
-					'values': d[self.ageing_col_idx_start : self.ageing_col_idx_start+5]
+					'values': formatted_values
 				}
 			)
 
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 7a230a7..7a1f6c5 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -435,7 +435,7 @@
 	jv_obj.flags.ignore_validate_update_after_submit = True
 	jv_obj.save(ignore_permissions=True)
 
-def update_reference_in_payment_entry(d, payment_entry):
+def update_reference_in_payment_entry(d, payment_entry, do_not_save=False):
 	reference_details = {
 		"reference_doctype": d.against_voucher_type,
 		"reference_name": d.against_voucher,
@@ -466,7 +466,17 @@
 	payment_entry.setup_party_account_field()
 	payment_entry.set_missing_values()
 	payment_entry.set_amounts()
-	payment_entry.save(ignore_permissions=True)
+
+	if d.difference_amount and d.difference_account:
+		payment_entry.set_gain_or_loss(account_details={
+			'account': d.difference_account,
+			'cost_center': payment_entry.cost_center or frappe.get_cached_value('Company',
+				payment_entry.company, "cost_center"),
+			'amount': d.difference_amount
+		})
+
+	if not do_not_save:
+		payment_entry.save(ignore_permissions=True)
 
 def unlink_ref_doc_from_payment_entries(ref_doc):
 	remove_ref_doc_link_from_jv(ref_doc.doctype, ref_doc.name)
diff --git a/erpnext/controllers/item_variant.py b/erpnext/controllers/item_variant.py
index 9152c31..dee71dc 100644
--- a/erpnext/controllers/item_variant.py
+++ b/erpnext/controllers/item_variant.py
@@ -98,8 +98,8 @@
 	if allow_rename_attribute_value:
 		pass
 	elif attribute_value not in attributes_list:
-		frappe.throw(_("Value {0} for Attribute {1} does not exist in the list of valid Item Attribute Values for Item {2}").format(
-			attribute_value, attribute, item), InvalidItemAttributeValueError, title=_('Invalid Attribute'))
+		frappe.throw(_("The value {0} is already assigned to an exisiting Item {2}.").format(
+			attribute_value, attribute, item), InvalidItemAttributeValueError, title=_('Rename Not Allowed'))
 
 def get_attribute_values(item):
 	if not frappe.flags.attribute_values:
@@ -176,7 +176,7 @@
 	for key in variants:
 		total_variants *= len(variants[key])
 	if total_variants >= 600:
-		frappe.msgprint("Please do not create more than 500 items at a time", raise_exception=1)
+		frappe.throw(_("Please do not create more than 500 items at a time"))
 		return
 	if total_variants < 10:
 		return create_multiple_variants(item, args)
diff --git a/erpnext/crm/doctype/utils.py b/erpnext/crm/doctype/utils.py
index bd8b678..9cfab15 100644
--- a/erpnext/crm/doctype/utils.py
+++ b/erpnext/crm/doctype/utils.py
@@ -87,7 +87,7 @@
 		'parent': communication_medium,
 		'from_time': ['<=', now_time],
 		'to_time': ['>=', now_time],
-	}, fields=['employee_group'], debug=1)
+	}, fields=['employee_group'])
 
 	available_employee_groups = tuple([emp.employee_group for emp in available_employee_groups])
 
diff --git a/erpnext/education/doctype/question/question.py b/erpnext/education/doctype/question/question.py
index b822108..9a973c7 100644
--- a/erpnext/education/doctype/question/question.py
+++ b/erpnext/education/doctype/question/question.py
@@ -38,7 +38,7 @@
 		options = self.options
 		answers = [item.name for item in options if item.is_correct == True]
 		if len(answers) == 0:
-			frappe.throw("No correct answer is set for {0}".format(self.name))
+			frappe.throw(_("No correct answer is set for {0}".format(self.name)))
 			return None
 		elif len(answers) == 1:
 			return answers[0]
diff --git a/erpnext/education/doctype/quiz/quiz.py b/erpnext/education/doctype/quiz/quiz.py
index 8e54745..ae1cb6c 100644
--- a/erpnext/education/doctype/quiz/quiz.py
+++ b/erpnext/education/doctype/quiz/quiz.py
@@ -4,12 +4,13 @@
 
 from __future__ import unicode_literals
 import frappe
+from frappe import _
 from frappe.model.document import Document
 
 class Quiz(Document):
 	def validate(self):
 		if self.passing_score > 100:
-			frappe.throw("Passing Score value should be between 0 and 100")
+			frappe.throw(_("Passing Score value should be between 0 and 100"))
 
 	def allowed_attempt(self, enrollment, quiz_name):
 		if self.max_attempts ==  0:
@@ -17,7 +18,7 @@
 
 		try:
 			if len(frappe.get_all("Quiz Activity", {'enrollment': enrollment.name, 'quiz': quiz_name})) >= self.max_attempts:
-				frappe.msgprint("Maximum attempts for this quiz reached!")
+				frappe.msgprint(_("Maximum attempts for this quiz reached!"))
 				return False
 			else:
 				return True
@@ -56,5 +57,5 @@
 		else:
 			return False
 	except TypeError:
-		frappe.throw("Compare List function takes on list arguments")
+		frappe.throw(_("Compare List function takes on list arguments"))
 
diff --git a/erpnext/education/doctype/student_report_generation_tool/student_report_generation_tool.py b/erpnext/education/doctype/student_report_generation_tool/student_report_generation_tool.py
index f997975..16933dc 100644
--- a/erpnext/education/doctype/student_report_generation_tool/student_report_generation_tool.py
+++ b/erpnext/education/doctype/student_report_generation_tool/student_report_generation_tool.py
@@ -4,6 +4,7 @@
 
 from __future__ import unicode_literals
 import frappe, json
+from frappe import _
 from frappe.model.document import Document
 from erpnext.education.api import get_grade
 from frappe.utils.pdf import get_pdf
@@ -79,7 +80,7 @@
 		from_date, to_date = frappe.db.get_value("Academic Term", academic_term, ["term_start_date", "term_end_date"])
 	if from_date and to_date:
 		attendance = dict(frappe.db.sql('''select status, count(student) as no_of_days
-			from `tabStudent Attendance` where student = %s 
+			from `tabStudent Attendance` where student = %s
 			and date between %s and %s group by status''',
 			(student, from_date, to_date)))
 		if "Absent" not in attendance.keys():
@@ -88,4 +89,4 @@
 			attendance["Present"] = 0
 		return attendance
 	else:
-		frappe.throw("Provide the academic year and set the starting and ending date.") 
\ No newline at end of file
+		frappe.throw(_("Provide the academic year and set the starting and ending date."))
\ No newline at end of file
diff --git a/erpnext/education/utils.py b/erpnext/education/utils.py
index 8cd5bbb..e0b278c 100644
--- a/erpnext/education/utils.py
+++ b/erpnext/education/utils.py
@@ -148,7 +148,7 @@
 		# Check if self enrollment in allowed
 		program = frappe.get_doc('Program', program_name)
 		if not program.allow_self_enroll:
-			return frappe.throw("You are not allowed to enroll for this course")
+			return frappe.throw(_("You are not allowed to enroll for this course"))
 
 		student = get_current_student()
 		if not student:
@@ -162,7 +162,7 @@
 	# Check if self enrollment in allowed
 	program = frappe.get_doc('Program', program_name)
 	if not program.allow_self_enroll:
-		return frappe.throw("You are not allowed to enroll for this course")
+		return frappe.throw(_("You are not allowed to enroll for this course"))
 
 	# Enroll in program
 	program_enrollment = student.enroll_in_program(program_name)
@@ -185,7 +185,7 @@
 
 	student = get_current_student()
 	if not student:
-		return frappe.throw("Student with email {0} does not exist".format(frappe.session.user), frappe.DoesNotExistError)
+		return frappe.throw(_("Student with email {0} does not exist".format(frappe.session.user)), frappe.DoesNotExistError)
 
 	enrollment = get_or_create_course_enrollment(course, program)
 	if content_type == 'Quiz':
@@ -220,7 +220,7 @@
 		quiz = frappe.get_doc("Quiz", quiz_name)
 		questions = quiz.get_questions()
 	except:
-		frappe.throw("Quiz {0} does not exist".format(quiz_name))
+		frappe.throw(_("Quiz {0} does not exist".format(quiz_name)))
 		return None
 
 	questions = [{
@@ -347,7 +347,7 @@
 	if not course_enrollment:
 		program_enrollment = get_enrollment('program', program, student.name)
 		if not program_enrollment:
-			frappe.throw("You are not enrolled in program {0}".format(program))
+			frappe.throw(_("You are not enrolled in program {0}".format(program)))
 			return
 		return student.enroll_in_course(course_name=course, program_enrollment=get_enrollment('program', program, student.name))
 	else:
diff --git a/erpnext/erpnext_integrations/connectors/shopify_connection.py b/erpnext/erpnext_integrations/connectors/shopify_connection.py
index 88078ab..1d6e891 100644
--- a/erpnext/erpnext_integrations/connectors/shopify_connection.py
+++ b/erpnext/erpnext_integrations/connectors/shopify_connection.py
@@ -124,7 +124,7 @@
 
 	else:
 		so = frappe.get_doc("Sales Order", so)
-	
+
 	frappe.db.commit()
 	return so
 
@@ -252,6 +252,6 @@
 		{"parent": "Shopify Settings", "shopify_tax": tax_title}, "tax_account")
 
 	if not tax_account:
-		frappe.throw("Tax Account not specified for Shopify Tax {0}".format(tax.get("title")))
+		frappe.throw(_("Tax Account not specified for Shopify Tax {0}".format(tax.get("title"))))
 
 	return tax_account
diff --git a/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.py b/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.py
index 90bf957..141329b 100644
--- a/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.py
+++ b/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.py
@@ -30,7 +30,7 @@
 			try:
 				frappe.delete_doc("Item",self.item)
 			except Exception:
-				frappe.throw("""Not permitted. Please disable the Procedure Template""")
+				frappe.throw(_("""Not permitted. Please disable the Procedure Template"""))
 
 	def get_item_details(self, args=None):
 		item = frappe.db.sql("""select stock_uom, item_name
diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js
index 2f328de..b3cbd1f 100644
--- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js
+++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js
@@ -298,7 +298,7 @@
 		});
 	}
 	else{
-		frappe.msgprint("Please select Patient to get prescribed procedure");
+		frappe.msgprint(__("Please select Patient to get prescribed procedure"));
 	}
 };
 
diff --git a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.js b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.js
index c7df5b7..7ea4568 100644
--- a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.js
+++ b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.js
@@ -160,7 +160,7 @@
 
 var btn_create_procedure = function (frm) {
 	if(!frm.doc.patient){
-		frappe.throw("Please select patient");
+		frappe.throw(__("Please select patient"));
 	}
 	frappe.route_options = {
 		"patient": frm.doc.patient,
diff --git a/erpnext/hr/doctype/employee_benefit_claim/employee_benefit_claim.py b/erpnext/hr/doctype/employee_benefit_claim/employee_benefit_claim.py
index 3a80b30..abb82f2 100644
--- a/erpnext/hr/doctype/employee_benefit_claim/employee_benefit_claim.py
+++ b/erpnext/hr/doctype/employee_benefit_claim/employee_benefit_claim.py
@@ -84,7 +84,7 @@
 			pay_against_benefit_claim, max_benefit_amount = frappe.db.get_value("Salary Component", sal_struct_row.salary_component, ["pay_against_benefit_claim", "max_benefit_amount"])
 		except TypeError:
 			# show the error in tests?
-			frappe.throw("Unable to find Salary Component {0}".format(sal_struct_row.salary_component))
+			frappe.throw(_("Unable to find Salary Component {0}".format(sal_struct_row.salary_component)))
 		if sal_struct_row.is_flexible_benefit == 1 and pay_against_benefit_claim != 1:
 			total_pro_rata_max += max_benefit_amount
 	if total_pro_rata_max > 0:
diff --git a/erpnext/hr/doctype/hr_settings/hr_settings.js b/erpnext/hr/doctype/hr_settings/hr_settings.js
index d8be46b..9e5effe 100644
--- a/erpnext/hr/doctype/hr_settings/hr_settings.js
+++ b/erpnext/hr/doctype/hr_settings/hr_settings.js
@@ -15,7 +15,7 @@
 		let policy = frm.doc.password_policy;
 		if (policy) {
 			if (policy.includes(' ') || policy.includes('--')) {
-				frappe.msgprint("Password policy cannot contain spaces or simultaneous hyphens. The format will be restructured automatically");
+				frappe.msgprint(_("Password policy cannot contain spaces or simultaneous hyphens. The format will be restructured automatically"));
 			}
 			frm.set_value('password_policy', policy.split(new RegExp(" |-", 'g')).filter((token) => token).join('-'));
 		}
diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py
index 0c94df3..0d01c67 100644
--- a/erpnext/hub_node/api.py
+++ b/erpnext/hub_node/api.py
@@ -120,7 +120,7 @@
 def publish_selected_items(items_to_publish):
 	items_to_publish = json.loads(items_to_publish)
 	if not len(items_to_publish):
-		frappe.throw('No items to publish')
+		frappe.throw(_('No items to publish'))
 
 	for item in items_to_publish:
 		item_code = item.get('item_code')
@@ -165,7 +165,7 @@
 		frappe.db.set_value("Marketplace Settings", "Marketplace Settings", "sync_in_progress", 1)
 		return response
 	else:
-		frappe.throw('Unable to update remote activity')
+		frappe.throw(_('Unable to update remote activity'))
 
 
 def item_sync_postprocess():
@@ -173,7 +173,7 @@
 	if response:
 		frappe.db.set_value('Marketplace Settings', 'Marketplace Settings', 'last_sync_datetime', frappe.utils.now())
 	else:
-		frappe.throw('Unable to update remote activity')
+		frappe.throw(_('Unable to update remote activity'))
 
 	frappe.db.set_value('Marketplace Settings', 'Marketplace Settings', 'sync_in_progress', 0)
 
diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py
index ded1e53..55a6892 100644
--- a/erpnext/projects/doctype/project/project.py
+++ b/erpnext/projects/doctype/project/project.py
@@ -645,7 +645,7 @@
 	set status for project and all related tasks
 	'''
 	if not status in ('Completed', 'Cancelled'):
-		frappe.throw('Status must be Cancelled or Completed')
+		frappe.throw(_('Status must be Cancelled or Completed'))
 
 	project = frappe.get_doc('Project', project)
 	frappe.has_permission(doc = project, throw = True)
diff --git a/erpnext/public/js/education/lms/quiz.js b/erpnext/public/js/education/lms/quiz.js
index 1b520eb..5248129 100644
--- a/erpnext/public/js/education/lms/quiz.js
+++ b/erpnext/public/js/education/lms/quiz.js
@@ -68,7 +68,7 @@
 		}).then(res => {
 			this.submit_btn.remove()
 			if (!res.message) {
-				frappe.throw("Something went wrong while evaluating the quiz.")
+				frappe.throw(__("Something went wrong while evaluating the quiz."))
 			}
 
 			let indicator = 'red'
diff --git a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.html b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.html
index 77a9b63..2da79a6 100644
--- a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.html
+++ b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.html
@@ -222,17 +222,17 @@
 			</tr>
 			<tr>
 				<td>&nbsp (1) {{__("As per rules 42 & 43 of CGST Rules")}}</td>
-				<td></td>
-				<td></td>
-				<td></td>
-				<td></td>
+				<td class="right">{{ flt(data.itc_elg.itc_rev[0].iamt, 2) }}</td>
+				<td class="right">{{ flt(data.itc_elg.itc_rev[0].camt, 2) }}</td>
+				<td class="right">{{ flt(data.itc_elg.itc_rev[0].samt, 2) }}</td>
+				<td class="right">{{ flt(data.itc_elg.itc_rev[0].csamt, 2) }}</td>
 			</tr>
 			<tr>
 				<td>&nbsp (2) {{__("Others")}}</td>
-				<td></td>
-				<td></td>
-				<td></td>
-				<td></td>
+				<td class="right">{{ flt(data.itc_elg.itc_rev[1].iamt, 2) }}</td>
+				<td class="right">{{ flt(data.itc_elg.itc_rev[1].camt, 2) }}</td>
+				<td class="right">{{ flt(data.itc_elg.itc_rev[1].samt, 2) }}</td>
+				<td class="right">{{ flt(data.itc_elg.itc_rev[1].csamt, 2) }}</td>
 			</tr>
 			<tr>
 				<td><b>(C) {{__("Net ITC Available(A) - (B)")}}</b></td>
diff --git a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py
index 6569833..aad267e 100644
--- a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py
+++ b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py
@@ -4,6 +4,7 @@
 
 from __future__ import unicode_literals
 import frappe
+from frappe import _
 from frappe.model.document import Document
 import json
 from six import iteritems
@@ -91,10 +92,10 @@
 					},
 					{
 						"ty": "ISD",
-						"iamt": 1,
-						"camt": 1,
-						"samt": 1,
-						"csamt": 1
+						"iamt": 0,
+						"camt": 0,
+						"samt": 0,
+						"csamt": 0
 					},
 					{
 						"samt": 0,
@@ -104,6 +105,22 @@
 						"iamt": 0
 					}
 				],
+				"itc_rev": [
+					{
+						"ty": "RUL",
+						"iamt": 0,
+						"camt": 0,
+						"samt": 0,
+						"csamt": 0
+					},
+					{
+						"ty": "OTH",
+						"iamt": 0,
+						"camt": 0,
+						"samt": 0,
+						"csamt": 0
+					}
+				],
 				"itc_net": {
 					"samt": 0,
 					"csamt": 0,
@@ -173,6 +190,10 @@
 		net_itc = self.report_dict["itc_elg"]["itc_net"]
 
 		for d in self.report_dict["itc_elg"]["itc_avl"]:
+
+			itc_type = itc_type_map.get(d["ty"])
+			gst_category = "Registered Regular"
+
 			if d["ty"] == 'ISRC':
 				reverse_charge = "Y"
 			else:
@@ -180,24 +201,22 @@
 
 			for account_head in self.account_heads:
 
-				d["iamt"] = flt(itc_details.get((itc_type_map.get(d["ty"]), reverse_charge, account_head.get('igst_account')), {}).get("amount"), 2)
-				net_itc["iamt"] += flt(d["iamt"], 2)
+				d["iamt"] += flt(itc_details.get((gst_category, itc_type, reverse_charge, account_head.get('igst_account')), {}).get("amount"), 2)
+				d["camt"] += flt(itc_details.get((gst_category, itc_type, reverse_charge, account_head.get('cgst_account')), {}).get("amount"), 2)
+				d["samt"] += flt(itc_details.get((gst_category, itc_type, reverse_charge, account_head.get('sgst_account')), {}).get("amount"), 2)
+				d["csamt"] += flt(itc_details.get((gst_category, itc_type, reverse_charge, account_head.get('cess_account')), {}).get("amount"), 2)
 
-				d["camt"] = flt(itc_details.get((itc_type_map.get(d["ty"]), reverse_charge, account_head.get('cgst_account')), {}).get("amount"), 2)
-				net_itc["camt"] += flt(d["camt"], 2)
-
-				d["samt"] = flt(itc_details.get((itc_type_map.get(d["ty"]), reverse_charge, account_head.get('sgst_account')), {}).get("amount"), 2)
-				net_itc["samt"] += flt(d["samt"], 2)
-
-				d["csamt"] = flt(itc_details.get((itc_type_map.get(d["ty"]), reverse_charge, account_head.get('cess_account')), {}).get("amount"), 2)
-				net_itc["csamt"] += flt(d["csamt"], 2)
+			net_itc["iamt"] += flt(d["iamt"], 2)
+			net_itc["camt"] += flt(d["camt"], 2)
+			net_itc["samt"] += flt(d["samt"], 2)
+			net_itc["csamt"] += flt(d["csamt"], 2)
 
 		for account_head in self.account_heads:
-
-			self.report_dict["itc_elg"]["itc_inelg"][1]["iamt"] = flt(itc_details.get(("Ineligible", "N", account_head.get("igst_account")), {}).get("amount"), 2)
-			self.report_dict["itc_elg"]["itc_inelg"][1]["camt"] = flt(itc_details.get(("Ineligible", "N", account_head.get("cgst_account")), {}).get("amount"), 2)
-			self.report_dict["itc_elg"]["itc_inelg"][1]["samt"] = flt(itc_details.get(("Ineligible", "N", account_head.get("sgst_account")), {}).get("amount"), 2)
-			self.report_dict["itc_elg"]["itc_inelg"][1]["csamt"] = flt(itc_details.get(("Ineligible", "N", account_head.get("cess_account")), {}).get("amount"), 2)
+			itc_inelg = self.report_dict["itc_elg"]["itc_inelg"][1]
+			itc_inelg["iamt"] = flt(itc_details.get(("Ineligible", "N", account_head.get("igst_account")), {}).get("amount"), 2)
+			itc_inelg["camt"] = flt(itc_details.get(("Ineligible", "N", account_head.get("cgst_account")), {}).get("amount"), 2)
+			itc_inelg["samt"] = flt(itc_details.get(("Ineligible", "N", account_head.get("sgst_account")), {}).get("amount"), 2)
+			itc_inelg["csamt"] = flt(itc_details.get(("Ineligible", "N", account_head.get("cess_account")), {}).get("amount"), 2)
 
 	def prepare_data(self, doctype, tax_details, supply_type, supply_category, gst_category_list, reverse_charge="N"):
 
@@ -226,20 +245,22 @@
 
 	def set_inter_state_supply(self, inter_state_supply):
 
+		osup_det = self.report_dict["sup_details"]["osup_det"]
+
 		for d in inter_state_supply.get("Unregistered", []):
 			self.report_dict["inter_sup"]["unreg_details"].append(d)
-			self.report_dict["sup_details"]["osup_det"]["txval"] += flt(d["txval"], 2)
-			self.report_dict["sup_details"]["osup_det"]["iamt"] += flt(d["iamt"], 2)
+			osup_det["txval"] = flt(osup_det["txval"] + d["txval"], 2)
+			osup_det["iamt"] = flt(osup_det["iamt"] + d["iamt"], 2)
 
 		for d in inter_state_supply.get("Registered Composition", []):
 			self.report_dict["inter_sup"]["comp_details"].append(d)
-			self.report_dict["sup_details"]["osup_det"]["txval"] += flt(d["txval"], 2)
-			self.report_dict["sup_details"]["osup_det"]["iamt"] += flt(d["iamt"], 2)
+			osup_det["txval"] = flt(osup_det["txval"] + d["txval"], 2)
+			osup_det["iamt"] = flt(osup_det["iamt"] + d["iamt"], 2)
 
 		for d in inter_state_supply.get("UIN Holders", []):
 			self.report_dict["inter_sup"]["uin_details"].append(d)
-			self.report_dict["sup_details"]["osup_det"]["txval"] += flt(d["txval"], 2)
-			self.report_dict["sup_details"]["osup_det"]["iamt"] += flt(d["iamt"], 2)
+			osup_det["txval"] = flt(osup_det["txval"] + d["txval"], 2)
+			osup_det["iamt"] = flt(osup_det["iamt"] + d["iamt"], 2)
 
 	def get_total_taxable_value(self, doctype, reverse_charge):
 
@@ -268,7 +289,7 @@
 		itc_details = {}
 
 		for d in itc_amount:
-			itc_details.setdefault((d.eligibility_for_itc, d.reverse_charge, d.account_head),{
+			itc_details.setdefault((d.gst_category, d.eligibility_for_itc, d.reverse_charge, d.account_head),{
 				"amount": d.tax_amount
 			})
 
@@ -315,9 +336,10 @@
 					"iamt": flt(inter_state_supply_tax_mapping.get(d.place_of_supply), 2)
 				})
 			else:
-				self.report_dict["sup_details"]["osup_det"]["txval"] += flt(d.total, 2)
-				self.report_dict["sup_details"]["osup_det"]["camt"] += flt(inter_state_supply_tax_mapping.get(d.place_of_supply)/2, 2)
-				self.report_dict["sup_details"]["osup_det"]["samt"] += flt(inter_state_supply_tax_mapping.get(d.place_of_supply)/2, 2)
+				osup_det = self.report_dict["sup_details"]["osup_det"]
+				osup_det["txval"] = flt(osup_det["txval"] + d.total, 2)
+				osup_det["camt"] = flt(osup_det["camt"] + inter_state_supply_tax_mapping.get(d.place_of_supply)/2, 2)
+				osup_det["samt"] = flt(osup_det["samt"] + inter_state_supply_tax_mapping.get(d.place_of_supply)/2, 2)
 
 		return inter_state_supply_details
 
@@ -393,7 +415,7 @@
 		if gst_details:
 			return gst_details[0]
 		else:
-			frappe.throw("Please enter GSTIN and state for the Company Address {0}".format(self.company_address))
+			frappe.throw(_("Please enter GSTIN and state for the Company Address {0}".format(self.company_address)))
 
 	def get_account_heads(self):
 
@@ -406,7 +428,7 @@
 		if account_heads:
 			return account_heads
 		else:
-			frappe.throw("Please set account heads in GST Settings for Compnay {0}".format(self.company))
+			frappe.throw(_("Please set account heads in GST Settings for Compnay {0}".format(self.company)))
 
 	def get_missing_field_invoices(self):
 
diff --git a/erpnext/stock/report/delayed_item_report/delayed_item_report.js b/erpnext/stock/report/delayed_item_report/delayed_item_report.js
index f1ead2c..40e6abe 100644
--- a/erpnext/stock/report/delayed_item_report/delayed_item_report.js
+++ b/erpnext/stock/report/delayed_item_report/delayed_item_report.js
@@ -55,7 +55,7 @@
 			label: __("Based On"),
 			fieldtype: "Select",
 			options: ["Delivery Note", "Sales Invoice"],
-			default: "Delivery Note",
+			default: "Sales Invoice",
 			reqd: 1
 		},
 	]
diff --git a/erpnext/stock/report/delayed_item_report/delayed_item_report.py b/erpnext/stock/report/delayed_item_report/delayed_item_report.py
index 7b968b8..4fc4027 100644
--- a/erpnext/stock/report/delayed_item_report/delayed_item_report.py
+++ b/erpnext/stock/report/delayed_item_report/delayed_item_report.py
@@ -46,7 +46,8 @@
 		self.transactions = frappe.db.sql(""" SELECT `tab{child_doc}`.item_code, `tab{child_doc}`.item_name,
 				`tab{child_doc}`.item_group, `tab{child_doc}`.qty, `tab{child_doc}`.rate, `tab{child_doc}`.amount,
 				`tab{child_doc}`.so_detail, `tab{child_doc}`.{so_field} as sales_order,
-				`tab{doctype}`.customer, `tab{doctype}`.posting_date, `tab{doctype}`.name, `tab{doctype}`.grand_total
+				`tab{doctype}`.shipping_address_name, `tab{doctype}`.po_no, `tab{doctype}`.customer,
+				`tab{doctype}`.posting_date, `tab{doctype}`.name, `tab{doctype}`.grand_total
 			FROM `tab{child_doc}`, `tab{doctype}`
 			WHERE
 				`tab{child_doc}`.parent = `tab{doctype}`.name and `tab{doctype}`.docstatus = 1 and
@@ -97,12 +98,20 @@
 			"fieldtype": "Link",
 			"options": based_on,
 			"width": 100
-		},{
+		},
+		{
 			"label": _("Customer"),
 			"fieldname": "customer",
 			"fieldtype": "Link",
 			"options": "Customer",
-			"width": 100
+			"width": 200
+		},
+		{
+			"label": _("Shipping Address"),
+			"fieldname": "shipping_address_name",
+			"fieldtype": "Link",
+			"options": "Address",
+			"width": 120
 		},
 		{
 			"label": _("Expected Delivery Date"),
diff --git a/erpnext/stock/report/delayed_order_report/delayed_order_report.js b/erpnext/stock/report/delayed_order_report/delayed_order_report.js
index 5b02a58..aab0f3d 100644
--- a/erpnext/stock/report/delayed_order_report/delayed_order_report.js
+++ b/erpnext/stock/report/delayed_order_report/delayed_order_report.js
@@ -55,7 +55,7 @@
 			label: __("Based On"),
 			fieldtype: "Select",
 			options: ["Delivery Note", "Sales Invoice"],
-			default: "Delivery Note",
+			default: "Sales Invoice",
 			reqd: 1
 		},
 	]
diff --git a/erpnext/stock/report/delayed_order_report/delayed_order_report.py b/erpnext/stock/report/delayed_order_report/delayed_order_report.py
index d2a1a30..79dc5d8 100644
--- a/erpnext/stock/report/delayed_order_report/delayed_order_report.py
+++ b/erpnext/stock/report/delayed_order_report/delayed_order_report.py
@@ -42,7 +42,14 @@
 			"fieldname": "customer",
 			"fieldtype": "Link",
 			"options": "Customer",
-			"width": 100
+			"width": 200
+		},
+		{
+			"label": _("Shipping Address"),
+			"fieldname": "shipping_address_name",
+			"fieldtype": "Link",
+			"options": "Address",
+			"width": 140
 		},
 		{
 			"label": _("Expected Delivery Date"),
@@ -73,11 +80,11 @@
 			"fieldname": "sales_order",
 			"fieldtype": "Link",
 			"options": "Sales Order",
-			"width": 100
+			"width": 150
 		},
 		{
 			"label": _("Customer PO"),
 			"fieldname": "po_no",
 			"fieldtype": "Data",
-			"width": 100
+			"width": 110
 		}]
\ No newline at end of file