Skip to content

Commit

Permalink
Merge pull request #29869 from deepeshgarg007/gstr_1_gstin_filter
Browse files Browse the repository at this point in the history
fix: GSTIN filter for GSTR-1 report
  • Loading branch information
deepeshgarg007 authored Feb 19, 2022
2 parents b9072eb + d188fcc commit 83a60a2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
22 changes: 19 additions & 3 deletions erpnext/regional/report/gstr_1/gstr_1.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ frappe.query_reports["GSTR-1"] = {
"fieldtype": "Link",
"options": "Address",
"get_query": function () {
var company = frappe.query_report.get_filter_value('company');
let company = frappe.query_report.get_filter_value('company');
if (company) {
return {
"query": 'frappe.contacts.doctype.address.address.address_query',
Expand All @@ -26,6 +26,11 @@ frappe.query_reports["GSTR-1"] = {
}
}
},
{
"fieldname": "company_gstin",
"label": __("Company GSTIN"),
"fieldtype": "Select"
},
{
"fieldname": "from_date",
"label": __("From Date"),
Expand Down Expand Up @@ -60,10 +65,21 @@ frappe.query_reports["GSTR-1"] = {
}
],
onload: function (report) {
let filters = report.get_values();

frappe.call({
method: 'erpnext.regional.report.gstr_1.gstr_1.get_company_gstins',
args: {
company: filters.company
},
callback: function(r) {
frappe.query_report.page.fields_dict.company_gstin.df.options = r.message;
frappe.query_report.page.fields_dict.company_gstin.refresh();
}
});

report.page.add_inner_button(__("Download as JSON"), function () {
var filters = report.get_values();

report.page.add_inner_button(__("Download as JSON"), function () {
frappe.call({
method: 'erpnext.regional.report.gstr_1.gstr_1.get_json',
args: {
Expand Down
23 changes: 22 additions & 1 deletion erpnext/regional/report/gstr_1/gstr_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ def get_conditions(self):
for opts in (("company", " and company=%(company)s"),
("from_date", " and posting_date>=%(from_date)s"),
("to_date", " and posting_date<=%(to_date)s"),
("company_address", " and company_address=%(company_address)s")):
("company_address", " and company_address=%(company_address)s"),
("company_gstin", " and company_gstin=%(company_gstin)s")):
if self.filters.get(opts[0]):
conditions += opts[1]

Expand Down Expand Up @@ -1192,3 +1193,23 @@ def is_inter_state(invoice_detail):
return True
else:
return False


@frappe.whitelist()
def get_company_gstins(company):
address = frappe.qb.DocType("Address")
links = frappe.qb.DocType("Dynamic Link")

addresses = frappe.qb.from_(address).inner_join(links).on(
address.name == links.parent
).select(
address.gstin
).where(
links.link_doctype == 'Company'
).where(
links.link_name == company
).run(as_dict=1)

address_list = [''] + [d.gstin for d in addresses]

return address_list

0 comments on commit 83a60a2

Please sign in to comment.