Skip to content

Commit

Permalink
Merge pull request #2432 from resilient-tech/version-15-hotfix
Browse files Browse the repository at this point in the history
chore: release v15
  • Loading branch information
vorasmit authored Jul 17, 2024
2 parents 3fc363d + 37495d8 commit 79ee2df
Show file tree
Hide file tree
Showing 23 changed files with 337 additions and 64 deletions.
12 changes: 10 additions & 2 deletions india_compliance/audit_trail/report/audit_trail/audit_trail.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@

import frappe
from frappe import _
from frappe.utils.data import format_datetime, get_timespan_date_range, getdate
from frappe.utils.data import (
format_date,
format_datetime,
get_timespan_date_range,
get_user_date_format,
getdate,
)

from india_compliance.audit_trail.utils import get_audit_trail_doctypes

Expand Down Expand Up @@ -271,7 +277,9 @@ def append_rows(self, records, doctype):
for row in records:
row["date_time"] = format_datetime(row["date_time"])
row["doctype"] = doctype
row["creation_date"] = getdate(row["date_time"])
row["creation_date"] = getdate(
format_date(row["date_time"], get_user_date_format())
)

if doctype == "Bill of Entry":
row["party_name"] = ""
Expand Down
12 changes: 12 additions & 0 deletions india_compliance/gst_india/client_scripts/party.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function validate_gstin(doctype) {
if (PAN_REGEX.test(pan)) {
frm.doc.pan = pan;
frm.refresh_field("pan");
set_party_type(frm);
}
},
});
Expand All @@ -93,6 +94,7 @@ function validate_pan(doctype) {

frm.doc.pan = pan;
frm.refresh_field("pan");
set_party_type(frm);
},
});
}
Expand Down Expand Up @@ -147,3 +149,13 @@ function set_gst_category(doctype) {
},
});
}

function set_party_type(frm) {
if (!["Customer", "Supplier"].includes(frm.doc.doctype)) return;
pan_to_party_type_map = {
F: "Partnership",
C: "Company",
};
party_type = frm.doc.doctype === "Customer" ? "customer_type" : "supplier_type";
frm.set_value(party_type, pan_to_party_type_map[frm.doc.pan[3]] || "Individual");
}
12 changes: 12 additions & 0 deletions india_compliance/gst_india/constants/custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,8 @@
"fieldtype": "Link",
"options": "GST HSN Code",
"insert_after": "item_group",
"fetch_from": "item_group.gst_hsn_code",
"fetch_if_empty": 1,
"allow_in_quick_entry": 1,
"mandatory_depends_on": "eval:gst_settings.validate_hsn_code && doc.is_sales_item",
"description": "You can search code by the description of the category.",
Expand All @@ -926,6 +928,16 @@
"insert_after": "item_tax_section_break",
},
],
"Item Group": [
{
"fieldname": "gst_hsn_code",
"label": "HSN/SAC",
"fieldtype": "Link",
"options": "GST HSN Code",
"insert_after": "defaults",
"description": "You can search code by the description of the category.",
},
],
"Item Tax Template": [
{
"fieldname": "gst_treatment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

frappe.ui.form.on('GST HSN Code', {
refresh: function(frm) {
if(! frm.doc.__islocal && frm.doc.taxes.length){
if(!frm.doc.__islocal){
frm.add_custom_button(__('Update Taxes for Items'), function(){
frappe.confirm(
'Are you sure? It will overwrite taxes for all items with HSN Code <b>'+frm.doc.name+'</b>.',
Expand Down
27 changes: 24 additions & 3 deletions india_compliance/gst_india/doctype/gst_settings/gst_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,26 @@ def update_retry_e_invoice_e_waybill_scheduled_job(self):

frappe.db.set_value(
"Scheduled Job Type",
"e_invoice.retry_e_invoice_e_waybill_generation",
{
"method": "india_compliance.gst_india.utils.e_invoice.retry_e_invoice_e_waybill_generation"
},
"stopped",
not self.enable_retry_einv_ewb_generation,
)

def update_auto_refresh_authtoken_scheduled_job(self):
if not self.has_value_changed("enable_auto_reconciliation"):
return

frappe.db.set_value(
"Scheduled Job Type",
{
"method": "india_compliance.gst_india.doctype.purchase_reconciliation_tool.purchase_reconciliation_tool.auto_refresh_authtoken"
},
"stopped",
not self.enable_auto_reconciliation,
)

def get_gstin_with_credentials(self, service=None):
if not service:
return
Expand Down Expand Up @@ -365,9 +380,15 @@ def update_gst_category():

# party-wise addresses
category_map = {}
gstin_info_map = {}

for address in address_without_category:
gstin_info = get_gstin_info(address.gstin)
gst_category = gstin_info.gst_category
gstin = address.gstin

if gstin not in gstin_info_map:
gstin_info_map[gstin] = get_gstin_info(gstin)

gst_category = gstin_info_map[gstin].gst_category

category_map.setdefault(gst_category, []).append(address.name)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def recompute_books(self):

@frappe.whitelist()
def sync_with_gstn(self, sync_for):
self.validate(sync_for=sync_for)
self.validate(sync_for=sync_for, recompute_books=True)

@frappe.whitelist()
def mark_as_filed(self):
Expand Down
12 changes: 12 additions & 0 deletions india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ def process_data(self, data):
if row.get("upload_status") != "Missing in Books"
]

if category == GovJsonKey.DOC_ISSUE.value:
self.process_doc_issue_data(category_wise_data[category])

if category not in [
GovJsonKey.CDNR.value,
GovJsonKey.CDNUR.value,
Expand Down Expand Up @@ -195,6 +198,15 @@ def build_excel(self, data):
excel.remove_sheet("Sheet")
excel.export(get_file_name("Gov", self.gstin, self.period))

def process_doc_issue_data(self, data):
"""
Add draft count to cancelled count for DOC_ISSUE category
"""
for doc in data:
doc[GSTR1_DataField.CANCELLED_COUNT.value] += doc.get(
GSTR1_DataField.DRAFT_COUNT.value, 0
)

def get_category_headers(self, category):
return getattr(self, f"get_{category.lower()}_headers")()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,41 @@ <h5>3.1&nbsp&nbsp{{__("Details of Outward Supplies and inward supplies liable to
</tbody>
</table>

<h5>
3.1.1&nbsp&nbsp{{__("Supplies notified under section 9(5) of the CGST Act, 2017")}}
</h5>
<table class="table table-bordered">
<thead>
<tr>
<th>{{__("Description")}}</th>
<th>{{__("Total Taxable Value")}}</th>
<th>{{__("Integrated Tax")}}</th>
<th>{{__("Central Tax")}}</th>
<th>{{__("State/UT Tax")}}</th>
<th>{{__("Cess")}}</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{__("(i) Taxable supplies on which electronic commerce operator pays tax u/s 9(5) <br/>(to be furnished by electronic commerce operator)")}}</td>
<td class="right">0.00</td>
<td class="right">0.00</td>
<td class="right">0.00</td>
<td class="right">0.00</td>
<td class="right">0.00</td>
</tr>
<tr>
<td>{{__("(ii) Taxable supplies made by registered person through electronic commerce operator, <br/>on which electronic commerce operator is required to pay tax u/s 9(5)<br/> (to be furnished by registered person making supplies through electronic commerce operator)")}}</td>
<td class="right">{{flt(data.eco_dtls.eco_reg_sup.txval, 2) }}</td>
<td class="disabled"></td>
<td class="disabled"></td>
<td class="disabled"></td>
<td class="disabled"></td>

</tr>
</tbody>
</table>

<h5>
3.2&nbsp&nbsp{{__("Of the supplies shown in 3.1 (a) above, details of inter-State supplies made to unregisterd
persons, composition taxable persons and UIN holders")}}
Expand Down
76 changes: 58 additions & 18 deletions india_compliance/gst_india/doctype/gstr_3b_report/gstr_3b_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def get_data(self):
)
self.set_inward_nil_exempt(inward_nil_exempt)

self.set_reverse_charge_supply_through_ecomm_operators()

self.missing_field_invoices = self.get_missing_field_invoices()
self.report_dict = format_values(self.report_dict)
self.json_output = frappe.as_json(self.report_dict)
Expand Down Expand Up @@ -182,19 +184,15 @@ def update_itc_reversal_from_journal_entry(self):
journal_entry.ineligibility_reason,
Sum(journal_entry_account.credit_in_account_currency).as_("amount"),
)
.where(journal_entry.docstatus == 1)
.where(journal_entry.is_opening == "No")
.where(journal_entry.voucher_type == "Reversal Of ITC")
.where(Extract(DatePart.month, journal_entry.posting_date) == self.month_no)
.where(Extract(DatePart.year, journal_entry.posting_date) == self.year)
.where(IfNull(journal_entry_account.gst_tax_type, "") != "")
.where(journal_entry.company == self.company)
.where(journal_entry.company_gstin == self.gst_details.get("gstin"))
.groupby(
journal_entry_account.gst_tax_type, journal_entry.ineligibility_reason
)
.run(as_dict=True)
)
reversal_entries = self.get_query_with_conditions(
journal_entry, reversal_entries, party_gstin=""
).run(as_dict=True)

net_itc = self.report_dict["itc_elg"]["itc_net"]
gst_tax_type_to_key_map = {
Expand Down Expand Up @@ -326,6 +324,28 @@ def get_inward_nil_exempt(self, state):

return inward_nil_exempt_details

def set_reverse_charge_supply_through_ecomm_operators(self):
si = frappe.qb.DocType("Sales Invoice")
si_item = frappe.qb.DocType("Sales Invoice Item")
query = (
frappe.qb.from_(si)
.join(si_item)
.on(si.name == si_item.parent)
.select(
IfNull(Sum(si_item.taxable_value), 0).as_("taxable_value"),
)
)
query = self.get_query_with_conditions(si, query, si.billing_address_gstin)
result = (
query.where(si.is_reverse_charge == 1)
.where(IfNull(si.ecommerce_gstin, "") != "")
.run(as_dict=True)
)
total_taxable_value = flt(result[0]["taxable_value"], 2)

self.report_dict["eco_dtls"]["eco_reg_sup"]["txval"] = total_taxable_value
self.report_dict["sup_details"]["osup_det"]["txval"] -= total_taxable_value

def get_outward_supply_details(self, doctype, reverse_charge=None):
self.get_outward_tax_invoices(doctype, reverse_charge=reverse_charge)
self.get_invoice_item_wise_tax_details(doctype)
Expand Down Expand Up @@ -425,17 +445,33 @@ def get_outward_tax_invoices(self, doctype, reverse_charge=None):
self.invoice_map = {}

invoice = frappe.qb.DocType(doctype)
fields = [invoice.name, invoice.gst_category, invoice.place_of_supply]
fields = [
invoice.name,
invoice.gst_category,
invoice.place_of_supply,
invoice.is_reverse_charge,
]
party_gstin = invoice.supplier_gstin

if doctype == "Sales Invoice":
fields.append(invoice.is_export_with_gst)
party_gstin = invoice.billing_address_gstin

query = (
frappe.qb.from_(invoice)
.select(*fields)
.where(invoice.docstatus == 1)
query = frappe.qb.from_(invoice).select(*fields)
query = self.get_query_with_conditions(invoice, query, party_gstin)

if reverse_charge:
query = query.where(invoice.is_reverse_charge == 1)

invoice_details = query.orderby(invoice.name).run(as_dict=True)
self.invoice_map = {d.name: d for d in invoice_details}
self.reverse_charge_invoices = {
d.name for d in invoice_details if d.is_reverse_charge
}

def get_query_with_conditions(self, invoice, query, party_gstin):
return (
query.where(invoice.docstatus == 1)
.where(Extract(DatePart.month, invoice.posting_date).eq(self.month_no))
.where(Extract(DatePart.year, invoice.posting_date).eq(self.year))
.where(invoice.company == self.company)
Expand All @@ -444,12 +480,6 @@ def get_outward_tax_invoices(self, doctype, reverse_charge=None):
.where(invoice.company_gstin != IfNull(party_gstin, ""))
)

if reverse_charge:
query = query.where(invoice.is_reverse_charge == 1)

invoice_details = query.orderby(invoice.name).run(as_dict=True)
self.invoice_map = {d.name: d for d in invoice_details}

def get_outward_items(self, doctype):
if not self.invoice_map:
return {}
Expand All @@ -472,6 +502,8 @@ def get_outward_tax_details(self, doctype):
if not self.invoice_map:
return {}

condition = self.get_reverse_charge_invoice_condition(doctype)

tax_template = f"{doctype.split()[0]} Taxes and Charges"
tax_details = frappe.db.sql(
f"""
Expand All @@ -481,6 +513,7 @@ def get_outward_tax_details(self, doctype):
WHERE
parenttype = %s and docstatus = 1
and parent in ({", ".join(["%s"] * len(self.invoice_map))})
{condition}
ORDER BY account_head
""",
(doctype, *self.invoice_map.keys()),
Expand All @@ -489,6 +522,13 @@ def get_outward_tax_details(self, doctype):

return tax_details

def get_reverse_charge_invoice_condition(self, doctype):
condition = ""
if doctype == "Sales Invoice" and self.reverse_charge_invoices:
condition = f""" and parent not in ({', '.join([f'"{invoice}"' for invoice in self.reverse_charge_invoices])})"""

return condition

def set_outward_taxable_supplies(self):
inter_state_supply_details = {}
gst_treatment_map = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,17 @@
"csamt": 0
}
]
},
"eco_dtls":{
"eco_sup":{
"txval":0,
"iamt":0,
"camt":0,
"samt":0,
"csamt":0
},
"eco_reg_sup":{
"txval":0
}
}
}
Loading

0 comments on commit 79ee2df

Please sign in to comment.