From f9553ceaba09fc61096d394f27532e0156adfdfd Mon Sep 17 00:00:00 2001 From: Preetam Biswal Date: Fri, 3 Apr 2026 02:49:35 +0200 Subject: [PATCH 1/2] fix: add hourly auto-poll and trigger company detection after XML attach - Add hourly scheduler to poll all integration settings automatically - Save EDocument after XML attachment in webhook to trigger field detection --- edocument_integration/api.py | 4 ++++ edocument_integration/hooks.py | 22 +++++----------------- edocument_integration/tasks.py | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 edocument_integration/tasks.py diff --git a/edocument_integration/api.py b/edocument_integration/api.py index f442f0a..aa7d348 100644 --- a/edocument_integration/api.py +++ b/edocument_integration/api.py @@ -335,6 +335,10 @@ def webhook(**kwargs): } ) file_doc.save(ignore_permissions=True) + + # Save EDocument again to trigger field detection (company, etc.) from attached XML + edocument.reload() + edocument.save(ignore_permissions=True) frappe.db.commit() # nosemgrep: Webhook must persist before returning result = {"edocument": edocument.name, "document_id": document_id} diff --git a/edocument_integration/hooks.py b/edocument_integration/hooks.py index 08ea080..c7f9ce0 100644 --- a/edocument_integration/hooks.py +++ b/edocument_integration/hooks.py @@ -145,23 +145,11 @@ # Scheduled Tasks # --------------- -# scheduler_events = { -# "all": [ -# "edocument_integration.tasks.all" -# ], -# "daily": [ -# "edocument_integration.tasks.daily" -# ], -# "hourly": [ -# "edocument_integration.tasks.hourly" -# ], -# "weekly": [ -# "edocument_integration.tasks.weekly" -# ], -# "monthly": [ -# "edocument_integration.tasks.monthly" -# ], -# } +scheduler_events = { + "hourly": [ + "edocument_integration.tasks.poll_all_incoming_documents", + ], +} # Testing # ------- diff --git a/edocument_integration/tasks.py b/edocument_integration/tasks.py new file mode 100644 index 0000000..c5368e4 --- /dev/null +++ b/edocument_integration/tasks.py @@ -0,0 +1,21 @@ +import frappe + + +def poll_all_incoming_documents(): + """Poll incoming documents for all EDocument Integration Settings.""" + settings_list = frappe.get_all( + "EDocument Integration Settings", + pluck="name", + ) + + for settings_name in settings_list: + try: + settings = frappe.get_doc("EDocument Integration Settings", settings_name) + settings.poll_incoming_documents() + frappe.db.commit() + except Exception: + frappe.db.rollback() + frappe.log_error( + f"Auto-poll failed for {settings_name}", + "EDocument Auto-Poll Error", + ) From d8eff4f2037de6d307a78d75d3a069d23068b6ea Mon Sep 17 00:00:00 2001 From: Preetam Biswal Date: Fri, 3 Apr 2026 03:03:12 +0200 Subject: [PATCH 2/2] fix: add type hints to poll_incoming_invoices to pass semgrep --- edocument_integration/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edocument_integration/api.py b/edocument_integration/api.py index aa7d348..8720773 100644 --- a/edocument_integration/api.py +++ b/edocument_integration/api.py @@ -360,7 +360,7 @@ def webhook(**kwargs): @frappe.whitelist() -def poll_incoming_invoices(profile=None, company=None): +def poll_incoming_invoices(profile: str | None = None, company: str | None = None): """ Poll Recommand inbox for incoming invoices and create EDocument records.