odoo-addon-account-statement-import-sheet-file 17.0.1.1.1__py3-none-any.whl → 18.0.1.0.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  # Copyright 2019 ForgeFlow, S.L.
2
2
  # Copyright 2020 CorporateHub (https://corporatehub.eu)
3
+ # Copyright 2025 Tecnativa - Pedro M. Baeza
3
4
  # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4
5
 
5
6
  from base64 import b64encode
@@ -10,183 +11,106 @@ from unittest.mock import Mock
10
11
  from odoo import fields
11
12
  from odoo.exceptions import UserError
12
13
  from odoo.tests import common
13
- from odoo.tools import float_round
14
+ from odoo.tools import float_round, mute_logger
14
15
 
15
16
 
16
17
  class TestAccountStatementImportSheetFile(common.TransactionCase):
17
- def setUp(self):
18
- super().setUp()
19
-
20
- self.now = fields.Datetime.now()
21
- self.currency_eur = self.env.ref("base.EUR")
22
- self.currency_usd = self.env.ref("base.USD")
23
- self.currency_usd.active = True
24
- # Make sure the currency of the company is USD, as this not always happens
25
- # To be removed in V17: https://github.com/odoo/odoo/pull/107113
26
- self.company = self.env.company
27
- self.env.cr.execute(
28
- "UPDATE res_company SET currency_id = %s WHERE id = %s",
29
- (self.env.ref("base.USD").id, self.company.id),
30
- )
18
+ @classmethod
19
+ def setUpClass(cls):
20
+ super().setUpClass()
21
+ cls.now = fields.Datetime.now()
22
+ cls.currency_eur = cls.env.ref("base.EUR")
23
+ cls.currency_usd = cls.env.ref("base.USD")
24
+ cls.currency_usd.active = True
31
25
  # Activate EUR for unit test, by default is not active
