Skip to content

Commit

Permalink
[FIX] website_sale_affiliate: remove too generic exception passing
Browse files Browse the repository at this point in the history
  • Loading branch information
em230418 committed Nov 16, 2023
1 parent 660bc3b commit 7f10878
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
13 changes: 8 additions & 5 deletions website_sale_affiliate/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ class WebsiteSale(Base):
def _store_affiliate_info(self, **kwargs):
Affiliate = request.env["sale.affiliate"]
affiliate = Affiliate.sudo().find_from_kwargs(**kwargs)
try:
affiliate_request = affiliate.get_request(**kwargs)
request.session["affiliate_request"] = affiliate_request.id
except (AttributeError, ValueError):
pass
if not affiliate:
return

affiliate_request = affiliate.get_request(**kwargs)
if not affiliate_request:
return # pragma: no cover

request.session["affiliate_request"] = affiliate_request.id

@route()
def shop(self, *args, **post):
Expand Down
13 changes: 9 additions & 4 deletions website_sale_affiliate/models/sale_affiliate_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,18 @@ def _conversions_qualify(self):
return qualified_sales and qualified_time

def current_qualified(self):
if not request:
return

try:
current_id = request.session["affiliate_request"]
current = self.search([("id", "=", current_id)], limit=1)
except (KeyError, RuntimeError):
# KeyError if session exists, but no request
# RuntimeError if session is non-existent (XML record creations)
except KeyError:
return

current = self.search([("id", "=", current_id)], limit=1)
if not current:
return

if current._conversions_qualify():
return current
return
6 changes: 0 additions & 6 deletions website_sale_affiliate/tests/test_sale_affiliate_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,6 @@ def test_current_qualified_no_request_in_session(self, request_mock):
request_mock.session = {}
self.assertIsNone(self.AffiliateRequest.current_qualified())

@patch("%s.request" % MODEL_PATH)
def test_current_qualified_no_session(self, request_mock):
"""Returns None if there is no session."""
request_mock.session.__getitem__.side_effect = RuntimeError
self.assertIsNone(self.AffiliateRequest.current_qualified())

@patch.object(AffiliateRequest, "_conversions_qualify")
@patch("%s.request" % MODEL_PATH)
def test_current_qualified_request_in_session_calls_conversions_qualify(
Expand Down

0 comments on commit 7f10878

Please sign in to comment.