Skip to content

Commit

Permalink
Merge pull request #1094 from ljain112/manual-backport
Browse files Browse the repository at this point in the history
  • Loading branch information
vorasmit authored Oct 2, 2023
2 parents fe83df9 + 993e6a0 commit a494623
Show file tree
Hide file tree
Showing 19 changed files with 276 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_columns(self):
def get_data(self):
pass

def append_rows(self):
def append_rows(self, new_count, modified_count, doctype):
pass

def get_conditions(self):
Expand Down
10 changes: 6 additions & 4 deletions india_compliance/gst_india/api_classes/returns.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ class GSTR2bAPI(ReturnsAPI):
API_NAME = "GSTR-2B"
BASE_PATH = "returns/gstr2b"

def get_data(self, return_period, otp=None):
# TODO: Create further calls if more than one file to download
return self.get("GET2B", return_period, otp, {"rtnprd": return_period})
def get_data(self, return_period, otp=None, file_num=None):
params = {"rtnprd": return_period}
if file_num:
params["file_num"] = file_num

return self.get("GET2B", return_period, otp, params)


class GSTR2aAPI(ReturnsAPI):
API_NAME = "GSTR-2A"
BASE_PATH = "returns/gstr2a"

def get_data(self, action, return_period, otp=None):
# TODO: Create further calls if more than one file to download
return self.get(action, return_period, otp, {"ret_period": return_period})
12 changes: 7 additions & 5 deletions india_compliance/gst_india/constants/custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,19 @@
"translatable": 0,
},
{
"fieldname": "ignore_reconciliation",
"label": "Ignore Reconciliation",
"fieldtype": "Check",
"fieldname": "reconciliation_status",
"label": "Reconciliation Status",
"fieldtype": "Select",
"insert_after": "eligibility_for_itc",
"print_hide": 1,
"translatable": 0,
"options": ("\nNot Applicable\nReconciled\nUnreconciled\nIgnored"),
"no_copy": 1,
"read_only": 1,
},
{
"fieldname": "gst_col_break",
"fieldtype": "Column Break",
"insert_after": "ignore_reconciliation",
"insert_after": "reconciliation_status",
},
{
"fieldname": "itc_integrated_tax",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"engine": "InnoDB",
"field_order": [
"naming_series",
"column_break_2wjs",
"amended_from",
"column_break_hbfk",
"amended_from",
"column_break_2wjs",
"section_break_fqdh",
"purchase_invoice",
"column_break_epap",
Expand All @@ -31,7 +31,7 @@
"column_break_xjvk",
"customs_expense_account",
"column_break_zsed",
"ignore_reconciliation",
"reconciliation_status",
"accounting_dimensions_section",
"cost_center",
"dimension_col_break",
Expand Down Expand Up @@ -272,19 +272,20 @@
"label": "Bill of Lading No."
},
{
"default": "0",
"fieldname": "ignore_reconciliation",
"fieldtype": "Check",
"label": "Ignore Reconciliation",
"fieldname": "reconciliation_status",
"fieldtype": "Select",
"label": "Reconciliation Status",
"no_copy": 1,
"print_hide": 1
"options": "\nNot Applicable\nReconciled\nUnreconciled\nIgnored",
"print_hide": 1,
"read_only": 1
}
],
"in_create": 1,
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2023-09-06 21:43:12.372700",
"modified": "2023-09-14 16:43:49.370165",
"modified_by": "Administrator",
"module": "GST India",
"name": "Bill of Entry",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def before_validate(self):
def validate(self):
self.validate_purchase_invoice()
self.validate_taxes()
self.reconciliation_status = "Unreconciled"

def on_submit(self):
make_gl_entries(self.get_gl_entries())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@
"fieldname": "password",
"fieldtype": "Password",
"in_list_view": 1,
"label": "Password"
"label": "Password",
"mandatory_depends_on": "eval: doc.service == 'e-Waybill / e-Invoice'"
}
],
"istable": 1,
"links": [],
"modified": "2022-07-24 02:04:03.084096",
"modified": "2023-09-15 11:41:45.553470",
"modified_by": "Administrator",
"module": "GST India",
"name": "GST Credential",
Expand Down
11 changes: 0 additions & 11 deletions india_compliance/gst_india/doctype/gst_settings/gst_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