32
- self.currency_eur.active = True
33
- self.sample_statement_map = self.env.ref(
26
+ cls.currency_eur.active = True
27
+ cls.sample_statement_map = cls.env.ref(
34
28
  "account_statement_import_sheet_file.sample_statement_map"
35
29
  )
36
- self.AccountJournal = self.env["account.journal"]
37
- self.AccountBankStatement = self.env["account.bank.statement"]
38
- self.AccountStatementImport = self.env["account.statement.import"]
39
- self.AccountStatementImportSheetMapping = self.env[
30
+ cls.AccountJournal = cls.env["account.journal"]
31
+ cls.AccountBankStatement = cls.env["account.bank.statement"]
32
+ cls.AccountStatementImport = cls.env["account.statement.import"]
33
+ cls.AccountStatementImportSheetMapping = cls.env[
40
34
  "account.statement.import.sheet.mapping"
41
35
  ]
42
- self.AccountStatementImportWizard = self.env["account.statement.import"]
43
- self.suspense_account = self.env["account.account"].create(
36
+ cls.AccountStatementImportWizard = cls.env["account.statement.import"]
37
+ cls.suspense_account = cls.env["account.account"].create(
44
38
  {
45
39
  "code": "987654",
46
40
  "name": "Suspense Account",
47
41
  "account_type": "asset_current",
48
42
  }
49
43
  )
50
- self.parser = self.env["account.statement.import.sheet.parser"]
44
+ cls.parser = cls.env["account.statement.import.sheet.parser"]
51
45
  # Mock the mapping object to return predefined separators
52
- self.mock_mapping_comma_dot = Mock()
53
- self.mock_mapping_comma_dot._get_float_separators.return_value = (",", ".")
54
- self.mock_mapping_dot_comma = Mock()
55
- self.mock_mapping_dot_comma._get_float_separators.return_value = (".", ",")
56
-
57
- def _data_file(self, filename, encoding=None):
58
- mode = "rt" if encoding else "rb"
59
- with open(path.join(path.dirname(__file__), filename), mode) as file:
60
- data = file.read()
61
- if encoding:
62
- data = data.encode(encoding)
63
- return b64encode(data)
64
-
65
- def test_import_csv_file(self):
66
- journal = self.AccountJournal.create(
46
+ cls.mock_mapping_comma_dot = Mock()
47
+ cls.mock_mapping_comma_dot._get_float_separators.return_value = (",", ".")
48
+ cls.mock_mapping_dot_comma = Mock()
49
+ cls.mock_mapping_dot_comma._get_float_separators.return_value = (".", ",")
50
+ cls.journal = cls.AccountJournal.create(
67
51
  {
68
52
  "name": "Bank",
69
53
  "type": "bank",
70
54
  "code": "BANK",
71
- "currency_id": self.currency_usd.id,
72
- "suspense_account_id": self.suspense_account.id,
55
+ "currency_id": cls.currency_usd.id,
56
+ "suspense_account_id": cls.suspense_account.id,
73
57
  }
74
58
  )
75
- data = self._data_file("fixtures/sample_statement_en.csv", "utf-8")
76
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
59
+ cls.statement_domain = [("journal_id", "=", cls.journal.id)]
60
+
61
+ def _get_import_wizard(self, path):
62
+ return self.AccountStatementImport.with_context(
63
+ journal_id=self.journal.id, account_statement_import_sheet_file_test=True
64
+ ).create(
77
65
  {
78
- "statement_filename": "fixtures/sample_statement_en.csv",
79
- "statement_file": data,
66
+ "statement_filename": path,
67
+ "statement_file": self._data_file(path),
80
68
  "sheet_mapping_id": self.sample_statement_map.id,
81
69
  }
82
70
  )
83
- wizard.with_context(
84
- account_statement_import_sheet_file_test=True
85
- ).import_file_button()
86
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
71
+
72
+ def _data_file(self, filename, encoding=None):
73
+ mode = "rt" if encoding else "rb"
74
+ with open(path.join(path.dirname(__file__), filename), mode) as file:
75
+ data = file.read()
76
+ if encoding:
77
+ data = data.encode(encoding)
78
+ return b64encode(data)
79
+
80
+ def test_import_csv_file(self):
81
+ wizard = self._get_import_wizard("fixtures/sample_statement_en.csv")
82
+ wizard.import_file_button()
83
+ statement = self.AccountBankStatement.search(self.statement_domain)
87
84
  self.assertEqual(len(statement), 1)
88
85
  self.assertEqual(len(statement.line_ids), 2)
89
86
 
90
87
  def test_import_empty_csv_file(self):
91
- journal = self.AccountJournal.create(
92
- {
93
- "name": "Bank",
94
- "type": "bank",
95
- "code": "BANK",
96
- "currency_id": self.currency_usd.id,
97
- "suspense_account_id": self.suspense_account.id,
98
- }
99
- )
100
- data = self._data_file("fixtures/empty_statement_en.csv", "utf-8")
101
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
102
- {
103
- "statement_filename": "fixtures/empty_statement_en.csv",
104
- "statement_file": data,
105
- "sheet_mapping_id": self.sample_statement_map.id,
106
- }
107
- )
88
+ wizard = self._get_import_wizard("fixtures/empty_statement_en.csv")
108
89
  with self.assertRaises(UserError):
109
- wizard.with_context(
110
- account_statement_import_sheet_file_test=True
111
- ).import_file_button()
112
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
90
+ wizard.import_file_button()
91
+ statement = self.AccountBankStatement.search(self.statement_domain)
113
92
  self.assertEqual(len(statement), 0)
114
93
 
115
94
  def test_import_xlsx_file(self):
116
- journal = self.AccountJournal.create(
117
- {
118
- "name": "Bank",
119
- "type": "bank",
120
- "code": "BANK",
121
- "currency_id": self.currency_usd.id,
122
- "suspense_account_id": self.suspense_account.id,
123
- }
124
- )
125
- data = self._data_file("fixtures/sample_statement_en.xlsx")
126
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
127
- {
128
- "statement_filename": "fixtures/sample_statement_en.xlsx",
129
- "statement_file": data,
130
- "sheet_mapping_id": self.sample_statement_map.id,
131
- }
132
- )
133
- wizard.with_context(
134
- account_statement_import_sheet_file_test=True
135
- ).import_file_button()
136
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
95
+ wizard = self._get_import_wizard("fixtures/sample_statement_en.xlsx")
96
+ wizard.import_file_button()
97
+ statement = self.AccountBankStatement.search(self.statement_domain)
137
98
  self.assertEqual(len(statement), 1)
138
99
  self.assertEqual(len(statement.line_ids), 2)
139
100
 
140
101
  def test_import_empty_xlsx_file(self):
141
- journal = self.AccountJournal.create(
142
- {
143
- "name": "Bank",
144
- "type": "bank",
145
- "code": "BANK",
146
- "currency_id": self.currency_usd.id,
147
- "suspense_account_id": self.suspense_account.id,
148
- }
149
- )
150
- data = self._data_file("fixtures/empty_statement_en.xlsx")
151
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
152
- {
153
- "statement_filename": "fixtures/empty_statement_en.xlsx",
154
- "statement_file": data,
155
- "sheet_mapping_id": self.sample_statement_map.id,
156
- }
157
- )
102
+ wizard = self._get_import_wizard("fixtures/empty_statement_en.xlsx")
158
103
  with self.assertRaises(UserError):
159
- wizard.with_context(
160
- account_statement_import_sheet_file_test=True
161
- ).import_file_button()
162
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
104
+ wizard.import_file_button()
105
+ statement = self.AccountBankStatement.search(self.statement_domain)
163
106
  self.assertEqual(len(statement), 0)
164
107
 
165
108
  def test_original_currency(self):
166
- journal = self.AccountJournal.create(
167
- {
168
- "name": "Bank",
169
- "type": "bank",
170
- "code": "BANK",
171
- "currency_id": self.currency_usd.id,
172
- "suspense_account_id": self.suspense_account.id,
173
- }
174
- )
175
- data = self._data_file("fixtures/original_currency.csv", "utf-8")
176
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
177
- {
178
- "statement_filename": "fixtures/original_currency.csv",
179
- "statement_file": data,
180
- "sheet_mapping_id": self.sample_statement_map.id,
181
- }
182
- )
183
- wizard.with_context(
184
- account_statement_import_sheet_file_test=True
185
- ).import_file_button()
186
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
109
+ wizard = self._get_import_wizard("fixtures/original_currency.csv")
110
+ wizard.import_file_button()
111
+ statement = self.AccountBankStatement.search(self.statement_domain)
187
112
  self.assertEqual(len(statement), 1)
