Skip to content

Commit efbeecc

Browse files
authored
Merge pull request #378 from oyarzun/transfer-action-support
Add required TFERACTION to TRANSFER
2 parents 1eb1d9a + 63e4944 commit efbeecc

4 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/ofxstatement/ofx.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,11 @@ def buildInvestTransaction(self, line: InvestStatementLine) -> None:
248248
inner_tran_type_tag_name = (
249249
None # income transactions don't have an envelope element
250250
)
251+
elif line.trntype == "TRANSFER":
252+
tran_type_detailed_tag_name = "TFERACTION"
253+
inner_tran_type_tag_name = None
251254
else:
252-
# INVEXPENSE and TRANSFER transactions don't have details or an envelope
255+
# INVEXPENSE transactions don't have details or an envelope
253256
tran_type_detailed_tag_name = None
254257
inner_tran_type_tag_name = None
255258

src/ofxstatement/statement.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
"SELLSHORT", # open short sale
5656
]
5757

58+
INVEST_TRANSACTION_TFERACTION = [
59+
"IN",
60+
"OUT",
61+
]
5862
INVEST_TRANSACTION_INCOMETYPES = [
5963
"CGLONG",
6064
"CGSHORT",
@@ -376,8 +380,11 @@ def assert_valid_sellstock(self):
376380

377381
def assert_valid_transfer(self):
378382
assert (
379-
self.trntype_detailed is None
380-
), f"trntype_detailed '{self.trntype_detailed}' should be empty for {self.trntype}"
383+
self.trntype_detailed in INVEST_TRANSACTION_TFERACTION
384+
), "trntype_detailed %s is not valid, must be one of %s" % (
385+
self.trntype_detailed,
386+
INVEST_TRANSACTION_TFERACTION,
387+
)
381388
assert self.security_id
382389
assert self.units
383390

src/ofxstatement/tests/test_ofx_invest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
<SUBACCTFUND>OTHER</SUBACCTFUND>
138138
</INVBANKTRAN>
139139
<TRANSFER>
140+
<TFERACTION>IN</TFERACTION>
140141
<INVTRAN>
141142
<FITID>7</FITID>
142143
<DTTRADE>20210103</DTTRADE>
@@ -239,7 +240,7 @@ def test_ofxWriter(self) -> None:
239240
statement.invest_lines.append(invest_line)
240241

241242
invest_line = InvestStatementLine(
242-
"7", datetime(2021, 1, 3), "Journaled Shares", "TRANSFER"
243+
"7", datetime(2021, 1, 3), "Journaled Shares", "TRANSFER", "IN"
243244
)
244245
invest_line.security_id = "MSFT"
245246
invest_line.units = Decimal("4")

src/ofxstatement/tests/test_statement.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def test_generate_unique_transaction_id(self) -> None:
5454
def test_transfer_line_validation(self) -> None:
5555
line = statement.InvestStatementLine("id", datetime(2020, 3, 25))
5656
line.trntype = "TRANSFER"
57+
line.trntype_detailed = "IN"
5758
line.security_id = "ABC"
5859
line.units = Decimal(2)
5960
line.assert_valid()

0 commit comments

Comments
 (0)