frappe.ui.form.on("GST Settings", {
setup(frm) {
frm.get_field("credentials").grid.get_docfield("password").reqd = 1;

["cgst_account", "sgst_account", "igst_account", "cess_account"].forEach(
field => filter_accounts(frm, field)
);
Expand Down Expand Up @@ -38,15 +36,6 @@ frappe.ui.form.on("GST Settings", {
},
});

frappe.ui.form.on("GST Credential", {
service(frm, cdt, cdn) {
const doc = frappe.get_doc(cdt, cdn);
const row = frm.get_field("credentials").grid.grid_rows_by_docname[doc.name];

row.toggle_reqd("password", doc.service !== "Returns");
},
});

function filter_accounts(frm, account_field) {
frm.set_query(account_field, "gst_accounts", (_, cdt, cdn) => {
const row = frappe.get_doc(cdt, cdn);
Expand Down
5 changes: 3 additions & 2 deletions india_compliance/gst_india/doctype/gstin/gstin.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ def _throw(message):

if gstin_doc.status not in ("Active", "Cancelled"):
return _throw(
_("Status of Party GSTIN {1} is {0}").format(gstin_doc.status),
gstin_doc.gstin,
_("Status of Party GSTIN {1} is {0}").format(
gstin_doc.status, gstin_doc.gstin
)
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def create_import_log(
gstin,
return_type,
return_period,
data_not_found=False,
classification=None,
data_not_found=False,
request_id=None,
retry_after_mins=None,
):
Expand All @@ -37,8 +37,8 @@ def _create_import_log(
gstin,
return_type,
return_period,
data_not_found=False,
classification=None,
data_not_found=False,
request_id=None,
retry_after_mins=None,
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ def get_unmatched(self, category, amended_category):
query = self.with_period_filter()
data = (
query.where(IfNull(self.GSTR2.match_status, "") == "")
.where(self.GSTR2.action != "Ignore")
.where(self.GSTR2.classification.isin(categories))
.run(as_dict=True)
)
Expand Down Expand Up @@ -302,6 +301,9 @@ def get_query(self, additional_fields=None):
.groupby(self.GSTR2_ITEM.parent)
.select(*fields, ConstantColumn("GST Inward Supply").as_("doctype"))
)
if self.include_ignored == 0:
query = query.where(IfNull(self.GSTR2.action, "") != "Ignore")

return query

def get_fields(self, additional_fields=None, table=None):
Expand Down Expand Up @@ -379,7 +381,6 @@ def get_unmatched(self, category):
)
)
)
.where(self.PI.ignore_reconciliation == 0)
.where(self.PI.gst_category.isin(gst_category))
.where(self.PI.is_return == is_return)
)
Expand All @@ -404,18 +405,15 @@ def get_query(self, additional_fields=None, is_return=False):
.groupby(PI_ITEM.parent)
)

return (
query = (
frappe.qb.from_(self.PI)
.left_join(self.PI_TAX)
.on(self.PI_TAX.parent == self.PI.name)
.left_join(pi_item)
.on(pi_item.parent == self.PI.name)
.where(self.company_gstin == self.PI.company_gstin)
.where(self.PI.docstatus == 1)
# Filter for B2B transactions where match can be made
.where(self.PI.supplier_gstin != "")
.where(self.PI.gst_category != "Registered Composition")
.where(self.PI.supplier_gstin.isnotnull())
.where(IfNull(self.PI.reconciliation_status, "") != "Not Applicable")
.groupby(self.PI.name)
.select(
*fields,
Expand All @@ -424,6 +422,11 @@ def get_query(self, additional_fields=None, is_return=False):
)
)

if self.include_ignored == 0:
query = query.where(IfNull(self.PI.reconciliation_status, "") != "Ignored")

return query

def get_fields(self, additional_fields=None, is_return=False):
gst_accounts = get_gst_accounts_by_type(self.company, "Input")
tax_fields = [
Expand Down Expand Up @@ -524,7 +527,6 @@ def get_unmatched(self, category):
)
)
)
.where(self.BOE.ignore_reconciliation == 0)
)

data = query.run(as_dict=True)
Expand All @@ -537,18 +539,22 @@ def get_unmatched(self, category):
def get_query(self, additional_fields=None):
fields = self.get_fields(additional_fields)

