From 11231b5c6642d4c21de4bee1a532760b52ab6f1e Mon Sep 17 00:00:00 2001 From: Antoine Maas Date: Wed, 11 Feb 2026 11:05:23 +0100 Subject: [PATCH 1/3] fix: prevent modifications to transmitted edocuments --- edocument/edocument/doctype/edocument/edocument.js | 12 +++++++++--- edocument/edocument/doctype/edocument/edocument.py | 14 +++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/edocument/edocument/doctype/edocument/edocument.js b/edocument/edocument/doctype/edocument/edocument.js index 331f112..9eba436 100644 --- a/edocument/edocument/doctype/edocument/edocument.js +++ b/edocument/edocument/doctype/edocument/edocument.js @@ -8,8 +8,10 @@ frappe.ui.form.on("EDocument", { }); function setup_action_buttons(frm) { - // Generate XML - for outgoing documents - if (frm.doc.edocument_source_document && frm.doc.edocument_profile) { + const is_transmitted = frm.doc.status === "Transmission Successful"; + + // Generate XML - for outgoing documents (not already transmitted) + if (frm.doc.edocument_source_document && frm.doc.edocument_profile && !is_transmitted) { frm.add_custom_button( __("Generate XML"), () => { @@ -35,7 +37,11 @@ function setup_action_buttons(frm) { if (!r.message && !frm.doc.xml_file) return; frm.add_custom_button(__("Preview EDocument"), () => show_preview(frm), __("Actions")); - frm.add_custom_button(__("Validate XML"), () => validate_xml(frm), __("Actions")); + + if (!is_transmitted) { + frm.add_custom_button(__("Validate XML"), () => validate_xml(frm), __("Actions")); + } + frm.add_custom_button(__("Match Document"), () => match_document(frm), __("Actions")); frm.add_custom_button( __("Create Document"), diff --git a/edocument/edocument/doctype/edocument/edocument.py b/edocument/edocument/doctype/edocument/edocument.py index c76fd6b..6925263 100644 --- a/edocument/edocument/doctype/edocument/edocument.py +++ b/edocument/edocument/doctype/edocument/edocument.py @@ -120,6 +120,9 @@ def generate_xml(self): Note: This method only generates XML - validation is handled separately. This is the public method called from the button. """ + if self.status == "Transmission Successful": + frappe.throw(_("Cannot regenerate XML for an already transmitted document.")) + try: file_name = self._generate_xml_internal() # Save the document to persist status and error field changes @@ -219,6 +222,9 @@ def validate_xml(self): Updates the status and error fields based on validation results. This is the public method called from the button. """ + if self.status == "Transmission Successful": + frappe.throw(_("Cannot re-validate an already transmitted document.")) + try: self._validate_xml_internal() # Save the document to persist status and error field changes @@ -301,7 +307,13 @@ def before_save(self): f"Error during automatic XML generation for EDocument {self.name}: {error_msg}" ) - if self.edocument_profile: + # Don't overwrite status for documents that reached a terminal state + # (already transmitted or matched) — re-validation would reset status + # back to "Validation Successful" and re-enable the Send button. + terminal_statuses = ("Transmission Successful", "Transmission Failed", + "Matching Successful", "Matching Failed") + + if self.edocument_profile and self.status not in terminal_statuses: # Validate XML automatically try: self._validate_xml_internal() From 025391dcaedd7b0715fc90f0f39b4ae2ba32cc26 Mon Sep 17 00:00:00 2001 From: Antoine Maas Date: Thu, 12 Feb 2026 13:45:12 +0100 Subject: [PATCH 2/3] fix: format terminal_statuses tuple for ruff compliance --- edocument/edocument/doctype/edocument/edocument.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/edocument/edocument/doctype/edocument/edocument.py b/edocument/edocument/doctype/edocument/edocument.py index 6925263..2b30a65 100644 --- a/edocument/edocument/doctype/edocument/edocument.py +++ b/edocument/edocument/doctype/edocument/edocument.py @@ -310,8 +310,12 @@ def before_save(self): # Don't overwrite status for documents that reached a terminal state # (already transmitted or matched) — re-validation would reset status # back to "Validation Successful" and re-enable the Send button. - terminal_statuses = ("Transmission Successful", "Transmission Failed", - "Matching Successful", "Matching Failed") + terminal_statuses = ( + "Transmission Successful", + "Transmission Failed", + "Matching Successful", + "Matching Failed", + ) if self.edocument_profile and self.status not in terminal_statuses: # Validate XML automatically From 618039c3774188dde41b9c352fd31cc5f95b7268 Mon Sep 17 00:00:00 2001 From: Antoine Maas Date: Thu, 12 Feb 2026 13:49:26 +0100 Subject: [PATCH 3/3] fix: make status field read-only --- edocument/edocument/doctype/edocument/edocument.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/edocument/edocument/doctype/edocument/edocument.json b/edocument/edocument/doctype/edocument/edocument.json index c1e59e4..1860faa 100644 --- a/edocument/edocument/doctype/edocument/edocument.json +++ b/edocument/edocument/doctype/edocument/edocument.json @@ -65,7 +65,8 @@ "in_list_view": 1, "in_standard_filter": 1, "label": "Status", - "options": "\nValidation Successful\nValidation Failed\nMatching Successful\nMatching Failed\nTransmission Successful\nTransmission Failed" + "options": "\nValidation Successful\nValidation Failed\nMatching Successful\nMatching Failed\nTransmission Successful\nTransmission Failed", + "read_only": 1 }, { "fieldname": "country",