188
113
  self.assertEqual(len(statement.line_ids), 1)
189
-
190
114
  line = statement.line_ids
191
115
  self.assertEqual(line.currency_id, self.currency_usd)
192
116
  self.assertEqual(line.amount, 1525.0)
@@ -214,30 +138,12 @@ class TestAccountStatementImportSheetFile(common.TransactionCase):
214
138
  "bank_account_column": "6",
215
139
  }
216
140
  )
217
- journal = self.AccountJournal.create(
218
- {
219
- "name": "Bank",
220
- "type": "bank",
221
- "code": "BANK",
222
- "currency_id": self.currency_usd.id,
223
- "suspense_account_id": self.suspense_account.id,
224
- }
225
- )
226
- data = self._data_file("fixtures/original_currency_no_header.csv", "utf-8")
227
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
228
- {
229
- "statement_filename": "fixtures/original_currency.csv",
230
- "statement_file": data,
231
- "sheet_mapping_id": no_header_statement_map.id,
232
- }
233
- )
234
- wizard.with_context(
235
- account_statement_import_sheet_file_test=True
236
- ).import_file_button()
237
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
141
+ wizard = self._get_import_wizard("fixtures/original_currency_no_header.csv")
142
+ wizard.sheet_mapping_id = no_header_statement_map.id
143
+ wizard.import_file_button()
144
+ statement = self.AccountBankStatement.search(self.statement_domain)
238
145
  self.assertEqual(len(statement), 1)
