From 463be24a51bfac08883c1a31cef7ba109a850eac Mon Sep 17 00:00:00 2001 From: "chafique.delli" Date: Fri, 15 Jul 2022 18:22:43 +0200 Subject: [PATCH 1/3] [ADD] file format CPT195 --- account_move_csv_import/__manifest__.py | 3 +- account_move_csv_import/wizard/import_move.py | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/account_move_csv_import/__manifest__.py b/account_move_csv_import/__manifest__.py index 2fee800..7208ef4 100644 --- a/account_move_csv_import/__manifest__.py +++ b/account_move_csv_import/__manifest__.py @@ -26,7 +26,8 @@ * In Extenso, * Ciel paye, * Payfit, -* FEC (text format). +* FEC (text format), +* CPT195 (text format). This module can easily be extended to support other formats. diff --git a/account_move_csv_import/wizard/import_move.py b/account_move_csv_import/wizard/import_move.py index 7456d1e..5719e39 100644 --- a/account_move_csv_import/wizard/import_move.py +++ b/account_move_csv_import/wizard/import_move.py @@ -40,6 +40,7 @@ class AccountMoveImport(models.TransientModel): ('cielpaye', 'Ciel Paye'), ('payfit', 'Payfit'), ('silae', 'SILAE'), + ('cpt195_txt', 'CPT195 (text)'), ], string='File Format', required=True, default='genericxlsx') post_move = fields.Boolean( string='Post Journal Entry', @@ -157,6 +158,8 @@ def file2pivot(self, fileobj, file_bytes): return self.fectxt2pivot(fileobj) elif file_format == 'silae': return self.silae2pivot(fileobj) + elif file_format == 'cpt195_txt': + return self.cpt195txt2pivot(fileobj) else: raise UserError(_("You must select a file format.")) @@ -524,6 +527,38 @@ def silae2pivot(self, fileobj): 'line': i, } res.append(vals) + + def cpt195txt2pivot(self, fileobj): + res = [] + i = 0 + file_content = base64.decodebytes(self.file_to_import) + file_content = file_content.decode("latin1") + file_lines = file_content[:-4].split("\r\n") + for line in file_lines: + i += 1 + # Skip line that is not a detail of the account + if line[21] != 'D': + continue + vals = { + 'journal': line[16:19], + 'account': line[24:36], + 'date': datetime.strptime(line[22:24] + line[12:14] + line[158:160] + line[14:16], '%d%m%Y'), + 'name': line[80:100], + 'ref': line[140:143], + 'line': i, + } + if float(line[67:80]) != 0.0 and float(line[54:67]) != 0.0: + vals_credit = vals_debit = vals + vals_debit['credit'] = 0.0 + vals_debit['debit'] = float(line[54:65] + '.' + line[65:67]) + res.append(vals_debit) + vals_credit['credit'] = float(line[67:78] + '.' + line[78:80]) + vals_credit['debit'] = 0.0 + res.append(vals_credit) + else: + vals['debit'] = float(line[54:65] + '.' + line[65:67]) + vals['credit'] = float(line[67:78] + '.' + line[78:80]) + res.append(vals) return res def _prepare_partner_speeddict(self, company_id): From 88107447273633f8642a5318b884fea1e5c1f31a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Sun, 29 Jan 2023 21:02:36 +0100 Subject: [PATCH 2/3] account_move_csv_import: fix cpt195 import and add analytic support --- account_move_csv_import/wizard/import_move.py | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/account_move_csv_import/wizard/import_move.py b/account_move_csv_import/wizard/import_move.py index 5719e39..e2d5e7c 100644 --- a/account_move_csv_import/wizard/import_move.py +++ b/account_move_csv_import/wizard/import_move.py @@ -536,28 +536,35 @@ def cpt195txt2pivot(self, fileobj): file_lines = file_content[:-4].split("\r\n") for line in file_lines: i += 1 + # Skip empty line + if not line: + continue # Skip line that is not a detail of the account if line[21] != 'D': continue vals = { 'journal': line[16:19], 'account': line[24:36], - 'date': datetime.strptime(line[22:24] + line[12:14] + line[158:160] + line[14:16], '%d%m%Y'), + "analytic": line[36:38] != "99" and line[36:38], + 'date': datelib( + year=int(line[158:160] + line[14:16]), + month=int(line[12:14]), + day=int(line[22:24]), + ), 'name': line[80:100], 'ref': line[140:143], 'line': i, } - if float(line[67:80]) != 0.0 and float(line[54:67]) != 0.0: - vals_credit = vals_debit = vals - vals_debit['credit'] = 0.0 - vals_debit['debit'] = float(line[54:65] + '.' + line[65:67]) - res.append(vals_debit) - vals_credit['credit'] = float(line[67:78] + '.' + line[78:80]) - vals_credit['debit'] = 0.0 - res.append(vals_credit) + credit = int(line[67:80]) / 100. + debit = int(line[54:67]) / 100. + if credit and debit: + vals.update({"credit": credit, "debit": 0}) + res.append(vals) + vals2 = vals.copy() + vals2.update({"credit": 0, "debit": debit}) + res.append(vals2) else: - vals['debit'] = float(line[54:65] + '.' + line[65:67]) - vals['credit'] = float(line[67:78] + '.' + line[78:80]) + vals.update({"credit": credit, "debit": debit}) res.append(vals) return res From 1950ef3628a2ebae8c24fc9619ed488a6eab34ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Thu, 15 Feb 2024 16:07:29 +0100 Subject: [PATCH 3/3] account_move_csv_import: analytic code have 7 chars --- account_move_csv_import/wizard/import_move.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_move_csv_import/wizard/import_move.py b/account_move_csv_import/wizard/import_move.py index e2d5e7c..f9b2e7b 100644 --- a/account_move_csv_import/wizard/import_move.py +++ b/account_move_csv_import/wizard/import_move.py @@ -545,7 +545,7 @@ def cpt195txt2pivot(self, fileobj): vals = { 'journal': line[16:19], 'account': line[24:36], - "analytic": line[36:38] != "99" and line[36:38], + "analytic": line[36:43] != "9999999" and line[36:43], 'date': datelib( year=int(line[158:160] + line[14:16]), month=int(line[12:14]),