Skip to content

Commit 0bb7b9d

Browse files
committed
[FIX] account_statement_import_sheet_file: fix none separator
1 parent 9a349b4 commit 0bb7b9d

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

account_statement_import_sheet_file/models/account_statement_import_sheet_mapping.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class AccountStatementImportSheetMapping(models.Model):
2727
string="Decimals Separator",
2828
selection=[("dot", "dot (.)"), ("comma", "comma (,)"), ("none", "none")],
2929
default="comma",
30+
help="When the separator is 'none', the value will be shifted according "
31+
"to the currency decimals. For example, 12345 will be converted to "
32+
"123.45",
3033
)
3134
file_encoding = fields.Selection(
3235
string="Encoding",

account_statement_import_sheet_file/models/account_statement_import_sheet_parser.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright 2019 ForgeFlow, S.L.
22
# Copyright 2020 CorporateHub (https://corporatehub.eu)
3+
# Copyright 2025 Jacques-Etienne Baudoux (BCIM) <[email protected]>
34
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
45

56
import itertools
@@ -506,5 +507,14 @@ def _parse_decimal(self, value, mapping):
506507
or "0"
507508
)
508509
value = value.replace(thousands, "")
509-
value = value.replace(decimal, ".")
510+
float_separator = "."
511+
if decimal:
512+
value = value.replace(decimal, float_separator)
513+
else:
514+
journal = self.env["account.journal"].browse(
515+
self.env.context.get("journal_id")
516+
)
517+
currency = journal.currency_id or journal.company_id.currency_id
518+
decimal_places = currency.decimal_places if currency else 2
519+
value = value[:-decimal_places] + float_separator + value[-decimal_places:]
510520
return float(value)

account_statement_import_sheet_file/readme/CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
- [CorporateHub](https://corporatehub.eu/)
1212
- Alexey Pelykh \<<[email protected]>\>
1313
- Sebastiano Picchi <[email protected]>
14+
- Jacques-Etienne Baudoux (BCIM) <[email protected]>

account_statement_import_sheet_file/tests/test_account_statement_import_sheet_file.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright 2019 ForgeFlow, S.L.
22
# Copyright 2020 CorporateHub (https://corporatehub.eu)
3+
# Copyright 2025 Jacques-Etienne Baudoux (BCIM) <[email protected]>
34
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
45

56
from base64 import b64encode
@@ -53,6 +54,8 @@ def setUp(self):
5354
self.mock_mapping_comma_dot._get_float_separators.return_value = (",", ".")
5455
self.mock_mapping_dot_comma = Mock()
5556
self.mock_mapping_dot_comma._get_float_separators.return_value = (".", ",")
57+
self.mock_mapping_none_none = Mock()
58+
self.mock_mapping_none_none._get_float_separators.return_value = ("", "")
5659

5760
def _data_file(self, filename, encoding=None):
5861
mode = "rt" if encoding else "rb"
@@ -651,6 +654,11 @@ def test_parse_decimal(self):
651654
1234567.89,
652655
self.mock_mapping_dot_comma,
653656
), # inverted separators
657+
(
658+
"123456",
659+
1234.56,
660+
self.mock_mapping_none_none,
661+
), # no separator
654662
]
655663

656664
for value, expected, mock_mapping in test_cases:

0 commit comments

Comments
 (0)