feat: implement XML attachment file naming functionality#253
Conversation
Greptile SummaryThis PR adds a configurable auto-naming pattern for XML attachment file names in E Invoice Settings, wires the new
Confidence Score: 4/5The core naming logic and its fallbacks are sound, but the new settings field is gated behind auto_attach_xml in the UI while the manual download path also reads it, leaving that path unconfigurable without auto-attach enabled. The naming logic itself is well-implemented with proper sanitization and fallback. The one real defect is that eu_einvoice/european_e_invoice/doctype/e_invoice_settings/e_invoice_settings.json — the Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User action] --> B{Trigger}
B --> |Submit / Auto-attach| C[_attach_xml_file]
B --> |Download button| D[download_xrechnung]
C --> E[frappe.get_cached_doc E Invoice Settings]
D --> F[frappe.get_doc Sales Invoice]
F --> G[check_permission read]
G --> H[frappe.get_cached_doc E Invoice Settings]
E --> I[get_xml_attachment_file_base_name doc, pattern]
H --> I
I --> J{pattern empty?}
J --> |Yes| K[get_safe_file_name doc.name]
J --> |No| L[lstrip # from each dot-segment]
L --> M[parse_naming_series parts, doc]
M --> N{result empty or error?}
N --> |Yes / Exception| O[log_error + fallback to doc.name]
N --> |No| P[get_safe_file_name base]
K --> Q[base_name + .xml]
O --> Q
P --> Q
Reviews (3): Last reviewed commit: "refactor(eu_einvoice): enhance download_..." | Re-trigger Greptile |
|
@dafrose I think allowing endings like .#### creates new (global) naming series counters in the database and is something that we do not need. Normally a user wants to:
in the .xml name + some string like "Rechnung-", which makes the .xml prefix usually unique per Invoice, so no further numbering is needed |
|
I removed the mention of |
|
Just thinking of the manual "download"-button. Is there a reason, why, if the admin chooses to rename automatically, we would exclude it on this button? |
10a6f18 to
a0e6a1e
Compare
… XML
Add optional pattern on E Invoice Settings (auto_name_format_for_xml_file) for the
file base name when auto-attaching XML on Sales Invoice submit. Empty pattern keeps
using the document name; otherwise use naming-series-style segments (dot-separated,
parse_naming_series, {field} placeholders, date tokens), strip leading # per
segment so counter-only parts do not consume Series, sanitize with get_safe_file_name,
and fall back to the document name on error.
Colocate get_xml_attachment_file_base_name with Sales Invoice custom logic and cover
naming edge cases in test_sales_invoice.py.
Refresh E Invoice Settings controller and de / template catalogs for the new strings.
c009198 to
4812a5d
Compare
… base name Update the download_xrechnung function to retrieve the Sales Invoice document and check permissions before generating the XML file. The filename now utilizes a configurable base name from E Invoice Settings, improving flexibility for file naming. This change ensures that the generated XML file adheres to the specified naming format.
I implemented the button behaviour @0xD0M1M0 I also squashed the commits after rearranging the files a little bit. If there are no further comments, the PR is ready to be merged @barredterra |
Rearrange fields in e_invoice_settings.json for better organization, adding a label for the XML Settings section. Update localization files (de.po and main.pot) to reflect changes in field names and add new translations for XML Settings. Adjust POT creation dates for consistency.
|
Functionality works fine, just some nitpicks on the code. |
bda172e to
f740d09
Compare
05eb28c to
d8e3413
Compare
Resolve the downloadable XML filename stem in get_xml_attachment_file_base_name: read *Auto name format for XML file* from **E Invoice Settings** when the pattern argument is omitted, accept an optional keyword-only pattern override, and build the stem with parse_naming_series plus a no-op number generator so naming has no series counter DB side effects. Sanitize with get_safe_file_name and fall back to doc.name when the pattern is empty or fails. Call sites use the helper without duplicating settings reads. Tests pass pattern= for empty or whitespace patterns, and assert the settings-backed path by patching frappe.get_single_value only for **E Invoice Settings** / auto_name_format_for_xml_file.
d8e3413 to
41de37a
Compare
|
@Mergifyio backport version-16-hotfix version-15-hotfix |
✅ Backports have been createdDetails
Cherry-pick of d45a1f0 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
Cherry-pick of d45a1f0 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
* feat(eu_einvoice): configurable base name for auto-attached XRechnung XML
Add optional pattern on E Invoice Settings (auto_name_format_for_xml_file) for the
file base name when auto-attaching XML on Sales Invoice submit. Empty pattern keeps
using the document name; otherwise use naming-series-style segments (dot-separated,
parse_naming_series, {field} placeholders, date tokens), strip leading # per
segment so counter-only parts do not consume Series, sanitize with get_safe_file_name,
and fall back to the document name on error.
Colocate get_xml_attachment_file_base_name with Sales Invoice custom logic and cover
naming edge cases in test_sales_invoice.py.
Refresh E Invoice Settings controller and de / template catalogs for the new strings.
* refactor(eu_einvoice): enhance download_xrechnung to use configurable base name
Update the download_xrechnung function to retrieve the Sales Invoice document
and check permissions before generating the XML file.
The filename now utilizes a configurable base name from E Invoice Settings,
improving flexibility for file naming.
This change ensures that the generated XML file adheres to the specified naming format.
* chore(eu_einvoice): update E Invoice Settings and localization files
Rearrange fields in e_invoice_settings.json for better organization, adding a label for
the XML Settings section. Update localization files (de.po and main.pot) to reflect
changes in field names and add new translations for XML Settings.
Adjust POT creation dates for consistency.
* refactor(eu_einvoice): centralize sales invoice xml stem naming
Resolve the downloadable XML filename stem in get_xml_attachment_file_base_name:
read *Auto name format for XML file* from **E Invoice Settings** when the pattern
argument is omitted, accept an optional keyword-only pattern override, and build
the stem with parse_naming_series plus a no-op number generator so naming has no
series counter DB side effects. Sanitize with get_safe_file_name and fall back to
doc.name when the pattern is empty or fails.
Call sites use the helper without duplicating settings reads. Tests pass pattern=
for empty or whitespace patterns, and assert the settings-backed path by patching
frappe.get_single_value only for **E Invoice Settings** / auto_name_format_for_xml_file.
---------
Co-authored-by: Daniel Rose <26166128+dafrose@users.noreply.github.com>
(cherry picked from commit d45a1f0)
* feat(eu_einvoice): configurable base name for auto-attached XRechnung XML
Add optional pattern on E Invoice Settings (auto_name_format_for_xml_file) for the
file base name when auto-attaching XML on Sales Invoice submit. Empty pattern keeps
using the document name; otherwise use naming-series-style segments (dot-separated,
parse_naming_series, {field} placeholders, date tokens), strip leading # per
segment so counter-only parts do not consume Series, sanitize with get_safe_file_name,
and fall back to the document name on error.
Colocate get_xml_attachment_file_base_name with Sales Invoice custom logic and cover
naming edge cases in test_sales_invoice.py.
Refresh E Invoice Settings controller and de / template catalogs for the new strings.
* refactor(eu_einvoice): enhance download_xrechnung to use configurable base name
Update the download_xrechnung function to retrieve the Sales Invoice document
and check permissions before generating the XML file.
The filename now utilizes a configurable base name from E Invoice Settings,
improving flexibility for file naming.
This change ensures that the generated XML file adheres to the specified naming format.
* chore(eu_einvoice): update E Invoice Settings and localization files
Rearrange fields in e_invoice_settings.json for better organization, adding a label for
the XML Settings section. Update localization files (de.po and main.pot) to reflect
changes in field names and add new translations for XML Settings.
Adjust POT creation dates for consistency.
* refactor(eu_einvoice): centralize sales invoice xml stem naming
Resolve the downloadable XML filename stem in get_xml_attachment_file_base_name:
read *Auto name format for XML file* from **E Invoice Settings** when the pattern
argument is omitted, accept an optional keyword-only pattern override, and build
the stem with parse_naming_series plus a no-op number generator so naming has no
series counter DB side effects. Sanitize with get_safe_file_name and fall back to
doc.name when the pattern is empty or fails.
Call sites use the helper without duplicating settings reads. Tests pass pattern=
for empty or whitespace patterns, and assert the settings-backed path by patching
frappe.get_single_value only for **E Invoice Settings** / auto_name_format_for_xml_file.
---------
Co-authored-by: Daniel Rose <26166128+dafrose@users.noreply.github.com>
(cherry picked from commit d45a1f0)
Co-authored-by: Cursor <cursoragent@cursor.com>
* feat(eu_einvoice): configurable base name for auto-attached XRechnung XML
Add optional pattern on E Invoice Settings (auto_name_format_for_xml_file) for the
file base name when auto-attaching XML on Sales Invoice submit. Empty pattern keeps
using the document name; otherwise use naming-series-style segments (dot-separated,
parse_naming_series, {field} placeholders, date tokens), strip leading # per
segment so counter-only parts do not consume Series, sanitize with get_safe_file_name,
and fall back to the document name on error.
Colocate get_xml_attachment_file_base_name with Sales Invoice custom logic and cover
naming edge cases in test_sales_invoice.py.
Refresh E Invoice Settings controller and de / template catalogs for the new strings.
* refactor(eu_einvoice): enhance download_xrechnung to use configurable base name
Update the download_xrechnung function to retrieve the Sales Invoice document
and check permissions before generating the XML file.
The filename now utilizes a configurable base name from E Invoice Settings,
improving flexibility for file naming.
This change ensures that the generated XML file adheres to the specified naming format.
* chore(eu_einvoice): update E Invoice Settings and localization files
Rearrange fields in e_invoice_settings.json for better organization, adding a label for
the XML Settings section. Update localization files (de.po and main.pot) to reflect
changes in field names and add new translations for XML Settings.
Adjust POT creation dates for consistency.
* refactor(eu_einvoice): centralize sales invoice xml stem naming
Resolve the downloadable XML filename stem in get_xml_attachment_file_base_name:
read *Auto name format for XML file* from **E Invoice Settings** when the pattern
argument is omitted, accept an optional keyword-only pattern override, and build
the stem with parse_naming_series plus a no-op number generator so naming has no
series counter DB side effects. Sanitize with get_safe_file_name and fall back to
doc.name when the pattern is empty or fails.
Call sites use the helper without duplicating settings reads. Tests pass pattern=
for empty or whitespace patterns, and assert the settings-backed path by patching
frappe.get_single_value only for **E Invoice Settings** / auto_name_format_for_xml_file.
---------
Co-authored-by: Daniel Rose <26166128+dafrose@users.noreply.github.com>
(cherry picked from commit d45a1f0)
Co-authored-by: Cursor <cursoragent@cursor.com>
* feat(eu_einvoice): configurable base name for auto-attached XRechnung XML
Add optional pattern on E Invoice Settings (auto_name_format_for_xml_file) for the
file base name when auto-attaching XML on Sales Invoice submit. Empty pattern keeps
using the document name; otherwise use naming-series-style segments (dot-separated,
parse_naming_series, {field} placeholders, date tokens), strip leading # per
segment so counter-only parts do not consume Series, sanitize with get_safe_file_name,
and fall back to the document name on error.
Colocate get_xml_attachment_file_base_name with Sales Invoice custom logic and cover
naming edge cases in test_sales_invoice.py.
Refresh E Invoice Settings controller and de / template catalogs for the new strings.
* refactor(eu_einvoice): enhance download_xrechnung to use configurable base name
Update the download_xrechnung function to retrieve the Sales Invoice document
and check permissions before generating the XML file.
The filename now utilizes a configurable base name from E Invoice Settings,
improving flexibility for file naming.
This change ensures that the generated XML file adheres to the specified naming format.
* chore(eu_einvoice): update E Invoice Settings and localization files
Rearrange fields in e_invoice_settings.json for better organization, adding a label for
the XML Settings section. Update localization files (de.po and main.pot) to reflect
changes in field names and add new translations for XML Settings.
Adjust POT creation dates for consistency.
* refactor(eu_einvoice): centralize sales invoice xml stem naming
Resolve the downloadable XML filename stem in get_xml_attachment_file_base_name:
read *Auto name format for XML file* from **E Invoice Settings** when the pattern
argument is omitted, accept an optional keyword-only pattern override, and build
the stem with parse_naming_series plus a no-op number generator so naming has no
series counter DB side effects. Sanitize with get_safe_file_name and fall back to
doc.name when the pattern is empty or fails.
Call sites use the helper without duplicating settings reads. Tests pass pattern=
for empty or whitespace patterns, and assert the settings-backed path by patching
frappe.get_single_value only for **E Invoice Settings** / auto_name_format_for_xml_file.
---------
Co-authored-by: Daniel Rose <26166128+dafrose@users.noreply.github.com>
(cherry picked from commit d45a1f0)
Co-authored-by: Cursor <cursoragent@cursor.com>
* feat(eu_einvoice): configurable base name for auto-attached XRechnung XML
Add optional pattern on E Invoice Settings (auto_name_format_for_xml_file) for the
file base name when auto-attaching XML on Sales Invoice submit. Empty pattern keeps
using the document name; otherwise use naming-series-style segments (dot-separated,
parse_naming_series, {field} placeholders, date tokens), strip leading # per
segment so counter-only parts do not consume Series, sanitize with get_safe_file_name,
and fall back to the document name on error.
Colocate get_xml_attachment_file_base_name with Sales Invoice custom logic and cover
naming edge cases in test_sales_invoice.py.
Refresh E Invoice Settings controller and de / template catalogs for the new strings.
* refactor(eu_einvoice): enhance download_xrechnung to use configurable base name
Update the download_xrechnung function to retrieve the Sales Invoice document
and check permissions before generating the XML file.
The filename now utilizes a configurable base name from E Invoice Settings,
improving flexibility for file naming.
This change ensures that the generated XML file adheres to the specified naming format.
* chore(eu_einvoice): update E Invoice Settings and localization files
Rearrange fields in e_invoice_settings.json for better organization, adding a label for
the XML Settings section. Update localization files (de.po and main.pot) to reflect
changes in field names and add new translations for XML Settings.
Adjust POT creation dates for consistency.
* refactor(eu_einvoice): centralize sales invoice xml stem naming
Resolve the downloadable XML filename stem in get_xml_attachment_file_base_name:
read *Auto name format for XML file* from **E Invoice Settings** when the pattern
argument is omitted, accept an optional keyword-only pattern override, and build
the stem with parse_naming_series plus a no-op number generator so naming has no
series counter DB side effects. Sanitize with get_safe_file_name and fall back to
doc.name when the pattern is empty or fails.
Call sites use the helper without duplicating settings reads. Tests pass pattern=
for empty or whitespace patterns, and assert the settings-backed path by patching
frappe.get_single_value only for **E Invoice Settings** / auto_name_format_for_xml_file.
---------
Co-authored-by: Daniel Rose <26166128+dafrose@users.noreply.github.com>
* feat(eu_einvoice): configurable base name for auto-attached XRechnung XML
Add optional pattern on E Invoice Settings (auto_name_format_for_xml_file) for the
file base name when auto-attaching XML on Sales Invoice submit. Empty pattern keeps
using the document name; otherwise use naming-series-style segments (dot-separated,
parse_naming_series, {field} placeholders, date tokens), strip leading # per
segment so counter-only parts do not consume Series, sanitize with get_safe_file_name,
and fall back to the document name on error.
Colocate get_xml_attachment_file_base_name with Sales Invoice custom logic and cover
naming edge cases in test_sales_invoice.py.
Refresh E Invoice Settings controller and de / template catalogs for the new strings.
* refactor(eu_einvoice): enhance download_xrechnung to use configurable base name
Update the download_xrechnung function to retrieve the Sales Invoice document
and check permissions before generating the XML file.
The filename now utilizes a configurable base name from E Invoice Settings,
improving flexibility for file naming.
This change ensures that the generated XML file adheres to the specified naming format.
* chore(eu_einvoice): update E Invoice Settings and localization files
Rearrange fields in e_invoice_settings.json for better organization, adding a label for
the XML Settings section. Update localization files (de.po and main.pot) to reflect
changes in field names and add new translations for XML Settings.
Adjust POT creation dates for consistency.
* refactor(eu_einvoice): centralize sales invoice xml stem naming
Resolve the downloadable XML filename stem in get_xml_attachment_file_base_name:
read *Auto name format for XML file* from **E Invoice Settings** when the pattern
argument is omitted, accept an optional keyword-only pattern override, and build
the stem with parse_naming_series plus a no-op number generator so naming has no
series counter DB side effects. Sanitize with get_safe_file_name and fall back to
doc.name when the pattern is empty or fails.
Call sites use the helper without duplicating settings reads. Tests pass pattern=
for empty or whitespace patterns, and assert the settings-backed path by patching
frappe.get_single_value only for **E Invoice Settings** / auto_name_format_for_xml_file.
---------
Co-authored-by: Daniel Rose <26166128+dafrose@users.noreply.github.com>
(cherry picked from commit d45a1f0)
Co-authored-by: Cursor <cursoragent@cursor.com>



get_xml_attachment_file_base_namefunction to resolve file names.test_xml_attachment_naming.py.Ref: IBT-164
closes #245