Skip to content

Commit bf8ae26

Browse files
committed
Make name and email acquisition more reliable
1 parent d3e51db commit bf8ae26

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

account_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,17 @@ def _paypal_transaction_to_lines(self, data):
291291
transaction_note = transaction.get("transaction_note")
292292
invoice = transaction.get("invoice_id")
293293
payer_name = payer.get("payer_name", {})
294-
payer_email = payer_name.get("email_address")
294+
payer_email = payer_name.get("email_address") or payer.get("email_address")
295+
payer_full_name = payer_name.get("full_name") or payer_name.get(
296+
"alternate_full_name"
297+
)
295298
if invoice:
296299
invoice = _("Invoice %s") % invoice
297300
note = transaction_id
298301
if transaction_subject or transaction_note:
299302
note = f"{note}: {transaction_subject or transaction_note}"
300-
if payer_email:
301-
note += " (%s)" % payer_email
303+
if payer_email or payer_full_name:
304+
note += f" ({payer_email or payer_full_name})"
302305
unique_import_id = f"{transaction_id}-{int(date.timestamp())}"
303306
name = (
304307
invoice
@@ -315,9 +318,6 @@ def _paypal_transaction_to_lines(self, data):
315318
"unique_import_id": unique_import_id,
316319
"raw_data": transaction,
317320
}
318-
payer_full_name = payer_name.get("full_name") or payer_name.get(
319-
"alternate_full_name"
320-
)
321321
if payer_full_name:
322322
line.update({"partner_name": payer_full_name})
323323
lines = [line]

account_statement_import_online_paypal/tests/test_account_statement_import_online_paypal.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,9 @@ def test_pull(self):
560560
"date": self.yesterday,
561561
"amount": "1000.00",
562562
"ref": "Invoice 1",
563-
"payment_ref": "1234567890: Payment for Invoice(s) 1",
563+
"payment_ref": (
564+
"1234567890: Payment for Invoice(s) 1 ([email protected])"
565+
),
564566
"partner_name": "Acme, Inc.",
565567
"unique_import_id": f"1234567890-{self.yesterday_timestamp}",
566568
},
@@ -572,7 +574,8 @@ def test_pull(self):
572574
"amount": "-100.00",
573575
"ref": "Fee for Invoice 1",
574576
"payment_ref": (
575-
"Transaction fee for 1234567890: Payment for Invoice(s) 1"
577+
"Transaction fee for 1234567890: Payment for Invoice(s) 1 "
578+
576579
),
577580
"partner_name": "PayPal",
578581
"unique_import_id": f"1234567890-{self.yesterday_timestamp}-FEE",
@@ -634,7 +637,9 @@ def test_transaction_parse_1(self):
634637
"date": self.today,
635638
"amount": "1000.00",
636639
"ref": "Invoice 1",
637-
"payment_ref": "1234567890: Payment for Invoice(s) 1",
640+
"payment_ref": (
641+
"1234567890: Payment for Invoice(s) 1 ([email protected])"
642+
),
638643
"partner_name": "Acme, Inc.",
639644
"unique_import_id": f"1234567890-{self.today_timestamp}",
640645
},
@@ -694,7 +699,9 @@ def test_transaction_parse_2(self):
694699
"date": self.today,
695700
"amount": "1000.00",
696701
"ref": "Invoice 1",
697-
"payment_ref": "1234567890: Payment for Invoice(s) 1",
702+
"payment_ref": (
703+
"1234567890: Payment for Invoice(s) 1 ([email protected])"
704+
),
698705
"partner_name": "Acme, Inc.",
699706
"unique_import_id": f"1234567890-{self.today_timestamp}",
700707
},
@@ -754,7 +761,9 @@ def test_transaction_parse_3(self):
754761
"date": self.today,
755762
"amount": "1000.00",
756763
"ref": "Invoice 1",
757-
"payment_ref": "1234567890: Payment for Invoice(s) 1",
764+
"payment_ref": (
765+
"1234567890: Payment for Invoice(s) 1 ([email protected])"
766+
),
758767
"partner_name": "Acme, Inc.",
759768
"unique_import_id": f"1234567890-{self.today_timestamp}",
760769
},
@@ -766,7 +775,8 @@ def test_transaction_parse_3(self):
766775
"amount": "-100.00",
767776
"ref": "Fee for Invoice 1",
768777
"payment_ref": (
769-
"Transaction fee for 1234567890: Payment for Invoice(s) 1"
778+
"Transaction fee for 1234567890: Payment for Invoice(s) 1 "
779+
770780
),
771781
"partner_name": "PayPal",
772782
"unique_import_id": f"1234567890-{self.today_timestamp}-FEE",
@@ -823,7 +833,9 @@ def test_transaction_parse_4(self):
823833
"date": self.today,
824834
"amount": "1000.00",
825835
"ref": "Invoice 1",
826-
"payment_ref": "1234567890: Payment for Invoice(s) 1",
836+
"payment_ref": (
837+
"1234567890: Payment for Invoice(s) 1 ([email protected])"
838+
),
827839
"partner_name": "Acme, Inc.",
828840
"unique_import_id": f"1234567890-{self.today_timestamp}",
829841
},

0 commit comments

Comments
 (0)