Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions edocument/edocument/doctype/edocument/edocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
() => {
Expand All @@ -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"),
Expand Down
3 changes: 2 additions & 1 deletion edocument/edocument/doctype/edocument/edocument.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 17 additions & 1 deletion edocument/edocument/doctype/edocument/edocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -301,7 +307,17 @@ 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()
Expand Down