From d6efade7f1a3daf05ce55f013950049a88bae64a Mon Sep 17 00:00:00 2001 From: Preetam Biswal Date: Fri, 3 Apr 2026 01:32:19 +0200 Subject: [PATCH 1/2] fix: auto-poll incoming documents and trigger field detection - Add hourly scheduler to poll all integration settings automatically - Save EDocument after XML attachment to trigger company detection --- edocument_integration/api.py | 10 ++++++++-- edocument_integration/hooks.py | 22 +++++----------------- edocument_integration/tasks.py | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 edocument_integration/tasks.py diff --git a/edocument_integration/api.py b/edocument_integration/api.py index 305a923..79be84c 100644 --- a/edocument_integration/api.py +++ b/edocument_integration/api.py @@ -238,6 +238,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} @@ -345,8 +349,10 @@ def poll_incoming_invoices(profile=None, company=None): is_private=1, ) - # Set xml_file field on EDocument to the file URL - edocument.db_set("xml_file", file_doc.file_url, update_modified=False) + # Save EDocument to trigger field detection (company, etc.) from attached XML + edocument.reload() + edocument.xml_file = file_doc.file_url + edocument.save(ignore_permissions=True) frappe.db.commit() # Add comment with metadata 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 6e522afa932ace664d19360383b836a01c839a20 Mon Sep 17 00:00:00 2001 From: Preetam Biswal Date: Fri, 3 Apr 2026 02:59:00 +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 79be84c..f307b55 100644 --- a/edocument_integration/api.py +++ b/edocument_integration/api.py @@ -263,7 +263,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.