Skip to content

Commit

Permalink
T1567 wordpress import (#32)
Browse files Browse the repository at this point in the history
* fix: add call to parent on exception

* chore: format

---------

Co-authored-by: Clément <[email protected]>
  • Loading branch information
clementcharmillot and Clément authored Aug 8, 2024
1 parent a04dc89 commit 741a310
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions website_sponsorship/models/res_partner_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,33 @@ def _get_valid_create_fields(self):

def _match_email_and_name(self, vals):
# Replace the rule with fuzzy search and using firstname and lastname
email = vals["email"].strip()
name = vals["firstname"] + " " + vals["lastname"]
return self.env["res.partner"].search(
[
("name", "%", name),
("email", "=ilike", email),
],
limit=1,
)
try:
email = vals["email"].strip()
name = vals["firstname"] + " " + vals["lastname"]
return self.env["res.partner"].search(
[
("name", "%", name),
("email", "=ilike", email),
],
limit=1,
)
except KeyError:
# No "firstname" or "lastname", the caller probably expected the initial
# behavior of the parent with "name"
return super()._match_email_and_name(vals)

def _match_name_and_zip(self, vals):
# Replace the rule for using firstname and lastname
name = vals["firstname"] + " " + vals["lastname"]
return self.env["res.partner"].search(
[
("name", "ilike", name),
("zip", "=", vals["zip"]),
],
limit=1,
)
try:
name = vals["firstname"] + " " + vals["lastname"]
return self.env["res.partner"].search(
[
("name", "ilike", name),
("zip", "=", vals["zip"]),
],
limit=1,
)
except KeyError:
# No "firstname" or "lastname", the caller probably expected the initial
# behavior of the parent with "name"
return super()._match_name_and_zip(vals)

0 comments on commit 741a310

Please sign in to comment.