From b4535cfc04c965717a66e881fa38c24332742240 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20-=20Le=20Filament?= <remi@le-filament.com>
Date: Wed, 4 Sep 2024 04:46:58 +0200
Subject: [PATCH] [FIX] amount from ROP

---
 wizard/ebics_statement_rop_import_wizard.py | 34 ++++++++++++---------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/wizard/ebics_statement_rop_import_wizard.py b/wizard/ebics_statement_rop_import_wizard.py
index 15b7800..27b531e 100644
--- a/wizard/ebics_statement_rop_import_wizard.py
+++ b/wizard/ebics_statement_rop_import_wizard.py
@@ -178,18 +178,24 @@ class EbicsStatementRopImport(models.TransientModel):
         rop_lines = []
         content = base64.b64decode(data).decode("utf-8").split("\n")
         for line in content:
-            if line[0:2] in ("11", "12", "21", "22"):
-                sens = 87 if line[0:2] in ("11", "21") else 86
-                amount = int(line[75:87]) / 100
-                rop_lines.append(
-                    {
-                        "date": datetime.strptime(line[177:185], "%Y%m%d").date(),
-                        "payment_ref": line[29:61].rstrip()
-                        + " - "
-                        + line[138:158].rstrip()
-                        + " - "
-                        + line[104:128].rstrip(),
-                        "amount": amount if line[sens] == "C" else -amount,
-                    }
-                )
+            if line[0:2] in ("11", "21"):
+                multiplier = 1 if line[87] == "C" else -1
+                amount = int(line[75:87]) * multiplier / 100
+            elif line[0:2] in ("12", "22"):
+                multiplier = 1 if line[86] == "C" else -1
+                amount = int(line[75:86]) * multiplier / 100
+            else:
+                continue
+
+            rop_lines.append(
+                {
+                    "date": datetime.strptime(line[177:185], "%Y%m%d").date(),
+                    "payment_ref": line[29:61].rstrip()
+                    + " - "
+                    + line[138:158].rstrip()
+                    + " - "
+                    + line[104:128].rstrip(),
+                    "amount": amount,
+                }
+            )
         return rop_lines
-- 
GitLab