239
146
  self.assertEqual(len(statement.line_ids), 1)
240
-
241
147
  line = statement.line_ids
242
148
  self.assertEqual(line.currency_id, self.currency_usd)
243
149
  self.assertEqual(line.foreign_currency_id, self.currency_eur)
@@ -245,99 +151,43 @@ class TestAccountStatementImportSheetFile(common.TransactionCase):
245
151
  self.assertEqual(line.payment_ref, "Your payment INV0001")
246
152
 
247
153
  def test_original_currency_empty(self):
248
- journal = self.AccountJournal.create(
249
- {
250
- "name": "Bank",
251
- "type": "bank",
252
- "code": "BANK",
253
- "currency_id": self.currency_usd.id,
254
- "suspense_account_id": self.suspense_account.id,
255
- }
256
- )
257
- data = self._data_file("fixtures/original_currency_empty.csv", "utf-8")
258
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
259
- {
260
- "statement_filename": "fixtures/original_currency_empty.csv",
261
- "statement_file": data,
262
- "sheet_mapping_id": self.sample_statement_map.id,
263
- }
264
- )
265
- wizard.with_context(
266
- account_statement_import_sheet_file_test=True
267
- ).import_file_button()
268
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
154
+ wizard = self._get_import_wizard("fixtures/original_currency_empty.csv")
155
+ wizard.import_file_button()
156
+ statement = self.AccountBankStatement.search(self.statement_domain)
269
157
  self.assertEqual(len(statement), 1)
270
158
  self.assertEqual(len(statement.line_ids), 1)
271
-
272
159
  line = statement.line_ids
273
160
  self.assertFalse(line.foreign_currency_id)
274
161
  self.assertEqual(line.amount_currency, 0.0)
275
162
 
276
163
  def test_multi_currency(self):
277
- journal = self.AccountJournal.create(
278
- {
279
- "name": "Bank",
280
- "type": "bank",
281
- "code": "BANK",
282
- "currency_id": self.currency_usd.id,
283
- "suspense_account_id": self.suspense_account.id,
284
- }
285
- )
286
- statement_map = self.sample_statement_map.copy(
164
+ self.sample_statement_map.write(
287
165
  {
288
166
  "currency_column": "Currency",
289
167
  "original_currency_column": None,
290
168
  "original_amount_column": None,
291
169
  }
292
170
  )
293
- data = self._data_file("fixtures/multi_currency.csv", "utf-8")
294
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
295
- {
296
- "statement_filename": "fixtures/multi_currency.csv",
297
- "statement_file": data,
298
- "sheet_mapping_id": statement_map.id,
299
- }
300
- )
301
- wizard.with_context(
302
- account_statement_import_sheet_file_test=True
303
- ).import_file_button()
304
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
171
+ wizard = self._get_import_wizard("fixtures/multi_currency.csv")
172
+ wizard.import_file_button()
173
+ statement = self.AccountBankStatement.search(self.statement_domain)
305
174
  self.assertEqual(len(statement), 1)
306
175
  self.assertEqual(len(statement.line_ids), 1)
307
-
308
176
  line = statement.line_ids
309
177
  self.assertFalse(line.foreign_currency_id)
310
178
  self.assertEqual(line.amount, -33.5)
311
179
 
312
180
  def test_balance(self):
