<commit_before># Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from datetime import date
from erpnext.regional.report.gstr_1.gstr_1 import Gstr1Report

def execute(filters=None):
	return Gstr2Report(filters).run()

class Gstr2Report(Gstr1Report):
	def __init__(self, filters=None):
		self.filters = frappe._dict(filters or {})
		self.columns = []
		self.data = []
		self.doctype = "Purchase Invoice"
		self.tax_doctype = "Purchase Taxes and Charges"
		self.select_columns = """
			name as invoice_number,
			supplier_name,
			posting_date,
			base_grand_total,
			base_rounded_total,
			supplier_gstin,
			place_of_supply,
			ecommerce_gstin,
			reverse_charge,
			invoice_type,
			return_against,
			is_return,
			invoice_type,
			export_type,
			reason_for_issuing_document,
			eligibility_for_itc,
			itc_integrated_tax,
			itc_central_tax,
			itc_state_tax,
			itc_cess_amount
		"""

	def get_data(self):
		self.get_igst_invoices()
		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():
				row, taxable_value = self.get_row_data_for_invoice(inv, invoice_details, rate, items)
				tax_amount = taxable_value * rate / 100
				if inv in self.igst_invoices:
					row += [tax_amount, 0, 0]
				else:
					row += [0, tax_amount / 2, tax_amount / 2]

				row += [
					self.invoice_cess.get(inv),
					invoice_details.get('eligibility_for_itc'),
					invoice_details.get('itc_integrated_tax'),
					invoice_details.get('itc_central_tax'),
					invoice_details.get('itc_state_tax'),
					invoice_details.get('itc_cess_amount')
				]
				if self.filters.get("type_of_business") ==  "CDNR":
					row.append("Y" if invoice_details.posting_date <= date(2017, 7, 1) else "N")
					row.append("C" if invoice_details.return_against else "R")

				self.data.append(row)

	def get_igst_invoices(self):
		self.igst_invoices = []
		for d in self.tax_details:
			is_igst = True if d[1] in self.gst_accounts.igst_account else False
			if is_igst and d[0] not in self.igst_invoices:
				self.igst_invoices.append(d[0])
			if is_igst:
				break

	def get_conditions(self):
		conditions = ""

		for opts in (("company", " and company=%(company)s"),
			("from_date", " and posting_date>=%(from_date)s"),
			("to_date", " and posting_date<=%(to_date)s")):
				if self.filters.get(opts[0]):
					conditions += opts[1]

		if self.filters.get("type_of_business") ==  "B2B":
			conditions += "and ifnull(invoice_type, '') != 'Export' and is_return != 1 "

		elif self.filters.get("type_of_business") ==  "CDNR":
			conditions += """ and is_return = 1 """
<commit_msg>Fixed IGST ISSUE (#14975)<commit_after># Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from datetime import date
from erpnext.regional.report.gstr_1.gstr_1 import Gstr1Report

def execute(filters=None):
	return Gstr2Report(filters).run()

class Gstr2Report(Gstr1Report):
	def __init__(self, filters=None):
		self.filters = frappe._dict(filters or {})
		self.columns = []
		self.data = []
		self.doctype = "Purchase Invoice"
		self.tax_doctype = "Purchase Taxes and Charges"
		self.select_columns = """
			name as invoice_number,
			supplier_name,
			posting_date,
			base_grand_total,
			base_rounded_total,
			supplier_gstin,
			place_of_supply,
			ecommerce_gstin,
			reverse_charge,
			invoice_type,
			return_against,
			is_return,
			invoice_type,
			export_type,
			reason_for_issuing_document,
			eligibility_for_itc,
			itc_integrated_tax,
			itc_central_tax,
			itc_state_tax,
			itc_cess_amount
		"""

	def get_data(self):
		self.get_igst_invoices()
		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():
				row, taxable_value = self.get_row_data_for_invoice(inv, invoice_details, rate, items)
				tax_amount = taxable_value * rate / 100
				if inv in self.igst_invoices:
					row += [tax_amount, 0, 0]
				else:
					row += [0, tax_amount / 2, tax_amount / 2]

				row += [
					self.invoice_cess.get(inv),
					invoice_details.get('eligibility_for_itc'),
					invoice_details.get('itc_integrated_tax'),
					invoice_details.get('itc_central_tax'),
					invoice_details.get('itc_state_tax'),
					invoice_details.get('itc_cess_amount')
				]
				if self.filters.get("type_of_business") ==  "CDNR":
					row.append("Y" if invoice_details.posting_date <= date(2017, 7, 1) else "N")
					row.append("C" if invoice_details.return_against else "R")

				self.data.append(row)

	def get_igst_invoices(self):
		self.igst_invoices = []
		for d in self.tax_details:
			is_igst = True if d[1] in self.gst_accounts.igst_account else False
			if is_igst and d[0] not in self.igst_invoices:
				self.igst_invoices.append(d[0])

	def get_conditions(self):
		conditions = ""

		for opts in (("company", " and company=%(company)s"),
			("from_date", " and posting_date>=%(from_date)s"),
			("to_date", " and posting_date<=%(to_date)s")):
				if self.filters.get(opts[0]):
					conditions += opts[1]

		if self.filters.get("type_of_business") ==  "B2B":
			conditions += "and ifnull(invoice_type, '') != 'Export' and is_return != 1 "

		elif self.filters.get("type_of_business") ==  "CDNR":
			conditions += """ and is_return = 1 """

{'fraction_non_alphanumeric': 0.12150712096628809, 'fraction_numerical': 0.012439156300703082, 'mean_word_length': 4.204502814258912, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1872961', 'n_tokens_mistral': 2417, 'n_tokens_neox': 2024, 'n_words': 402}