fix: Purchase from registered composition dealer (#25057)

* fix: Purchase from registered composition dealer

* fix: Test case for GSTR 3b report
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 888b2da..369a400 100644
--- a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.html
+++ b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.html
@@ -109,7 +109,7 @@
 			</td>
 		</tr>
 		<tr>
-			<td>{{__("Suppliies made to Composition Taxable Persons")}}</td>
+			<td>{{__("Supplies made to Composition Taxable Persons")}}</td>
 			<td class="right">
 				{% for row in data.inter_sup.comp_details %}
 					{% if row %}
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 a49996d..a5dd5a2 100644
--- a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py
+++ b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py
@@ -172,7 +172,6 @@
 		self.json_output = frappe.as_json(self.report_dict)
 
 	def set_inward_nil_exempt(self, inward_nil_exempt):
-
 		self.report_dict["inward_sup"]["isup_details"][0]["inter"] = flt(inward_nil_exempt.get("gst").get("inter"), 2)
 		self.report_dict["inward_sup"]["isup_details"][0]["intra"] = flt(inward_nil_exempt.get("gst").get("intra"), 2)
 		self.report_dict["inward_sup"]["isup_details"][1]["inter"] = flt(inward_nil_exempt.get("non_gst").get("inter"), 2)
@@ -238,7 +237,6 @@
 		self.report_dict[supply_type][supply_category]["txval"] += flt(txval, 2)
 
 	def set_inter_state_supply(self, inter_state_supply):
-
 		osup_det = self.report_dict["sup_details"]["osup_det"]
 
 		for key, value in iteritems(inter_state_supply):
@@ -352,10 +350,18 @@
 		inward_nil_exempt = frappe.db.sql(""" select p.place_of_supply, sum(i.base_amount) as base_amount,
 			i.is_nil_exempt, i.is_non_gst from `tabPurchase Invoice` p , `tabPurchase Invoice Item` i
 			where p.docstatus = 1 and p.name = i.parent
+			and p.gst_category != 'Registered Composition'
 			and (i.is_nil_exempt = 1 or i.is_non_gst = 1) and
 			month(p.posting_date) = %s and year(p.posting_date) = %s and p.company = %s and p.company_gstin = %s
 			group by p.place_of_supply, i.is_nil_exempt, i.is_non_gst""", (self.month_no, self.year, self.company, self.gst_details.get("gstin")), as_dict=1)
 
+		inward_nil_exempt += frappe.db.sql("""SELECT sum(base_net_total) as base_amount, gst_category, place_of_supply
+			FROM `tabPurchase Invoice`
+			WHERE docstatus = 1 and gst_category = 'Registered Composition'
+			and month(posting_date) = %s and year(posting_date) = %s
+			and company = %s and company_gstin = %s
+			group by place_of_supply""", (self.month_no, self.year, self.company, self.gst_details.get("gstin")), as_dict=1)
+
 		inward_nil_exempt_details = {
 			"gst": {
 				"intra": 0.0,
@@ -369,9 +375,11 @@
 
 		for d in inward_nil_exempt:
 			if d.place_of_supply:
-				if d.is_nil_exempt == 1 and state == d.place_of_supply.split("-")[1]:
+				if (d.is_nil_exempt == 1 or d.get('gst_category') == 'Registered Composition') \
+					and state == d.place_of_supply.split("-")[1]:
 					inward_nil_exempt_details["gst"]["intra"] += d.base_amount
-				elif d.is_nil_exempt == 1 and state != d.place_of_supply.split("-")[1]:
+				elif (d.is_nil_exempt == 1 or d.get('gst_category') == 'Registered Composition') \
+					and state != d.place_of_supply.split("-")[1]:
 					inward_nil_exempt_details["gst"]["inter"] += d.base_amount
 				elif d.is_non_gst == 1 and state == d.place_of_supply.split("-")[1]:
 					inward_nil_exempt_details["non_gst"]["intra"] += d.base_amount
diff --git a/erpnext/regional/doctype/gstr_3b_report/test_gstr_3b_report.py b/erpnext/regional/doctype/gstr_3b_report/test_gstr_3b_report.py
index 023b4ed..ef8af24 100644
--- a/erpnext/regional/doctype/gstr_3b_report/test_gstr_3b_report.py
+++ b/erpnext/regional/doctype/gstr_3b_report/test_gstr_3b_report.py
@@ -64,7 +64,7 @@
 		self.assertEqual(output["sup_details"]["osup_zero"]["iamt"], 18),
 		self.assertEqual(output["inter_sup"]["unreg_details"][0]["iamt"], 18),
 		self.assertEqual(output["sup_details"]["osup_nil_exmp"]["txval"], 100),
-		self.assertEqual(output["inward_sup"]["isup_details"][0]["inter"], 250)
+		self.assertEqual(output["inward_sup"]["isup_details"][0]["intra"], 250)
 		self.assertEqual(output["itc_elg"]["itc_avl"][4]["samt"], 22.50)
 		self.assertEqual(output["itc_elg"]["itc_avl"][4]["camt"], 22.50)
 
@@ -228,6 +228,19 @@
 
 	pi1.submit()
 
+	pi2 = make_purchase_invoice(company="_Test Company GST",
+			customer = '_Test Registered Supplier',
+			currency = 'INR',
+			item = 'Milk',
+			warehouse = 'Finished Goods - _GST',
+			expense_account = 'Cost of Goods Sold - _GST',
+			cost_center = 'Main - _GST',
+			rate=250,
+			qty=1,
+			do_not_save=1
+		)
+	pi2.submit()
+
 def make_suppliers():
 	if not frappe.db.exists("Supplier", "_Test Registered Supplier"):
 		frappe.get_doc({
diff --git a/erpnext/regional/report/gstr_2/gstr_2.py b/erpnext/regional/report/gstr_2/gstr_2.py
index f899349..616c2b8 100644
--- a/erpnext/regional/report/gstr_2/gstr_2.py
+++ b/erpnext/regional/report/gstr_2/gstr_2.py
@@ -44,7 +44,7 @@
 		for inv, items_based_on_rate in self.items_based_on_tax_rate.items():
 			invoice_details = self.invoices.get(inv)
 			for rate, items in items_based_on_rate.items():
-				if rate:
+				if rate or invoice_details.get('gst_category') == 'Registered Composition':
 					if inv not in self.igst_invoices:
 						rate = rate / 2
 						row, taxable_value = self.get_row_data_for_invoice(inv, invoice_details, rate, items)
@@ -86,7 +86,7 @@
 					conditions += opts[1]
 
 		if self.filters.get("type_of_business") ==  "B2B":
-			conditions += "and ifnull(gst_category, '') in ('Registered Regular', 'Deemed Export', 'SEZ') and is_return != 1 "
+			conditions += "and ifnull(gst_category, '') in ('Registered Regular', 'Deemed Export', 'SEZ', 'Registered Composition') and is_return != 1 "
 
 		elif self.filters.get("type_of_business") ==  "CDNR":
 			conditions += """ and is_return = 1 """