Merge pull request #22697 from rohitwaghchaure/fixed-not-able-to-submit-si

fix: not able to submit sales invoice
diff --git a/erpnext/patches/v13_0/update_actual_start_and_end_date_in_wo.py b/erpnext/patches/v13_0/update_actual_start_and_end_date_in_wo.py
index 331c559..adfa20e 100644
--- a/erpnext/patches/v13_0/update_actual_start_and_end_date_in_wo.py
+++ b/erpnext/patches/v13_0/update_actual_start_and_end_date_in_wo.py
@@ -6,7 +6,6 @@
 
 import frappe
 from frappe.utils import add_to_date
-from frappe.utils.dashboard import get_config, make_records
 
 def execute():
 	frappe.reload_doc("manufacturing", "doctype", "work_order")
diff --git a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.js b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.js
index a1cea8f..5170185 100644
--- a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.js
+++ b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.js
@@ -45,6 +45,10 @@
 		frm.set_df_property('year', 'options', options);
 	},
 
+	validate: function(frm) {
+		frm.dirty();
+	},
+
 	setup: function(frm) {
 		frm.set_query('company_address', function(doc) {
 			if(!doc.company) {
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 619734f..6d9b8db 100644
--- a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py
+++ b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py
@@ -243,20 +243,15 @@
 
 		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)
-			osup_det["txval"] = flt(osup_det["txval"] + d["txval"], 2)
-			osup_det["iamt"] = flt(osup_det["iamt"] + d["iamt"], 2)
+		for key, value in iteritems(inter_state_supply):
+			if key[0] == "Unregistered":
+				self.report_dict["inter_sup"]["unreg_details"].append(value)
 
-		for d in inter_state_supply.get("Registered Composition", []):
-			self.report_dict["inter_sup"]["comp_details"].append(d)
-			osup_det["txval"] = flt(osup_det["txval"] + d["txval"], 2)
-			osup_det["iamt"] = flt(osup_det["iamt"] + d["iamt"], 2)
+			if key[0] == "Registered Composition":
+				self.report_dict["inter_sup"]["comp_details"].append(value)
 
-		for d in inter_state_supply.get("UIN Holders", []):
-			self.report_dict["inter_sup"]["uin_details"].append(d)
-			osup_det["txval"] = flt(osup_det["txval"] + d["txval"], 2)
-			osup_det["iamt"] = flt(osup_det["iamt"] + d["iamt"], 2)
+			if key[0] == "UIN Holders":
+				self.report_dict["inter_sup"]["uin_details"].append(value)
 
 	def get_total_taxable_value(self, doctype, reverse_charge):
 
@@ -301,41 +296,54 @@
 			(self.month_no, self.year, self.company, self.gst_details.get("gstin")), as_dict=1)[0].total
 
 	def get_inter_state_supplies(self, state_number):
-
-		inter_state_supply_taxable_value = frappe.db.sql(""" select sum(s.net_total) as total, s.place_of_supply, s.gst_category
-			from `tabSales Invoice` s where s.docstatus = 1 and month(s.posting_date) = %s and year(s.posting_date) = %s
-			and s.company = %s and s.company_gstin = %s and s.gst_category in ('Unregistered', 'Registered Composition', 'UIN Holders')
-			group by s.gst_category, s.place_of_supply""", (self.month_no, self.year, self.company, self.gst_details.get("gstin")), as_dict=1)
-
-		inter_state_supply_tax = frappe.db.sql(""" select sum(t.tax_amount_after_discount_amount) as tax_amount, s.place_of_supply, s.gst_category
-			from `tabSales Invoice` s, `tabSales Taxes and Charges` t
+		inter_state_supply_tax = frappe.db.sql(""" select t.account_head, t.tax_amount_after_discount_amount as tax_amount,
+			s.name, s.net_total, s.place_of_supply, s.gst_category from `tabSales Invoice` s, `tabSales Taxes and Charges` t
 			where t.parent = s.name and s.docstatus = 1 and month(s.posting_date) = %s and year(s.posting_date) = %s
 			and s.company = %s and s.company_gstin = %s and s.gst_category in ('Unregistered', 'Registered Composition', 'UIN Holders')
-			group by s.gst_category, s.place_of_supply""", (self.month_no, self.year, self.company, self.gst_details.get("gstin")), as_dict=1)
+		""", (self.month_no, self.year, self.company, self.gst_details.get("gstin")), as_dict=1)
 
-		inter_state_supply_tax_mapping={}
+		inter_state_supply_tax_mapping = {}
 		inter_state_supply_details = {}
 
 		for d in inter_state_supply_tax:
-			inter_state_supply_tax_mapping.setdefault(d.place_of_supply, d.tax_amount)
+			inter_state_supply_tax_mapping.setdefault(d.name, {
+				'place_of_supply': d.place_of_supply,
+				'taxable_value': d.net_total,
+				'camt': 0.0,
+				'samt': 0.0,
+				'iamt': 0.0,
+				'csamt': 0.0
+			})
 
-		for d in inter_state_supply_taxable_value:
-			inter_state_supply_details.setdefault(
-				d.gst_category, []
-			)
+			if d.account_head in [d.cgst_account for d in self.account_heads]:
+				inter_state_supply_tax_mapping[d.name]['camt'] += d.tax_amount
 
+			if d.account_head in [d.sgst_account for d in self.account_heads]:
+				inter_state_supply_tax_mapping[d.name]['samt'] += d.tax_amount
+
+			if d.account_head in [d.igst_account for d in self.account_heads]:
+				inter_state_supply_tax_mapping[d.name]['samt'] += d.tax_amount
+
+			if d.account_head in [d.cess_account for d in self.account_heads]:
+				inter_state_supply_tax_mapping[d.name]['csamt'] += d.tax_amount
+
+		for key, value in iteritems(inter_state_supply_tax_mapping):
 			if d.place_of_supply:
+				osup_det = self.report_dict["sup_details"]["osup_det"]
+				osup_det["txval"] = flt(osup_det["txval"] + value['taxable_value'], 2)
+				osup_det["camt"] = flt(osup_det["camt"] + value['camt'], 2)
+				osup_det["samt"] = flt(osup_det["samt"] + value['samt'], 2)
+				osup_det["csamt"] = flt(osup_det["csamt"] + value['csamt'], 2)
+
 				if state_number != d.place_of_supply.split("-")[0]:
-					inter_state_supply_details[d.gst_category].append({
+					inter_state_supply_details.setdefault((d.gst_category, d.place_of_supply), {
+						"txval": 0.0,
 						"pos": d.place_of_supply.split("-")[0],
-						"txval": flt(d.total, 2),
-						"iamt": flt(inter_state_supply_tax_mapping.get(d.place_of_supply), 2)
+						"iamt": 0.0
 					})
-				else:
-					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)
+
+					inter_state_supply_details[(d.gst_category, d.place_of_supply)]['txval'] += value['taxable_value']
+					inter_state_supply_details[(d.gst_category, d.place_of_supply)]['iamt'] += value['iamt']
 
 		return inter_state_supply_details
 
diff --git a/erpnext/stock/report/stock_ledger/stock_ledger.py b/erpnext/stock/report/stock_ledger/stock_ledger.py
index abf959e..a5f92e2 100644
--- a/erpnext/stock/report/stock_ledger/stock_ledger.py
+++ b/erpnext/stock/report/stock_ledger/stock_ledger.py
@@ -4,10 +4,10 @@
 from __future__ import unicode_literals
 
 import frappe
+from frappe.utils import cint, flt
 from erpnext.stock.utils import update_included_uom_in_report
 from frappe import _
 
-
 def execute(filters=None):
 	include_uom = filters.get("include_uom")
 	columns = get_columns()
@@ -15,6 +15,7 @@
 	sl_entries = get_stock_ledger_entries(filters, items)
 	item_details = get_item_details(items, sl_entries, include_uom)
 	opening_row = get_opening_balance(filters, columns)
+	precision = cint(frappe.db.get_single_value("System Settings", "float_precision"))
 
 	data = []
 	conversion_factors = []
@@ -29,7 +30,7 @@
 		sle.update(item_detail)
 
 		if filters.get("batch_no"):
-			actual_qty += sle.actual_qty
+			actual_qty += flt(sle.actual_qty, precision)
 			stock_value += sle.stock_value_difference
 
 			if sle.voucher_type == 'Stock Reconciliation':