Skip to content

Commit

Permalink
[IMP]ir_config_parameter_multi_company: Improvements to get_base_url …
Browse files Browse the repository at this point in the history
…method in multicompany web.base.url scenario
  • Loading branch information
LorenzoC0 committed Feb 12, 2025
1 parent bc97b08 commit b3ae852
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions ir_config_parameter_multi_company/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import ir_config_parameter
from . import ir_model
11 changes: 11 additions & 0 deletions ir_config_parameter_multi_company/models/ir_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from odoo import models

class BaseModel(models.AbstractModel):
_inherit = 'base'

def get_base_url(self):
if 'company_id' in self._fields:
company = self.company_id
else:
company = self.env.company
return super(BaseModel,self.with_context(force_config_parameter_company = company)).get_base_url()
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,24 @@ def test_get_params_by_company(self):
.get_param("mail.catchall.alias_test")
)
self.assertEqual(value, "testValue")

def test_get_base_url_by_company(self):
testCompany1 = self.env["res.company"].browse(1)
testCompany2 = self.env["res.company"].create({"name": "TestCompany2"})
self.user.company_ids += testCompany2
parameter1 = self.env["ir.config_parameter"].with_user(self.user.id).search(
[("key", "=", "web.base.url")]
)
parameter1.write({"value": "TestCompany1", "company_id": testCompany1.id})
self.env["ir.config_parameter"].create(
{
"key": "web.base.url",
"value": "TestCompany2",
"company_id": testCompany2.id,
}
)
value = self.user.get_base_url()
self.assertEqual(value, "TestCompany1")
self.user.company_id = testCompany2.id
value = self.user.get_base_url()
self.assertEqual(value, "TestCompany2")

0 comments on commit b3ae852

Please sign in to comment.