6
6
7
7
from babel .numbers import NumberFormatError , parse_decimal
8
8
9
+ from pytr .utils import get_logger
10
+
9
11
10
12
class EventType (Enum ):
11
13
pass
@@ -51,15 +53,14 @@ class PPEventType(EventType):
51
53
# Dividends
52
54
"CREDIT" : PPEventType .DIVIDEND ,
53
55
"ssp_corporate_action_invoice_cash" : PPEventType .DIVIDEND ,
54
- # Failed card transactions
55
- "card_failed_transaction" : PPEventType .REMOVAL ,
56
56
# Interests
57
57
"INTEREST_PAYOUT" : PPEventType .INTEREST ,
58
58
"INTEREST_PAYOUT_CREATED" : PPEventType .INTEREST ,
59
59
# Removals
60
60
"OUTGOING_TRANSFER" : PPEventType .REMOVAL ,
61
61
"OUTGOING_TRANSFER_DELEGATION" : PPEventType .REMOVAL ,
62
62
"PAYMENT_OUTBOUND" : PPEventType .REMOVAL ,
63
+ "card_failed_transaction" : PPEventType .REMOVAL ,
63
64
"card_order_billed" : PPEventType .REMOVAL ,
64
65
"card_successful_atm_withdrawal" : PPEventType .REMOVAL ,
65
66
"card_successful_transaction" : PPEventType .REMOVAL ,
@@ -72,10 +73,37 @@ class PPEventType(EventType):
72
73
"ORDER_EXECUTED" : ConditionalEventType .TRADE_INVOICE ,
73
74
"SAVINGS_PLAN_EXECUTED" : ConditionalEventType .TRADE_INVOICE ,
74
75
"SAVINGS_PLAN_INVOICE_CREATED" : ConditionalEventType .TRADE_INVOICE ,
76
+ "trading_savingsplan_executed" : ConditionalEventType .TRADE_INVOICE ,
75
77
"benefits_spare_change_execution" : ConditionalEventType .TRADE_INVOICE ,
76
78
"TRADE_INVOICE" : ConditionalEventType .TRADE_INVOICE ,
79
+ "TRADE_CORRECTED" : ConditionalEventType .TRADE_INVOICE ,
77
80
}
78
81
82
+ log = get_logger (__name__ )
83
+
84
+ events_known_ignored = [
85
+ "CUSTOMER_CREATED" ,
86
+ "DEVICE_RESET" ,
87
+ "DOCUMENTS_ACCEPTED" ,
88
+ "DOCUMENTS_CREATED" ,
89
+ "EMAIL_VALIDATED" ,
90
+ "ORDER_CANCELED" ,
91
+ "ORDER_CREATED" ,
92
+ "ORDER_EXPIRED" ,
93
+ "ORDER_REJECTED" ,
94
+ "PUK_CREATED" ,
95
+ "REFERENCE_ACCOUNT_CHANGED" ,
96
+ "SECURITIES_ACCOUNT_CREATED" ,
97
+ "VERIFICATION_TRANSFER_ACCEPTED" ,
98
+ "card_failed_verification" ,
99
+ "card_successful_verification" ,
100
+ "current_account_activated" ,
101
+ "new_tr_iban" ,
102
+ "ssp_corporate_action_informative_notification" ,
103
+ "ssp_corporate_action_invoice_shares" ,
104
+ "ssp_dividend_option_customer_instruction" ,
105
+ ]
106
+
79
107
80
108
@dataclass
81
109
class Event :
@@ -110,9 +138,14 @@ def from_dict(cls, event_dict: Dict[Any, Any]):
110
138
111
139
@staticmethod
112
140
def _parse_type (event_dict : Dict [Any , Any ]) -> Optional [EventType ]:
113
- event_type : Optional [EventType ] = tr_event_type_mapping .get (event_dict .get ("eventType" , "" ), None )
114
- if event_dict .get ("status" , "" ).lower () == "canceled" :
115
- event_type = None
141
+ eventTypeStr = event_dict .get ("eventType" , "" )
142
+ event_type : Optional [EventType ] = tr_event_type_mapping .get (eventTypeStr , None )
143
+ if event_type is not None :
144
+ if event_dict .get ("status" , "" ).lower () == "canceled" :
145
+ event_type = None
146
+ else :
147
+ if eventTypeStr not in events_known_ignored :
148
+ log .warning (f"Ignoring event { eventTypeStr } " )
116
149
return event_type
117
150
118
151
@classmethod
@@ -247,13 +280,12 @@ def _parse_float_from_detail(elem_dict: Dict[str, Any]) -> Optional[float]:
247
280
Optional[float]: parsed float value or None
248
281
"""
249
282
unparsed_val = elem_dict .get ("detail" , {}).get ("text" , "" )
283
+ if unparsed_val == "" :
284
+ return None
250
285
parsed_val = re .sub (r"[^\,\.\d-]" , "" , unparsed_val )
251
286
252
- # Try the locale that will fail more likely first.
253
- if "." not in parsed_val :
254
- locales = ("en" , "de" )
255
- else :
256
- locales = ("de" , "en" )
287
+ # Prefer german locale.
288
+ locales = ("de" , "en" )
257
289
258
290
try :
259
291
result = float (parse_decimal (parsed_val , locales [0 ], strict = True ))
0 commit comments