From 682ccba7d23863202c48a943e2b021531358d012 Mon Sep 17 00:00:00 2001 From: Benjamin Dabelow Date: Tue, 5 Nov 2019 22:20:08 +0100 Subject: [PATCH 1/2] Parse GV codes anywhere in purpose - Adapt trigger condition for _parse_mt940_gvcodes() - Add test --- mt940/processors.py | 3 +- mt940_tests/self-provided/gv_codes.sta | 8 + mt940_tests/self-provided/gv_codes.yml | 206 +++++++++++++++++++++++++ 3 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 mt940_tests/self-provided/gv_codes.sta create mode 100644 mt940_tests/self-provided/gv_codes.yml diff --git a/mt940/processors.py b/mt940/processors.py index 21355d5..5e56cc3 100644 --- a/mt940/processors.py +++ b/mt940/processors.py @@ -205,7 +205,8 @@ def transaction_details_post_processor(transactions, tag, tag_dict, result): purpose = result.get('purpose') - if purpose and purpose[:4] in GVC_KEYS: # pragma: no branch + if purpose and any(gvk in purpose for gvk in GVC_KEYS + if gvk != ''): # pragma: no branch result.update(_parse_mt940_gvcodes(result['purpose'])) del result['transaction_details'] diff --git a/mt940_tests/self-provided/gv_codes.sta b/mt940_tests/self-provided/gv_codes.sta new file mode 100644 index 0000000..8f7b007 --- /dev/null +++ b/mt940_tests/self-provided/gv_codes.sta @@ -0,0 +1,8 @@ +:20:STARTUMS +:25:12345678/1020304050 +:28C:0 +:60F:C170914EUR12345,12 +:61:170914D233,15NMSC +:86:835?20Cie., S.C.A.?21SEPA-BASISLASTSCHRIFT?22EREF+ 1234567890123 PAYPAL?23MREF+ 12AB234CD6E7F CRED+ A?24B12CDE0000000000000000034 S?25VWZ+ . SPOTIFY, Ihr Einkauf?26bei SPOTIFY?32PayPal (Europe) S.a.r.l. et +:61:1910251025D24,30NMSCNONREF + diff --git a/mt940_tests/self-provided/gv_codes.yml b/mt940_tests/self-provided/gv_codes.yml new file mode 100644 index 0000000..d31e970 --- /dev/null +++ b/mt940_tests/self-provided/gv_codes.yml @@ -0,0 +1,206 @@ +&id003 !!python/object:mt940.models.Transactions +data: + account_identification: 12345678/1020304050 + final_opening_balance: !!python/object:mt940.models.Balance + amount: !!python/object:mt940.models.Amount + amount: !!python/object/apply:decimal.Decimal + - '12345.12' + currency: EUR + date: !!python/object/apply:mt940.models.Date + - !!binary | + B+EJDg== + status: C + sequence_number: null + statement_number: '0' + transaction_reference: STARTUMS +processors: + post_account_identification: [] + post_available_balance: [] + post_closing_balance: [] + post_date_time_indication: [] + post_final_closing_balance: [] + post_final_opening_balance: [] + post_floor_limit_indicator: [] + post_forward_available_balance: [] + post_intermediate_closing_balance: [] + post_intermediate_opening_balance: [] + post_non_swift: [] + post_opening_balance: [] + post_related_reference: [] + post_statement: + - !!python/name:mt940.processors.date_cleanup_post_processor '' + post_statement_number: [] + post_sum_credit_entries: [] + post_sum_debit_entries: [] + post_transaction_details: + - !!python/name:mt940.processors.transaction_details_post_processor '' + post_transaction_reference_number: [] + pre_account_identification: [] + pre_available_balance: [] + pre_closing_balance: [] + pre_date_time_indication: [] + pre_final_closing_balance: [] + pre_final_opening_balance: [] + pre_floor_limit_indicator: [] + pre_forward_available_balance: [] + pre_intermediate_closing_balance: [] + pre_intermediate_opening_balance: [] + pre_non_swift: [] + pre_opening_balance: [] + pre_related_reference: [] + pre_statement: + - !!python/name:mt940.processors.date_fixup_pre_processor '' + pre_statement_number: [] + pre_sum_credit_entries: [] + pre_sum_debit_entries: [] + pre_transaction_details: [] + pre_transaction_reference_number: [] +tags: + 13: !!python/object:mt940.tags.DateTimeIndication + re: !!python/object/apply:re._compile + - "^\n (?P\\d{2})\n (?P\\d{2})\n (?P\\d{2})\n (?P\\\ + d{2})\n (?P\\d{2})\n (\\+(?P\\d{4})|)\n " + - 98 + 20: !!python/object:mt940.tags.TransactionReferenceNumber + re: !!python/object/apply:re._compile + - (?P.{0,16}) + - 98 + 21: !!python/object:mt940.tags.RelatedReference + re: !!python/object/apply:re._compile + - (?P.{0,16}) + - 98 + 25: !!python/object:mt940.tags.AccountIdentification + re: !!python/object/apply:re._compile + - (?P.{0,35}) + - 98 + 28: !!python/object:mt940.tags.StatementNumber + re: !!python/object/apply:re._compile + - "\n (?P\\d{1,5}) # 5n\n (?:/?(?P\\\ + d{1,5}))? # [/5n]\n $" + - 98 + 60: !!python/object:mt940.tags.OpeningBalance + re: &id001 !!python/object/apply:re._compile + - "^\n (?P[DC]) # 1!a Debit/Credit\n (?P\\d{2}) # 6!n Value\ + \ Date (YYMMDD)\n (?P\\d{2})\n (?P\\d{2})\n (?P.{3})\ + \ # 3!a Currency\n (?P[0-9,]{0,16}) # 15d Amount (includes decimal\ + \ sign, so 16)\n " + - 98 + 60M: !!python/object:mt940.tags.IntermediateOpeningBalance + re: *id001 + 60F: !!python/object:mt940.tags.FinalOpeningBalance + re: *id001 + 61: !!python/object:mt940.tags.Statement + re: !!python/object/apply:re._compile + - "^\n (?P\\d{2}) # 6!n Value Date (YYMMDD)\n (?P\\d{2})\n\ + \ (?P\\d{2})\n (?P\\d{2})? # [4!n] Entry Date (MMDD)\n\ + \ (?P\\d{2})?\n (?P[A-Z]?[DC]) # 2a Debit/Credit Mark\n\ + \ (?P[A-Z])? # [1!a] Funds Code (3rd character of the currency\n\ + \ # code, if needed)\n \\n? # apparently some\ + \ banks (sparkassen) incorporate newlines here\n (?P[\\d,]{1,15})\ + \ # 15d Amount\n (?P[A-Z][A-Z0-9 ]{3})? # 1!a3!c Transaction Type Identification\ + \ Code\n (?P.{0,16}) # 16x Customer Reference\n (//(?P.{0,23}))?\ + \ # [//23x] Bank Reference\n (\\n?(?P.{0,34}))? # [34x]\ + \ Supplementary Details\n $" + - 98 + 62: !!python/object:mt940.tags.ClosingBalance + re: *id001 + 62M: !!python/object:mt940.tags.IntermediateClosingBalance + re: *id001 + 62F: !!python/object:mt940.tags.FinalClosingBalance + re: *id001 + 64: !!python/object:mt940.tags.AvailableBalance + re: *id001 + 65: !!python/object:mt940.tags.ForwardAvailableBalance + re: *id001 + 86: !!python/object:mt940.tags.TransactionDetails + re: !!python/object/apply:re._compile + - "\n (?P(([\\s\\S]{0,65}\\r?\\n?){0,8}[\\s\\S]{0,65}))\n\ + \ " + - 98 + 34: !!python/object:mt940.tags.FloorLimitIndicator + re: !!python/object/apply:re._compile + - "^\n (?P[A-Z]{3}) # 3!a Currency\n (?P[DC ]?) # 2a\ + \ Debit/Credit Mark\n (?P[0-9,]{0,16}) # 15d Amount (includes decimal\ + \ sign, so 16)\n $" + - 98 + NS: !!python/object:mt940.tags.NonSwift + re: !!python/object/apply:re._compile + - "\n (?P\n (\n (\\d{2}.{0,})\n (\\\ + n\\d{2}.{0,})*\n )|(\n [^\\n]*\n )\n )\n $" + - 98 + 90: !!python/object:mt940.tags.SumEntries + re: &id002 !!python/object/apply:re._compile + - "^\n (?P\\d*)\n (?P.{3}) # 3!a Currency\n (?P[\\\ + d,]{1,15}) # 15d Amount\n " + - 98 + 90D: !!python/object:mt940.tags.SumDebitEntries + re: *id002 + 90C: !!python/object:mt940.tags.SumCreditEntries + re: *id002 +transactions: +- !!python/object:mt940.models.Transaction + data: + FRST_ONE_OFF_RECC: null + additional_position_date: null + additional_position_reference: ' 12AB234CD6E7F ' + additional_purpose: null + amount: !!python/object:mt940.models.Amount + amount: !!python/object/apply:decimal.Decimal + - '-233.15' + currency: EUR + applicant_bin: null + applicant_creditor_id: ' AB12CDE0000000000000000034 ' + applicant_iban: null + applicant_name: PayPal (Europe) S.a.r.l. et + bank_reference: null + compensation_amount: null + currency: EUR + customer_reference: null + date: !!python/object/apply:mt940.models.Date + - !!binary | + B+EJDg== + debitor_identifier: null + deviate_applicant: null + deviate_recipient: null + end_to_end_reference: ' 1234567890123 PAYPAL' + extra_details: '' + funds_code: null + gvc_applicant_bin: null + gvc_applicant_iban: null + id: NMSC + old_SEPA_CI: null + old_SEPA_additional_position_reference: null + original_amount: null + posting_text: null + prima_nota: null + purpose: ' . SPOTIFY, Ihr Einkaufbei SPOTIFY' + purpose_code: null + recipient_name: null + return_debit_notes: null + settlement_tag: null + status: D + transaction_code: '835' + transactions: *id003 +- !!python/object:mt940.models.Transaction + data: + amount: !!python/object:mt940.models.Amount + amount: !!python/object/apply:decimal.Decimal + - '-24.30' + currency: EUR + bank_reference: null + currency: EUR + customer_reference: NONREF + date: !!python/object/apply:mt940.models.Date + - !!binary | + B+MKGQ== + entry_date: !!python/object/apply:mt940.models.Date + - !!binary | + B+MKGQ== + extra_details: '' + funds_code: null + guessed_entry_date: !!python/object/apply:mt940.models.Date + - !!binary | + B+MKGQ== + id: NMSC + status: D + transactions: *id003 From 67d9063362e952fe7ba72d3008a1236e8d2097eb Mon Sep 17 00:00:00 2001 From: Rick van Hattem Date: Fri, 8 Nov 2019 02:55:06 +0100 Subject: [PATCH 2/2] Incrementing version to v4.19.0 --- mt940/__about__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mt940/__about__.py b/mt940/__about__.py index 1b92f00..55cb95c 100644 --- a/mt940/__about__.py +++ b/mt940/__about__.py @@ -6,7 +6,7 @@ statistics and manipulation. '''.strip().split()) __email__ = 'wolph@wol.ph' -__version__ = '4.18.0' +__version__ = '4.19.0' __license__ = 'BSD' __copyright__ = 'Copyright 2015 Rick van Hattem (wolph)' __url__ = 'https://github.com/WoLpH/mt940'