return (
query = (
frappe.qb.from_(self.BOE)
.left_join(self.BOE_TAX)
.on(self.BOE_TAX.parent == self.BOE.name)
.join(self.PI)
.on(self.BOE.purchase_invoice == self.PI.name)
.where(self.company_gstin == self.BOE.company_gstin)
.where(self.BOE.docstatus == 1)
.groupby(self.BOE.name)
.select(*fields, ConstantColumn("Bill of Entry").as_("doctype"))
)

if self.include_ignored == 0:
query = query.where(IfNull(self.BOE.reconciliation_status, "") != "Ignored")

return query

def get_fields(self, additional_fields=None):
gst_accounts = get_gst_accounts_by_type(self.company, "Input")
tax_fields = [
Expand Down Expand Up @@ -635,6 +641,7 @@ def get_all_inward_supply(
from_date=self.inward_supply_from_date,
to_date=self.inward_supply_to_date,
gst_return=self.gst_return,
include_ignored=self.include_ignored,
).get_all(additional_fields, names, only_names)

def get_unmatched_inward_supply(self, category, amended_category):
Expand All @@ -643,6 +650,7 @@ def get_unmatched_inward_supply(self, category, amended_category):
from_date=self.inward_supply_from_date,
to_date=self.inward_supply_to_date,
gst_return=self.gst_return,
include_ignored=self.include_ignored,
).get_unmatched(category, amended_category)

def query_inward_supply(self, additional_fields=None):
Expand All @@ -651,6 +659,7 @@ def query_inward_supply(self, additional_fields=None):
from_date=self.inward_supply_from_date,
to_date=self.inward_supply_to_date,
gst_return=self.gst_return,
include_ignored=self.include_ignored,
)

return query.with_period_filter(additional_fields)
Expand All @@ -663,6 +672,7 @@ def get_all_purchase_invoice(
company_gstin=self.company_gstin,
from_date=self.purchase_from_date,
to_date=self.purchase_to_date,
include_ignored=self.include_ignored,
).get_all(additional_fields, names, only_names)

def get_unmatched_purchase(self, category):
Expand All @@ -671,11 +681,14 @@ def get_unmatched_purchase(self, category):
company_gstin=self.company_gstin,
from_date=self.purchase_from_date,
to_date=self.purchase_to_date,
include_ignored=self.include_ignored,
).get_unmatched(category)

def query_purchase_invoice(self, additional_fields=None):
return PurchaseInvoice(
company=self.company, company_gstin=self.company_gstin
company=self.company,
company_gstin=self.company_gstin,
include_ignored=self.include_ignored,
).get_query(additional_fields)

def get_all_bill_of_entry(
Expand All @@ -686,6 +699,7 @@ def get_all_bill_of_entry(
company_gstin=self.company_gstin,
from_date=self.purchase_from_date,
to_date=self.purchase_to_date,
include_ignored=self.include_ignored,
).get_all(additional_fields, names, only_names)

def get_unmatched_bill_of_entry(self, category):
Expand All @@ -694,11 +708,14 @@ def get_unmatched_bill_of_entry(self, category):
company_gstin=self.company_gstin,
from_date=self.purchase_from_date,
to_date=self.purchase_to_date,
include_ignored=self.include_ignored,
).get_unmatched(category)

def query_bill_of_entry(self, additional_fields=None):
return BillOfEntry(
company=self.company, company_gstin=self.company_gstin
company=self.company,
company_gstin=self.company_gstin,
include_ignored=self.include_ignored,
).get_query(additional_fields)

def get_unmatched_purchase_or_bill_of_entry(self, category):
Expand Down Expand Up @@ -1022,7 +1039,7 @@ def get_all_purchase_invoice_and_bill_of_entry(
"supplier_name",
"is_return",
"gst_category",
"ignore_reconciliation",
"reconciliation_status",
]

boe_names = purchase_names
Expand Down Expand Up @@ -1132,7 +1149,9 @@ def update_fields(self, data, purchase, inward_supply):
elif not inward_supply:
data.match_status = MatchStatus.MISSING_IN_2A_2B.value
data.action = (
"Ignore" if purchase.get("ignore_reconciliation") else "No Action"
"Ignore"
if purchase.get("reconciliation_status") == "Ignored"
else "No Action"
)

def update_amount_difference(self, data, purchase, inward_supply):
Expand Down
Loading

0 comments on commit a494623

Please sign in to comment.