Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0] [MIG] tg_event_guest #41

Closed

Conversation

kwhatk0k3
Copy link

[17.0] [MIG] tg_event_guest

@kwhatk0k3 kwhatk0k3 force-pushed the 17.0-mig-tg_event_guest branch from f2e6b0e to 642f44f Compare November 14, 2024 13:33
Comment on lines +7 to +8
class TestMain(TransactionCase):
def test_signup_01(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traceback (most recent call last):
  File "/__w/tg-addons/tg-addons/tg_event_guest/tests/test_main.py", line 52, in test_signup_01
    guest_user_tuple = Users.signup(
  File "/__w/tg-addons/tg-addons/tg_event_guest/models/res_users.py", line 24, in signup
    guest_register_code = request.params.get("guest_register_code")
  File "/opt/odoo-venv/lib/python3.10/site-packages/werkzeug/local.py", line 432, in __get__
    obj = instance._get_current_object()
  File "/opt/odoo-venv/lib/python3.10/site-packages/werkzeug/local.py", line 554, in _get_current_object
    return self.__local()  # type: ignore
  File "/opt/odoo-venv/lib/python3.10/site-packages/werkzeug/local.py", line 226, in _lookup
    raise RuntimeError("object unbound")
RuntimeError: object unbound
 

Это исправляется вводом patch_request

def patch_request(func):
def _decorator(self, *args, **kwargs):
with MockRequest(self.env) as req:
return func(self, req, *args, **kwargs)
return _decorator

и примением его к методу с тестом

@patch_request
def test_defaults_all_present(self, request_mock):

Comment on lines 22 to 23
guest_register_code = values.pop("guest_register_code", False)
res = super().signup(values, token)
guest_register_code = request.params.get("guest_register_code")
if guest_register_code:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/tg_event_guest/controllers/main.py b/tg_event_guest/controllers/main.py
index 1fc6d77..5173aa7 100644
--- a/tg_event_guest/controllers/main.py
+++ b/tg_event_guest/controllers/main.py
@@ -26,3 +26,9 @@ class AuthSignupHome(BaseAuthSignupHome):
                     qcontext["error"] = _("You need to logout to register guest")
 
         return qcontext
+
+    def _prepare_signup_values(self, qcontext):
+        values = super()._prepare_signup_values(qcontext)
+        if qcontext.get("guest_register_code"):
+            values["guest_register_code"] = qcontext["guest_register_code"]
+        return values
diff --git a/tg_event_guest/models/res_users.py b/tg_event_guest/models/res_users.py
index 6c22af0..dd3a9ac 100644
--- a/tg_event_guest/models/res_users.py
+++ b/tg_event_guest/models/res_users.py
@@ -21,7 +21,6 @@ class ResUsers(models.Model):
     def signup(self, values, token=None):
         guest_register_code = values.pop("guest_register_code", False)
         res = super().signup(values, token)
-        guest_register_code = request.params.get("guest_register_code")
         if guest_register_code:
             guest = self.env["event.guest"]._get_by_code(guest_register_code)
             if guest and not guest.result_partner:
diff --git a/tg_event_guest/tests/test_main.py b/tg_event_guest/tests/test_main.py
index de9cf09..6c9ef8e 100644
--- a/tg_event_guest/tests/test_main.py
+++ b/tg_event_guest/tests/test_main.py
@@ -58,8 +58,6 @@ class TestMain(TransactionCase):
             }
         )
         guest_user = Users.search([("login", "=", guest_user_tuple[1])])
-
-        guest._invalidate_cache(fnames=["result_partner"])
+        guest = self.env["event.guest"].browse(guest.id)
         self.assertEqual(guest.result_partner, guest_user.partner_id)
 
         # for example, some reason other test user registered with already used guest code # noqa: E501

Comment on lines 61 to 62

guest._invalidate_cache(fnames=["result_partner"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да пожалуй. Не могу найти причину, почему этот invalidate_cache сбрасывает значение, когда модуль ведет себя корректно.
Можно переделать, как я описал тут https://github.com/it-projects-llc/tg-addons/pull/41/files#r1843477360

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

То есть заменить invalidate_cache на guest = self.env["event.guest"].browse(guest.id)?

@kwhatk0k3 kwhatk0k3 force-pushed the 17.0-mig-tg_event_guest branch from f717f8d to 9948e5e Compare November 15, 2024 11:14
@kwhatk0k3 kwhatk0k3 force-pushed the 17.0-mig-tg_event_guest branch from 9948e5e to cd7e767 Compare November 15, 2024 11:15
@kwhatk0k3 kwhatk0k3 closed this Dec 9, 2024
@kwhatk0k3 kwhatk0k3 deleted the 17.0-mig-tg_event_guest branch December 9, 2024 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants