Skip to content

fix: edocument uses draft invoice name instead of final name after submit#28

Merged
pritambiswal merged 1 commit into
prilk-consulting:developfrom
maasanto:fix-overwrite-xml-on-submit
Jan 10, 2026
Merged

fix: edocument uses draft invoice name instead of final name after submit#28
pritambiswal merged 1 commit into
prilk-consulting:developfrom
maasanto:fix-overwrite-xml-on-submit

Conversation

@maasanto
Copy link
Copy Markdown
Contributor

@maasanto maasanto commented Jan 7, 2026

Problem

When a Sales Invoice was submitted, the generated eDocument XML retained the draft invoice name instead of updating to the final invoice name. This occurred because XML generation happened in the before_submit hook, before the invoice received its final name.
Fixes #21

Root Cause

In Frappe's document lifecycle:

  1. before_submit hook executes while document still has draft name
  2. XML was generated at this point with the draft name
  3. After before_submit completes, document gets its final name
  4. XML was never updated with the final name

Solution

Split the submit workflow between two hooks:

  1. before_submit - Only validates existing edocuments

    • Checks if edocument exists
    • Validates status to potentially block submission
    • Does NOT create or regenerate XML
  2. on_submit (new) - Creates/regenerates edocuments with final invoice name

    • Executes after invoice has final name
    • If edocument exists: deletes old XML files and calls generate_xml()
    • If edocument doesn't exist: creates new one with final name

Behavior

Scenario 1: edocument_generation_on_save enabled

  • Save → eDocument created with draft name
  • Submit → XML regenerated with final name

Scenario 2: edocument_generation_on_save disabled

  • Save → No eDocument created
  • Submit → eDocument created with final name

Both scenarios now produce edocuments with the correct final invoice name.

@pritambiswal pritambiswal merged commit ce59d28 into prilk-consulting:develop Jan 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: draft name of sales invoice is used after submit

2 participants