313
- journal = self.AccountJournal.create(
314
- {
315
- "name": "Bank",
316
- "type": "bank",
317
- "code": "BANK",
318
- "currency_id": self.currency_usd.id,
319
- "suspense_account_id": self.suspense_account.id,
320
- }
321
- )
322
- statement_map = self.sample_statement_map.copy(
181
+ self.sample_statement_map.write(
323
182
  {
324
183
  "balance_column": "Balance",
325
184
  "original_currency_column": None,
326
185
  "original_amount_column": None,
327
186
  }
328
187
  )
329
- data = self._data_file("fixtures/balance.csv", "utf-8")
330
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
331
- {
332
- "statement_filename": "fixtures/balance.csv",
333
- "statement_file": data,
334
- "sheet_mapping_id": statement_map.id,
335
- }
336
- )
337
- wizard.with_context(
338
- account_statement_import_sheet_file_test=True
339
- ).import_file_button()
340
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
188
+ wizard = self._get_import_wizard("fixtures/balance.csv")
189
+ wizard.import_file_button()
190
+ statement = self.AccountBankStatement.search(self.statement_domain)
341
191
  self.assertEqual(len(statement), 1)
342
192
  self.assertEqual(len(statement.line_ids), 2)
343
193
  self.assertEqual(statement.balance_start, 10.0)
@@ -345,16 +195,7 @@ class TestAccountStatementImportSheetFile(common.TransactionCase):
345
195
  self.assertEqual(statement.balance_end, 1510.0)
346
196
 
347
197
  def test_debit_credit(self):
348
- journal = self.AccountJournal.create(
349
- {
350
- "name": "Bank",
351
- "type": "bank",
352
- "code": "BANK",
353
- "currency_id": self.currency_usd.id,
354
- "suspense_account_id": self.suspense_account.id,
355
- }
356
- )
357
- statement_map = self.sample_statement_map.copy(
198
+ self.sample_statement_map.write(
358
199
  {
359
200
  "balance_column": "Balance",
360
201
  "original_currency_column": None,
@@ -364,18 +205,9 @@ class TestAccountStatementImportSheetFile(common.TransactionCase):
364
205
  "credit_value": "C",
365
206
  }
366
207
  )
367
- data = self._data_file("fixtures/debit_credit.csv", "utf-8")
368
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
369
- {
370
- "statement_filename": "fixtures/debit_credit.csv",
371
- "statement_file": data,
372
- "sheet_mapping_id": statement_map.id,
373
- }
374
- )
375
- wizard.with_context(
376
- account_statement_import_sheet_file_test=True
377
- ).import_file_button()
378
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
208
+ wizard = self._get_import_wizard("fixtures/debit_credit.csv")
209
+ wizard.import_file_button()
210
+ statement = self.AccountBankStatement.search(self.statement_domain)
379
211
  self.assertEqual(len(statement), 1)
380
212
  self.assertEqual(len(statement.line_ids), 2)
381
213
  self.assertEqual(statement.balance_start, 10.0)
@@ -383,16 +215,7 @@ class TestAccountStatementImportSheetFile(common.TransactionCase):
383
215
  self.assertEqual(statement.balance_end, 1510.0)
384
216
 
385
217
  def test_debit_credit_amount(self):
386
- journal = self.AccountJournal.create(
387
- {
388
- "name": "Bank",
389
- "type": "bank",
390
- "code": "BANK",
391
- "currency_id": self.currency_usd.id,
392
- "suspense_account_id": self.suspense_account.id,
393
- }
394
- )
395
- statement_map = self.sample_statement_map.copy(
218
+ self.sample_statement_map.write(
396
219
  {
397
220
  "amount_type": "distinct_credit_debit",
398
221
  "amount_debit_column": "Debit",
@@ -403,18 +226,9 @@ class TestAccountStatementImportSheetFile(common.TransactionCase):
403
226
  "original_amount_column": None,
404
227
  }
405
228
  )
406
- data = self._data_file("fixtures/debit_credit_amount.csv", "utf-8")
407
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
408
- {
409
- "statement_filename": "fixtures/debit_credit_amount.csv",
410
- "statement_file": data,
411
- "sheet_mapping_id": statement_map.id,
412
- }
413
- )
414
- wizard.with_context(
415
- account_statement_import_sheet_file_test=True
416
- ).import_file_button()
417
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
229
+ wizard = self._get_import_wizard("fixtures/debit_credit_amount.csv")
230
+ wizard.import_file_button()
231
+ statement = self.AccountBankStatement.search(self.statement_domain)
418
232
  self.assertEqual(len(statement), 1)
