[FIX] account_ebics - Number duplicate upload file names before the extension

A duplicate upload name got the counter appended to the previous
candidate and after the extension: pay.xml_1, then pay.xml_1_2,
pay.xml_1_2_3. Keep the extension and number from the original name:
pay_1.xml, pay_2.xml.
This commit is contained in:
Jérémy Didderen committed 2026-10-27 23:14:49 +01:00
1 parent a1fc381121
commit 0c86f79669
2 files changed
+15 -6

No files matched your search

+10 -4
View File
@@ -190,14 +190,20 @@ class TestEbicsXferUpload(EbicsTestCommon):
self.assertFalse(self.ebics_config.order_number) self.assertFalse(self.ebics_config.order_number)
def test_upload_same_name_twice(self): def test_upload_same_name_twice(self):
"""The counter goes before the extension and does not stack up."""
names = [] names = []
for _i in range(3): for _i in range(4):
wizard = self._upload_wizard(self.ff_btu) wizard = self._upload_wizard(self.ff_btu)
with self._fake_client(FakeEbicsClient()): with self._fake_client(FakeEbicsClient()):
names.append(wizard._ebics_upload().name) names.append(wizard._ebics_upload().name)
# Pinned, probably unintended: _update_ef_vals appends each counter to self.assertEqual(names, ["pay.xml", "pay_1.xml", "pay_2.xml", "pay_3.xml"])
# the previous candidate (pay.xml_1_2) instead of pay.xml_2. # without extension
self.assertEqual(names, ["pay.xml", "pay.xml_1", "pay.xml_1_2"]) wizard = self._upload_wizard(self.ff_btu, fname="pay")
with self._fake_client(FakeEbicsClient()):
self.assertEqual(wizard._ebics_upload().name, "pay")
wizard = self._upload_wizard(self.ff_btu, fname="pay")
with self._fake_client(FakeEbicsClient()):
self.assertEqual(wizard._ebics_upload().name, "pay_1")
def test_upload_ful_h003_order_number(self): def test_upload_ful_h003_order_number(self):
self.ebics_config.write({"ebics_version": "H003", "order_number": "A00Z"}) self.ebics_config.write({"ebics_version": "H003", "order_number": "A00Z"})
+5 -2
View File
@@ -3,6 +3,7 @@
import base64 import base64
import logging import logging
import os
from sys import exc_info from sys import exc_info
from traceback import format_exception from traceback import format_exception
@@ -578,11 +579,13 @@ class EbicsXfer(models.TransientModel):
fn = ef_vals["name"] fn = ef_vals["name"]
dups = self._check_duplicate_ebics_file(fn, self.format_id) dups = self._check_duplicate_ebics_file(fn, self.format_id)
if dups: if dups:
# pay.xml -> pay_1.xml, pay_2.xml, ...
base, ext = os.path.splitext(fn)
n = 1 n = 1
fn = "_".join([fn, str(n)]) fn = f"{base}_{n}{ext}"
while self._check_duplicate_ebics_file(fn, self.format_id): while self._check_duplicate_ebics_file(fn, self.format_id):
n += 1 n += 1
fn = "_".join([fn, str(n)]) fn = f"{base}_{n}{ext}"
ef_vals["name"] = fn ef_vals["name"] = fn
def _handle_download_data(self, data, file_format): def _handle_download_data(self, data, file_format):