From e1b0107c515536e8ccd8158b8ab7cf00dd56f2a9 Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Fri, 29 Nov 2024 15:17:08 +0530 Subject: [PATCH] fix: field to check if redownload is useful --- .../gstr_import_log/gstr_import_log.json | 9 ++++++- .../purchase_reconciliation_tool.py | 26 ++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/india_compliance/gst_india/doctype/gstr_import_log/gstr_import_log.json b/india_compliance/gst_india/doctype/gstr_import_log/gstr_import_log.json index da40c8e6cb..208abef43d 100644 --- a/india_compliance/gst_india/doctype/gstr_import_log/gstr_import_log.json +++ b/india_compliance/gst_india/doctype/gstr_import_log/gstr_import_log.json @@ -12,6 +12,7 @@ "return_period", "last_updated_on", "data_not_found", + "dont_redownload", "request_id", "request_time" ], @@ -64,11 +65,17 @@ "fieldtype": "Datetime", "hidden": 1, "label": "Request Time" + }, + { + "default": "0", + "fieldname": "dont_redownload", + "fieldtype": "Check", + "label": "Redownload not Required" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2024-03-29 11:54:43.449587", + "modified": "2024-11-29 15:06:33.113355", "modified_by": "Administrator", "module": "GST India", "name": "GSTR Import Log", diff --git a/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.py b/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.py index 3c9cf1ad9a..c709b58725 100644 --- a/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.py +++ b/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.py @@ -454,8 +454,9 @@ def download_gstr( return_type = ReturnType(return_type) periods = BaseUtil.get_periods(date_range, return_type) - if not force: - periods = get_periods_to_download(company_gstin, return_type, periods) + periods = get_periods_to_download( + company_gstin, return_type, periods, download_all=not force + ) if not periods: return @@ -467,12 +468,23 @@ def download_gstr( return download_gstr_2b(company_gstin, periods) -def get_periods_to_download(company_gstin, return_type, periods): +def get_periods_to_download(company_gstin, return_type, periods, download_all=False): + # check if redownload is useful + dont_redownload = get_import_history( + company_gstin, return_type, periods, fields=("return_period", "dont_redownload") + ) + dont_redownload = [ + log.return_period for log in dont_redownload if log.dont_redownload + ] + + periods = [period for period in periods if period not in dont_redownload] + + if download_all: + return periods + + # get missing periods existing_periods = get_import_history( - company_gstin, - return_type, - periods, - pluck="return_period", + company_gstin, return_type, periods, pluck="return_period" ) return [period for period in periods if period not in existing_periods]