419
233
  self.assertEqual(len(statement.line_ids), 4)
420
234
  self.assertEqual(statement.balance_start, 10.0)
@@ -422,16 +236,7 @@ class TestAccountStatementImportSheetFile(common.TransactionCase):
422
236
  self.assertEqual(statement.balance_end, 1510.0)
423
237
 
424
238
  def test_metadata_separated_debit_credit_csv(self):
425
- journal = self.AccountJournal.create(
426
- {
427
- "name": "Bank",
428
- "type": "bank",
429
- "code": "BANK",
430
- "currency_id": self.currency_usd.id,
431
- "suspense_account_id": self.suspense_account.id,
432
- }
433
- )
434
- statement_map = self.sample_statement_map.copy(
239
+ self.sample_statement_map.write(
435
240
  {
436
241
  "footer_lines_skip_count": 1,
437
242
  "header_lines_skip_count": 5,
@@ -448,19 +253,11 @@ class TestAccountStatementImportSheetFile(common.TransactionCase):
448
253
  "amount_credit_column": "Credit",
449
254
  }
450
255
  )
451
- data = self._data_file("fixtures/meta_data_separated_credit_debit.csv", "utf-8")
452
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
453
- {
454
- "statement_filename": "fixtures/meta_data_separated_credit_debit.csv",
455
- "statement_file": data,
456
- "sheet_mapping_id": statement_map.id,
457
- }
256
+ wizard = self._get_import_wizard(
257
+ "fixtures/meta_data_separated_credit_debit.csv"
458
258
  )
459
- wizard.with_context(
460
- journal_id=journal.id,
461
- account_bank_statement_import_txt_xlsx_test=True,
462
- ).import_file_button()
463
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
259
+ wizard.import_file_button()
260
+ statement = self.AccountBankStatement.search(self.statement_domain)
464
261
  self.assertEqual(len(statement), 1)
465
262
  self.assertEqual(len(statement.line_ids), 4)
466
263
  line1 = statement.line_ids.filtered(lambda x: x.payment_ref == "LABEL 1")
@@ -469,16 +266,7 @@ class TestAccountStatementImportSheetFile(common.TransactionCase):
469
266
  self.assertEqual(line4.amount, -1300)
470
267
 
471
268
  def test_metadata_separated_debit_credit_xlsx(self):
472
- journal = self.AccountJournal.create(
473
- {
474
- "name": "Bank",
475
- "type": "bank",
476
- "code": "BANK",
477
- "currency_id": self.currency_usd.id,
478
- "suspense_account_id": self.suspense_account.id,
479
- }
480
- )
481
- statement_map = self.sample_statement_map.copy(
269
+ self.sample_statement_map.write(
482
270
  {
483
271
  "footer_lines_skip_count": 1,
484
272
  "header_lines_skip_count": 5,
@@ -495,19 +283,11 @@ class TestAccountStatementImportSheetFile(common.TransactionCase):
495
283
  "amount_credit_column": "Credit",
496
284
  }
497
285
  )
498
- data = self._data_file("fixtures/meta_data_separated_credit_debit.xlsx")
499
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
500
- {
501
- "statement_filename": "fixtures/meta_data_separated_credit_debit.xlsx",
502
- "statement_file": data,
503
- "sheet_mapping_id": statement_map.id,
504
- }
286
+ wizard = self._get_import_wizard(
287
+ "fixtures/meta_data_separated_credit_debit.xlsx"
505
288
  )
506
- wizard.with_context(
507
- journal_id=journal.id,
508
- account_bank_statement_import_txt_xlsx_test=True,
509
- ).import_file_button()
510
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
289
+ wizard.import_file_button()
290
+ statement = self.AccountBankStatement.search(self.statement_domain)
511
291
  self.assertEqual(len(statement), 1)
512
292
  self.assertEqual(len(statement.line_ids), 4)
513
293
  line1 = statement.line_ids.filtered(lambda x: x.payment_ref == "LABEL 1")
@@ -517,28 +297,11 @@ class TestAccountStatementImportSheetFile(common.TransactionCase):
517
297
 
518
298
  def test_amount_inverse_sign(self):
519
299
  self.sample_statement_map.amount_inverse_sign = True
520
- journal = self.AccountJournal.create(
521
- {
522
- "name": "Bank",
523
- "type": "bank",
524
- "code": "BANK",
525
- "currency_id": self.currency_usd.id,
526
- "suspense_account_id": self.suspense_account.id,
527
- }
300
+ wizard = self._get_import_wizard(
301
+ "fixtures/sample_statement_credit_card_inverse_sign_en.csv"
528
302
  )
529
- filename = "fixtures/sample_statement_credit_card_inverse_sign_en.csv"
530
- data = self._data_file(filename, "utf-8")
531
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
532
- {
533
- "statement_filename": filename,
534
- "statement_file": data,
535
- "sheet_mapping_id": self.sample_statement_map.id,
536
- }
537
- )
538
- wizard.with_context(
539
- account_statement_import_sheet_file_test=True
540
- ).import_file_button()
541
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
303
+ wizard.import_file_button()
304
+ statement = self.AccountBankStatement.search(self.statement_domain)
542
305
  self.assertEqual(len(statement), 1)
543
306
  self.assertEqual(len(statement.line_ids), 2)
544
307
  line1 = statement.line_ids.filtered(lambda x: x.payment_ref == "LABEL 1")
@@ -571,27 +334,12 @@ class TestAccountStatementImportSheetFile(common.TransactionCase):
571
334
  }
572
335
  )
