@@ -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