Skip to content

Commit

Permalink
fix: remove extra inward supplies and unlink invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket322 committed Apr 22, 2024
1 parent 2a34abf commit bab5efc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def before_save(self):
):
update_docs_for_amendment(self)

def on_trash(self):
frappe.db.set_value(
"Purchase Invoice", self.link_name, "reconciliation_status", "Unreconciled"
)


def create_inward_supply(transaction):
filters = {
Expand Down
16 changes: 16 additions & 0 deletions india_compliance/gst_india/utils/gstr_2/gstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self, company, gstin, return_period, data, gen_date_2b):
self.setup()

def setup(self):
self.existing_transaction = {}
pass

def create_transactions(self, category, suppliers):
Expand All @@ -71,6 +72,20 @@ def create_transactions(self, category, suppliers):
doctype="Purchase Reconciliation Tool",
)

if transaction.get("unique_key") in self.existing_transaction:
self.existing_transaction.pop(transaction.get("unique_key"))

self.delete_missing_transactions()

def delete_missing_transactions(self):
"""
For GSTR2a, transactions are reflected immediately after it's pushed to GSTR-1.
At times, it may later be removed from GSTR-1.
In such cases, we need to delete such unfilled transactions not present in the latest data.
"""
return

def get_all_transactions(self, category, suppliers):
transactions = []
for supplier in suppliers:
Expand All @@ -97,6 +112,7 @@ def get_transaction(self, category, supplier, invoice):
**self.get_supplier_details(supplier),
**self.get_invoice_details(invoice),
items=self.get_transaction_items(invoice),
unique_key=supplier.ctin + "-" + invoice.inum,
)

def get_supplier_details(self, supplier):
Expand Down
25 changes: 25 additions & 0 deletions india_compliance/gst_india/utils/gstr_2/gstr_2a.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,31 @@ class GSTR2a(GSTR):
def setup(self):
self.all_gstins = set()
self.cancelled_gstins = {}
self.existing_transaction = self.get_existing_transaction()

def get_existing_transaction(self):
category = type(self).__name__[6:]

gst_is = frappe.qb.DocType("GST Inward Supply")
existing_transactions = (
frappe.qb.from_(gst_is)
.select(gst_is.name, gst_is.supplier_gstin, gst_is.bill_no)
.where(gst_is.sup_return_period == self.return_period)
.where(gst_is.classification == category)
.where(gst_is.gstr_1_filled == 0)
).run(as_dict=True)

return {
transaction.get("supplier_gstin")
+ "-"
+ transaction.get("bill_no"): transaction.get("name")
for transaction in existing_transactions
}

def delete_missing_transactions(self):
if self.existing_transaction:
for value in self.existing_transaction.values():
frappe.delete_doc("GST Inward Supply", value)

def get_supplier_details(self, supplier):
supplier_details = {
Expand Down

0 comments on commit bab5efc

Please sign in to comment.