573
336
  )
574
- journal = self.AccountJournal.create(
575
- {
576
- "name": "Bank 2",
577
- "type": "bank",
578
- "code": "BAN2",
579
- "currency_id": self.currency_usd.id,
580
- "suspense_account_id": self.suspense_account.id,
581
- }
337
+ wizard = self._get_import_wizard(
338
+ "fixtures/sample_statement_en_empty_values.xlsx"
582
339
  )
583
- data = self._data_file("fixtures/sample_statement_en_empty_values.xlsx")
584
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
585
- {
586
- "statement_filename": "fixtures/sample_statement_en_empty_values.xlsx",
587
- "statement_file": data,
588
- "sheet_mapping_id": sample_statement_map_empty_values.id,
589
- }
590
- )
591
- wizard.with_context(
592
- account_statement_import_sheet_file_test=True
593
- ).import_file_button()
594
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
340
+ wizard.sheet_mapping_id = sample_statement_map_empty_values.id
341
+ wizard.import_file_button()
342
+ statement = self.AccountBankStatement.search(self.statement_domain)
595
343
  self.assertEqual(len(statement), 1)
596
344
  self.assertEqual(len(statement.line_ids), 3)
597
345
 
@@ -679,16 +427,12 @@ class TestAccountStatementImportSheetFile(common.TransactionCase):
679
427
  1234.56,
680
428
  )
681
429
 
430
+ @mute_logger(
431
+ "odoo.addons.account_statement_import_sheet_file.models."
432
+ "account_statement_import"
433
+ )
682
434
  def test_offsets(self):
