Skip to content

Commit

Permalink
fix: update gstin status from GSTR (#1064)
Browse files Browse the repository at this point in the history
(cherry picked from commit bd104d1)
  • Loading branch information
ljain112 authored and mergify[bot] committed Oct 2, 2023
1 parent a494623 commit 8b3e810
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
5 changes: 5 additions & 0 deletions india_compliance/gst_india/utils/gstr/gstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def get_all_transactions(self, category, suppliers):
for supplier in suppliers:
transactions.extend(self.get_supplier_transactions(category, supplier))

self.update_gstins()

return transactions

def get_supplier_transactions(self, category, supplier):
Expand Down Expand Up @@ -117,3 +119,6 @@ def get_key(self, key):

def set_key(self, key, value):
self.KEY_MAPS[key] = value

def update_gstins(self):
pass
51 changes: 49 additions & 2 deletions india_compliance/gst_india/utils/gstr/gstr_2a.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import frappe

from india_compliance.gst_india.utils import parse_datetime
from india_compliance.gst_india.utils import get_datetime, parse_datetime
from india_compliance.gst_india.utils.gstr.gstr import GSTR, get_mapped_value


Expand All @@ -13,8 +13,12 @@ def map_date_format(date_str, source_format, target_format):


class GSTR2a(GSTR):
def setup(self):
self.all_gstins = set()
self.cancelled_gstins = {}

def get_supplier_details(self, supplier):
return {
supplier_details = {
"supplier_gstin": supplier.ctin,
"gstr_1_filled": get_mapped_value(
supplier.cfs, self.VALUE_MAPS.Y_N_to_check
Expand All @@ -27,6 +31,19 @@ def get_supplier_details(self, supplier):
"sup_return_period": map_date_format(supplier.flprdr1, "%b-%y", "%m%Y"),
}

self.update_gstins_list(supplier_details)

return supplier_details

def update_gstins_list(self, supplier_details):
self.all_gstins.add(supplier_details.get("supplier_gstin"))

if supplier_details.get("registration_cancel_date"):
self.cancelled_gstins.setdefault(
supplier_details.get("supplier_gstin"),
supplier_details.get("registration_cancel_date"),
)

# item details are in item_det for GSTR2a
def get_transaction_items(self, invoice):
return [
Expand All @@ -47,6 +64,36 @@ def get_transaction_item(self, item, item_number=None):
"cess": item.csamt,
}

def update_gstins(self):
if not self.all_gstins:
return

frappe.db.set_value(
"GSTIN",
{"name": ("in", self.all_gstins)},
"last_updated_on",
get_datetime(),
)
if not self.cancelled_gstins:
return

cancelled_gstins_to_update = frappe.db.get_all(
"GSTIN",
filters={
"name": ("in", self.cancelled_gstins),
"status": ("!=", "Cancelled"),
},
pluck="name",
)

for gstin in cancelled_gstins_to_update:
cancelled_date = self.cancelled_gstins.get(gstin)
frappe.db.set_value(
"GSTIN",
gstin,
{"cancelled_date": cancelled_date, "status": "Cancelled"},
)


class GSTR2aB2B(GSTR2a):
def setup(self):
Expand Down

0 comments on commit 8b3e810

Please sign in to comment.