mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-17 17:26:43 +00:00
Merge pull request #22730 from deepeshgarg007/gstr3b_cess_v12_hotfix
fix: Multiple GST fixes
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
frappe.ui.form.on('GSTR 3B Report', {
|
||||
refresh : function(frm) {
|
||||
frm.doc.__unsaved = 1;
|
||||
if(!frm.is_new()) {
|
||||
frm.set_intro(__("Please save the report again to rebuild or update"));
|
||||
frm.add_custom_button(__('Download JSON'), function() {
|
||||
|
||||
@@ -8,7 +8,7 @@ from frappe import _
|
||||
from frappe.model.document import Document
|
||||
import json
|
||||
from six import iteritems
|
||||
from frappe.utils import flt, getdate
|
||||
from frappe.utils import flt, getdate, cstr
|
||||
from erpnext.regional.india import state_numbers
|
||||
|
||||
class GSTR3BReport(Document):
|
||||
@@ -234,34 +234,26 @@ class GSTR3BReport(Document):
|
||||
self.report_dict[supply_type][supply_category][account_map.get(account_type)] += \
|
||||
flt(tax_details.get((account_name, gst_category), {}).get("amount"), 2)
|
||||
|
||||
for k, v in iteritems(account_map):
|
||||
txval -= self.report_dict.get(supply_type, {}).get(supply_category, {}).get(v, 0)
|
||||
|
||||
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 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):
|
||||
|
||||
return frappe._dict(frappe.db.sql("""
|
||||
select gst_category, sum(base_grand_total) as total
|
||||
select gst_category, sum(net_total) as total
|
||||
from `tab{doctype}`
|
||||
where docstatus = 1 and month(posting_date) = %s
|
||||
and year(posting_date) = %s and reverse_charge = %s
|
||||
@@ -301,41 +293,57 @@ class GSTR3BReport(Document):
|
||||
(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)
|
||||
and ifnull(s.name, '') != ''
|
||||
""", (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(cstr(d.name), {
|
||||
'place_of_supply': d.place_of_supply,
|
||||
'taxable_value': d.net_total,
|
||||
'gst_category': d.gst_category,
|
||||
'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 [a.cgst_account for a in self.account_heads]:
|
||||
inter_state_supply_tax_mapping[cstr(d.name)]['camt'] += d.tax_amount
|
||||
|
||||
if d.place_of_supply:
|
||||
if state_number != d.place_of_supply.split("-")[0]:
|
||||
inter_state_supply_details[d.gst_category].append({
|
||||
"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)
|
||||
if d.account_head in [a.sgst_account for a in self.account_heads]:
|
||||
inter_state_supply_tax_mapping[cstr(d.name)]['samt'] += d.tax_amount
|
||||
|
||||
if d.account_head in [a.igst_account for a in self.account_heads]:
|
||||
inter_state_supply_tax_mapping[cstr(d.name)]['iamt'] += d.tax_amount
|
||||
|
||||
if d.account_head in [a.cess_account for a in self.account_heads]:
|
||||
inter_state_supply_tax_mapping[cstr(d.name)]['csamt'] += d.tax_amount
|
||||
|
||||
for key, value in iteritems(inter_state_supply_tax_mapping):
|
||||
if value.get('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["iamt"] = flt(osup_det["iamt"] + value['iamt'], 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 != value.get('place_of_supply').split("-")[0]:
|
||||
inter_state_supply_details.setdefault((value.get('gst_category'), value.get('place_of_supply')), {
|
||||
"txval": 0.0,
|
||||
"pos": value.get('place_of_supply').split("-")[0],
|
||||
"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[(value.get('gst_category'), value.get('place_of_supply'))]['txval'] += value['taxable_value']
|
||||
inter_state_supply_details[(value.get('gst_category'), value.get('place_of_supply'))]['iamt'] += value['iamt']
|
||||
|
||||
return inter_state_supply_details
|
||||
|
||||
|
||||
@@ -387,6 +387,10 @@ def make_company():
|
||||
|
||||
def set_account_heads():
|
||||
|
||||
from erpnext.accounts.doctype.account.test_account import create_account
|
||||
|
||||
create_account(account_name="Cess", parent_account = "Duties and Taxes - _GST", company="_Test Company GST")
|
||||
|
||||
gst_settings = frappe.get_doc("GST Settings")
|
||||
|
||||
gst_account = frappe.get_all(
|
||||
@@ -400,6 +404,7 @@ def set_account_heads():
|
||||
"cgst_account": "CGST - _GST",
|
||||
"sgst_account": "SGST - _GST",
|
||||
"igst_account": "IGST - _GST",
|
||||
"cess_account": "Cess - _GST"
|
||||
})
|
||||
|
||||
gst_settings.save()
|
||||
|
||||
@@ -689,9 +689,10 @@ def update_totals(gst_tax, doc):
|
||||
doc.rounding_adjustment += flt(doc.rounded_total - doc.grand_total,
|
||||
doc.precision("rounding_adjustment"))
|
||||
|
||||
doc.outstanding_amount = doc.base_rounded_total
|
||||
doc.outstanding_amount = doc.rounded_total or doc.grand_total
|
||||
|
||||
doc.in_words = money_in_words(doc.grand_total, doc.currency)
|
||||
doc.set_payment_schedule()
|
||||
|
||||
def make_regional_gl_entries(gl_entries, doc):
|
||||
country = frappe.get_cached_value('Company', doc.company, 'country')
|
||||
|
||||
@@ -118,7 +118,7 @@ class Gstr1Report(object):
|
||||
row.append(invoice_details.get(fieldname))
|
||||
taxable_value = 0
|
||||
|
||||
if invoice in self.cgst_igst_invoices:
|
||||
if invoice in self.cgst_sgst_invoices:
|
||||
division_factor = 2
|
||||
else:
|
||||
division_factor = 1
|
||||
@@ -129,6 +129,8 @@ class Gstr1Report(object):
|
||||
taxable_value += abs(net_amount)
|
||||
elif not self.item_tax_rate.get(invoice):
|
||||
taxable_value += abs(net_amount)
|
||||
elif tax_rate:
|
||||
taxable_value += abs(net_amount)
|
||||
|
||||
row += [tax_rate or 0, taxable_value]
|
||||
|
||||
@@ -227,7 +229,7 @@ class Gstr1Report(object):
|
||||
|
||||
self.items_based_on_tax_rate = {}
|
||||
self.invoice_cess = frappe._dict()
|
||||
self.cgst_igst_invoices = []
|
||||
self.cgst_sgst_invoices = []
|
||||
|
||||
unidentified_gst_accounts = []
|
||||
for parent, account, item_wise_tax_detail, tax_amount in self.tax_details:
|
||||
@@ -251,8 +253,8 @@ class Gstr1Report(object):
|
||||
tax_rate = tax_amounts[0]
|
||||
if cgst_or_sgst:
|
||||
tax_rate *= 2
|
||||
if parent not in self.cgst_igst_invoices:
|
||||
self.cgst_igst_invoices.append(parent)
|
||||
if parent not in self.cgst_sgst_invoices:
|
||||
self.cgst_sgst_invoices.append(parent)
|
||||
|
||||
rate_based_dict = self.items_based_on_tax_rate\
|
||||
.setdefault(parent, {}).setdefault(tax_rate, [])
|
||||
|
||||
@@ -44,30 +44,30 @@ class Gstr2Report(Gstr1Report):
|
||||
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 inv not in self.igst_invoices:
|
||||
rate = rate / 2
|
||||
row, taxable_value = self.get_row_data_for_invoice(inv, invoice_details, rate, items)
|
||||
tax_amount = taxable_value * rate / 100
|
||||
row += [0, tax_amount, tax_amount]
|
||||
else:
|
||||
row, taxable_value = self.get_row_data_for_invoice(inv, invoice_details, rate, items)
|
||||
tax_amount = taxable_value * rate / 100
|
||||
row += [tax_amount, 0, 0]
|
||||
if rate:
|
||||
if inv not in self.igst_invoices:
|
||||
rate = rate / 2
|
||||
row, taxable_value = self.get_row_data_for_invoice(inv, invoice_details, rate, items)
|
||||
tax_amount = taxable_value * rate / 100
|
||||
row += [0, tax_amount, tax_amount]
|
||||
else:
|
||||
row, taxable_value = self.get_row_data_for_invoice(inv, invoice_details, rate, items)
|
||||
tax_amount = taxable_value * rate / 100
|
||||
row += [tax_amount, 0, 0]
|
||||
|
||||
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")
|
||||
|
||||
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)
|
||||
self.data.append(row)
|
||||
|
||||
def get_igst_invoices(self):
|
||||
self.igst_invoices = []
|
||||
@@ -86,7 +86,7 @@ class Gstr2Report(Gstr1Report):
|
||||
conditions += opts[1]
|
||||
|
||||
if self.filters.get("type_of_business") == "B2B":
|
||||
conditions += "and ifnull(gst_category, '') != 'Overseas' and is_return != 1 "
|
||||
conditions += "and ifnull(gst_category, '') in ('Registered Regular', 'Deemed Export', 'SEZ') and is_return != 1 "
|
||||
|
||||
elif self.filters.get("type_of_business") == "CDNR":
|
||||
conditions += """ and is_return = 1 """
|
||||
|
||||
Reference in New Issue
Block a user