683
- journal = self.AccountJournal.create(
684
- {
685
- "name": "Bank",
686
- "type": "bank",
687
- "code": "BANK",
688
- "currency_id": self.currency_usd.id,
689
- "suspense_account_id": self.suspense_account.id,
690
- }
691
- )
435
+ journal = self.journal
692
436
  file_name = "fixtures/sample_statement_offsets.xlsx"
693
437
  data = self._data_file(file_name)
694
438
  wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
@@ -698,72 +442,49 @@ class TestAccountStatementImportSheetFile(common.TransactionCase):
698
442
  "sheet_mapping_id": self.sample_statement_map.id,
699
443
  }
700
444
  )
445
+ # First try with incorrect values
701
446
  with self.assertRaises(UserError):
702
447
  wizard.with_context(
703
448
  account_statement_import_txt_xlsx_test=True
704
449
  ).import_file_button()
705
- statement_map_offsets = self.sample_statement_map.copy(
706
- {
707
- "offset_column": 1,
708
- "header_lines_skip_count": 3,
709
- }
710
- )
711
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
712
- {
713
- "statement_filename": file_name,
714
- "statement_file": data,
715
- "sheet_mapping_id": statement_map_offsets.id,
716
- }
450
+ self.sample_statement_map.write(
451
+ {"offset_column": 1, "header_lines_skip_count": 3}
717
452
  )
718
453
  wizard.with_context(
719
454
  account_statement_import_txt_xlsx_test=True
720
455
  ).import_file_button()
721
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
456
+ statement = self.AccountBankStatement.search(self.statement_domain)
722
457
  self.assertEqual(len(statement), 1)
723
458
  self.assertEqual(len(statement.line_ids), 2)
724
459
  self.assertEqual(statement.balance_start, 0.0)
725
460
  self.assertEqual(statement.balance_end_real, 1491.5)
726
461
  self.assertEqual(statement.balance_end, 1491.5)
727
462
 
463
+ @mute_logger(
464
+ "odoo.addons.account_statement_import_sheet_file.models."
465
+ "account_statement_import"
466
+ )
728
467
  def test_skip_empty_lines(self):
729
- journal = self.AccountJournal.create(
730
- {
731
- "name": "Bank",
732
- "type": "bank",
733
- "code": "BANK",
734
- "currency_id": self.currency_usd.id,
735
- "suspense_account_id": self.suspense_account.id,
736
- }
737
- )
468
+ journal = self.journal
738
469
  file_name = "fixtures/empty_lines_statement.csv"
739
470
  data = self._data_file(file_name, "utf-8")
740
- statement_map_empty_line = self.sample_statement_map.copy(
741
- {
742
- "skip_empty_lines": False,
743
- }
744
- )
471
+ self.sample_statement_map.skip_empty_lines = False
745
472
  wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
746
473
  {
747
474
  "statement_filename": file_name,
748
475
  "statement_file": data,
749
- "sheet_mapping_id": statement_map_empty_line.id,
476
+ "sheet_mapping_id": self.sample_statement_map.id,
750
477
  }
751
478
  )
752
479
  with self.assertRaises(UserError):
753
480
  wizard.with_context(
754
481
  account_statement_import_txt_xlsx_test=True
755
482
  ).import_file_button()
756
- wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
757
- {
758
- "statement_filename": file_name,
759
- "statement_file": data,
760
- "sheet_mapping_id": self.sample_statement_map.id,
761
- }
762
- )
483
+ self.sample_statement_map.skip_empty_lines = True
763
484
  wizard.with_context(
764
485
  account_statement_import_txt_xlsx_test=True
765
486
  ).import_file_button()
766
- statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
487
+ statement = self.AccountBankStatement.search(self.statement_domain)
767
488
  self.assertEqual(len(statement), 1)
768
489
  self.assertEqual(len(statement.line_ids), 3)
769
490
  self.assertEqual(statement.balance_start, 0.0)