Skip to content

Commit 4026a6f

Browse files
authored
Merge pull request #36 from maasanto/fix-protect-transmitted-edocuments
fix: prevent modifications to transmitted edocuments
2 parents 7935456 + 618039c commit 4026a6f

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

edocument/edocument/doctype/edocument/edocument.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ frappe.ui.form.on("EDocument", {
88
});
99

1010
function setup_action_buttons(frm) {
11-
// Generate XML - for outgoing documents
12-
if (frm.doc.edocument_source_document && frm.doc.edocument_profile) {
11+
const is_transmitted = frm.doc.status === "Transmission Successful";
12+
13+
// Generate XML - for outgoing documents (not already transmitted)
14+
if (frm.doc.edocument_source_document && frm.doc.edocument_profile && !is_transmitted) {
1315
frm.add_custom_button(
1416
__("Generate XML"),
1517
() => {
@@ -35,7 +37,11 @@ function setup_action_buttons(frm) {
3537
if (!r.message && !frm.doc.xml_file) return;
3638

3739
frm.add_custom_button(__("Preview EDocument"), () => show_preview(frm), __("Actions"));
38-
frm.add_custom_button(__("Validate XML"), () => validate_xml(frm), __("Actions"));
40+
41+
if (!is_transmitted) {
42+
frm.add_custom_button(__("Validate XML"), () => validate_xml(frm), __("Actions"));
43+
}
44+
3945
frm.add_custom_button(__("Match Document"), () => match_document(frm), __("Actions"));
4046
frm.add_custom_button(
4147
__("Create Document"),

edocument/edocument/doctype/edocument/edocument.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
"in_list_view": 1,
6666
"in_standard_filter": 1,
6767
"label": "Status",
68-
"options": "\nValidation Successful\nValidation Failed\nMatching Successful\nMatching Failed\nTransmission Successful\nTransmission Failed"
68+
"options": "\nValidation Successful\nValidation Failed\nMatching Successful\nMatching Failed\nTransmission Successful\nTransmission Failed",
69+
"read_only": 1
6970
},
7071
{
7172
"fieldname": "country",

edocument/edocument/doctype/edocument/edocument.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ def generate_xml(self):
120120
Note: This method only generates XML - validation is handled separately.
121121
This is the public method called from the button.
122122
"""
123+
if self.status == "Transmission Successful":
124+
frappe.throw(_("Cannot regenerate XML for an already transmitted document."))
125+
123126
try:
124127
file_name = self._generate_xml_internal()
125128
# Save the document to persist status and error field changes
@@ -219,6 +222,9 @@ def validate_xml(self):
219222
Updates the status and error fields based on validation results.
220223
This is the public method called from the button.
221224
"""
225+
if self.status == "Transmission Successful":
226+
frappe.throw(_("Cannot re-validate an already transmitted document."))
227+
222228
try:
223229
self._validate_xml_internal()
224230
# Save the document to persist status and error field changes
@@ -301,7 +307,17 @@ def before_save(self):
301307
f"Error during automatic XML generation for EDocument {self.name}: {error_msg}"
302308
)
303309

304-
if self.edocument_profile:
310+
# Don't overwrite status for documents that reached a terminal state
311+
# (already transmitted or matched) — re-validation would reset status
312+
# back to "Validation Successful" and re-enable the Send button.
313+
terminal_statuses = (
314+
"Transmission Successful",
315+
"Transmission Failed",
316+
"Matching Successful",
317+
"Matching Failed",
318+
)
319+
320+
if self.edocument_profile and self.status not in terminal_statuses:
305321
# Validate XML automatically
306322
try:
307323
self._validate_xml_internal()

0 commit comments

Comments
 (0)