Skip to content

Commit dcb9d77

Browse files
committed
hotfix: fix issue with parser when transaction description is split into multiple lines
1 parent 9f7fe4d commit dcb9d77

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

casparser/process/cas_detailed.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ..exceptions import HeaderParseError, CASParseError
99
from .regex import DETAILED_DATE_RE, FOLIO_RE, SCHEME_RE, REGISTRAR_RE
1010
from .regex import CLOSE_UNITS_RE, NAV_RE, OPEN_UNITS_RE, VALUATION_RE
11-
from .regex import DIVIDEND_RE, TRANSACTION_RE1, TRANSACTION_RE2
11+
from .regex import DIVIDEND_RE, TRANSACTION_RE1, TRANSACTION_RE2, DESCRIPTION_TAIL_RE
1212
from ..types import FolioType, SchemeType
1313
from .utils import isin_search
1414

@@ -165,9 +165,15 @@ def process_detailed_text(text):
165165
nav=Decimal(m.group(2).replace(",", "_")),
166166
)
167167
continue
168+
description_tail = ""
169+
if m := re.search(DESCRIPTION_TAIL_RE, line):
170+
description_tail = m.group(1).strip()
171+
line = line.replace(m.group(1), "")
168172
if m := parse_transaction(line):
169173
date = date_parser.parse(m.group(1)).date()
170174
desc = m.group(2).strip()
175+
if description_tail != "":
176+
desc = " ".join([desc, description_tail])
171177
amt = Decimal(m.group(3).replace(",", "_").replace("(", "-"))
172178
if m.group(4) is None:
173179
units = None

casparser/process/regex.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@
2626

2727
TRANSACTION_RE1 = rf"{date_re}\t\t([^0-9].*)\t\t{amt_re}\t\t{amt_re}\t\t{amt_re}\t\t{amt_re}"
2828
TRANSACTION_RE2 = rf"{date_re}\t\t([^0-9].*)\t\t{amt_re}(?:\t\t{amt_re}\t\t{amt_re}\t\t{amt_re})*"
29+
DESCRIPTION_TAIL_RE = r"(\n.+?)(\t\t|$)"
2930
DIVIDEND_RE = r"(?:dividend|idcw).+?(reinvest)*.*?@\s+Rs\.\s*([\d\.]+)\s+per\s+unit"

0 commit comments

Comments
 (0)