Skip to content

Commit

Permalink
[FIX] default_multi_user: incorrectly keeping cache after company switch
Browse files Browse the repository at this point in the history
This was fixed upstream but the signature of the method never got
updated here in the corresponding hook.
  • Loading branch information
LoisRForgeFlow committed Jun 25, 2024
1 parent 016e234 commit 66520c4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions default_multi_user/hooks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 ForgeFlow S.L.
# Copyright 2020-24 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import json
Expand All @@ -10,7 +10,7 @@

def post_load_hook():
@api.model
@tools.ormcache("self.env.uid", "model_name", "condition")
@tools.ormcache("self.env.uid", "self.env.company.id", "model_name", "condition")
def new_get_model_defaults(self, model_name, condition=False):
if not hasattr(self, "_get_model_defaults_query_and_params"):
return self.get_model_defaults_original(model_name, condition=condition)
Expand Down
32 changes: 31 additions & 1 deletion default_multi_user/tests/test_default_multi_user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 ForgeFlow S.L.
# Copyright 2020-24 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import json
Expand Down Expand Up @@ -148,3 +148,33 @@ def test_05_multi_company(self):
self.user_1.company_id = self.other_company
rec_3 = self.partner_model.with_user(self.user_1).create({"name": "Test"})
self.assertNotEqual(rec_3.phone, self.test_value)

def test_06_user_switch_company(self):
"""Test defaults changing when a user switches company"""
global_value = "+34 666 555 444"
self.default_model.create(
{
"field_id": self.field.id,
"json_value": json.dumps(global_value, ensure_ascii=False),
}
)
self.default_model.create(
{
"field_id": self.field.id,
"json_value": json.dumps(self.test_value, ensure_ascii=False),
"company_id": self.main_company.id,
}
)

rec_1 = (
self.partner_model.with_user(self.user_2)
.with_company(self.main_company)
.create({"name": "Test"})
)
self.assertEqual(rec_1.phone, self.test_value)
rec_2 = (
self.partner_model.with_user(self.user_2)
.with_company(self.other_company)
.create({"name": "Test"})
)
self.assertEqual(rec_2.phone, global_value)

0 comments on commit 66520c4

Please sign in to comment.