From 463be24a51bfac08883c1a31cef7ba109a850eac Mon Sep 17 00:00:00 2001 From: "chafique.delli" Date: Fri, 15 Jul 2022 18:22:43 +0200 Subject: [PATCH 1/4] [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/4] 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/4] 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]), From b24e4e750700c31566c373c29b848b954f3d8773 Mon Sep 17 00:00:00 2001 From: Guillaume MASSON Date: Thu, 23 Apr 2026 11:07:43 -1000 Subject: [PATCH 4/4] [IMP] account_move_csv_import : add method to extract values from CPT195 to ease override --- account_move_csv_import/wizard/import_move.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/account_move_csv_import/wizard/import_move.py b/account_move_csv_import/wizard/import_move.py index f9b2e7b..d2fb23e 100644 --- a/account_move_csv_import/wizard/import_move.py +++ b/account_move_csv_import/wizard/import_move.py @@ -527,12 +527,12 @@ def silae2pivot(self, fileobj): 'line': i, } res.append(vals) - + return res + def cpt195txt2pivot(self, fileobj): res = [] i = 0 - file_content = base64.decodebytes(self.file_to_import) - file_content = file_content.decode("latin1") + file_content = fileobj.read().decode("latin1") file_lines = file_content[:-4].split("\r\n") for line in file_lines: i += 1 @@ -544,13 +544,14 @@ def cpt195txt2pivot(self, fileobj): continue vals = { 'journal': line[16:19], + 'adp_code': line[140:145], 'account': line[24:36], - "analytic": line[36:43] != "9999999" and line[36:43], + 'analytic': line[36:43] != "9999999" and line[36:43], '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, @@ -736,6 +737,8 @@ def create_moves_from_pivot(self, pivot, post=False): comp_cur = self.company_id.currency_id seq = self.env['ir.sequence'].next_by_code('account.move.import') cur_move = {} + if self.split_move_method == 'balanced': + pivot.sort(key=lambda x: (x['journal'], x.get('date'))) for l in pivot: if ( skip_null_lines and @@ -864,4 +867,4 @@ def reconcile_move_lines(self, moves): rec_ref, ', '.join(partners.keys())) continue lines_to_rec.reconcile() - logger.info('Reconcile imported moves finished') + logger.info('Reconcile imported moves finished') \ No newline at end of file