diff --git a/account_statement_import_sheet_file/models/account_statement_import_sheet_mapping.py b/account_statement_import_sheet_file/models/account_statement_import_sheet_mapping.py index 2087cea7c..9952af199 100644 --- a/account_statement_import_sheet_file/models/account_statement_import_sheet_mapping.py +++ b/account_statement_import_sheet_file/models/account_statement_import_sheet_mapping.py @@ -27,6 +27,9 @@ class AccountStatementImportSheetMapping(models.Model): string="Decimals Separator", selection=[("dot", "dot (.)"), ("comma", "comma (,)"), ("none", "none")], default="comma", + help="When the separator is 'none', the value will be shifted according " + "to the currency decimals. For example, 12345 will be converted to " + "123.45", ) file_encoding = fields.Selection( string="Encoding", diff --git a/account_statement_import_sheet_file/models/account_statement_import_sheet_parser.py b/account_statement_import_sheet_file/models/account_statement_import_sheet_parser.py index 28c75ccfa..c5bb8246a 100644 --- a/account_statement_import_sheet_file/models/account_statement_import_sheet_parser.py +++ b/account_statement_import_sheet_file/models/account_statement_import_sheet_parser.py @@ -1,5 +1,6 @@ # Copyright 2019 ForgeFlow, S.L. # Copyright 2020 CorporateHub (https://corporatehub.eu) +# Copyright 2025 Jacques-Etienne Baudoux (BCIM) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). import itertools @@ -539,5 +540,14 @@ def _parse_decimal(self, value, mapping): or "0" ) value = value.replace(thousands, "") - value = value.replace(decimal, ".") + float_separator = "." + if decimal: + value = value.replace(decimal, float_separator) + else: + journal = self.env["account.journal"].browse( + self.env.context.get("journal_id") + ) + currency = journal.currency_id or journal.company_id.currency_id + decimal_places = currency.decimal_places if currency else 2 + value = value[:-decimal_places] + float_separator + value[-decimal_places:] return float(value) diff --git a/account_statement_import_sheet_file/readme/CONTRIBUTORS.md b/account_statement_import_sheet_file/readme/CONTRIBUTORS.md index 3c6a7839a..465777c8e 100644 --- a/account_statement_import_sheet_file/readme/CONTRIBUTORS.md +++ b/account_statement_import_sheet_file/readme/CONTRIBUTORS.md @@ -11,3 +11,4 @@ - [CorporateHub](https://corporatehub.eu/) - Alexey Pelykh \<\> - Sebastiano Picchi +- Jacques-Etienne Baudoux (BCIM) diff --git a/account_statement_import_sheet_file/tests/test_account_statement_import_sheet_file.py b/account_statement_import_sheet_file/tests/test_account_statement_import_sheet_file.py index 5199aef0f..f30133bee 100644 --- a/account_statement_import_sheet_file/tests/test_account_statement_import_sheet_file.py +++ b/account_statement_import_sheet_file/tests/test_account_statement_import_sheet_file.py @@ -1,5 +1,6 @@ # Copyright 2019 ForgeFlow, S.L. # Copyright 2020 CorporateHub (https://corporatehub.eu) +# Copyright 2025 Jacques-Etienne Baudoux (BCIM) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from base64 import b64encode @@ -55,6 +56,8 @@ def setUpClass(cls): cls.mock_mapping_comma_dot._get_float_separators.return_value = (",", ".") cls.mock_mapping_dot_comma = Mock() cls.mock_mapping_dot_comma._get_float_separators.return_value = (".", ",") + cls.mock_mapping_none_none = Mock() + cls.mock_mapping_none_none._get_float_separators.return_value = ("", "") def _data_file(self, filename, encoding=None): mode = "rt" if encoding else "rb" @@ -653,6 +656,11 @@ def test_parse_decimal(self): 1234567.89, self.mock_mapping_dot_comma, ), # inverted separators + ( + "123456", + 1234.56, + self.mock_mapping_none_none, + ), # no separator ] for value, expected, mock_mapping in test_cases: