-
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] mail_template_multi_company: Migration to 18.0
- Loading branch information
1 parent
ba0a8c3
commit 30f40de
Showing
7 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,7 @@ Contributors | |
- Andrea Stirpe <[email protected]> | ||
- Alberto Nieto de Pablos <[email protected]> | ||
(https://braintec.com) | ||
- `Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>`__ | ||
|
||
Maintainers | ||
----------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
from . import models | ||
|
||
|
||
def post_init_hook(cr, registry): | ||
def post_init_hook(env): | ||
"""We should not set the company by default on all existing mail templates | ||
when installing this module. Because many standard template need not be | ||
specialized by company. | ||
OTOH, when this module is installed it makes sense that new templates | ||
being created by users have a company set by default.""" | ||
cr.execute("UPDATE mail_template SET company_id=null") | ||
env.cr.execute("UPDATE mail_template SET company_id=null") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
- Andrea Stirpe \<<[email protected]>\> | ||
- Alberto Nieto de Pablos \<<[email protected]>\> | ||
(<https://braintec.com>) | ||
- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_mail_template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestMailTemplateMultiCompany(TransactionCase): | ||
def setUp(self): | ||
super().setUp() | ||
# Create a company | ||
self.company = self.env["res.company"].create({"name": "Test Company"}) | ||
|
||
# Create a user in the multi-company group | ||
self.multi_company_user = self.env["res.users"].create( | ||
{ | ||
"name": "Multi Company User", | ||
"login": "multi_company_user", | ||
"email": "[email protected]", | ||
"groups_id": [(6, 0, [self.env.ref("base.group_multi_company").id])], | ||
} | ||
) | ||
|
||
# Create a mail template | ||
self.mail_template = self.env["mail.template"].create( | ||
{ | ||
"name": "Test Template", | ||
"subject": "Test Subject", | ||
"company_id": self.company.id, | ||
} | ||
) | ||
|
||
def test_company_id_field(self): | ||
"""Test that the company_id field is correctly set and retrieved.""" | ||
self.assertEqual( | ||
self.mail_template.company_id, | ||
self.company, | ||
"The company_id field should be correctly set in the mail template", | ||
) | ||
|
||
def test_field_visibility_in_views(self): | ||
"""Test that the company_id field appears in views for multi-company users.""" | ||
FormView = self.env.ref("mail_template_multi_company.mail_template_form_view") | ||
TreeView = self.env.ref("mail_template_multi_company.mail_template_tree_view") | ||
SearchView = self.env.ref( | ||
"mail_template_multi_company.mail_template_search_view" | ||
) | ||
|
||
# Simulate view rendering (pseudo-validation) | ||
self.assertTrue( | ||
"company_id" in FormView.arch, | ||
"The company_id field should appear in the form view for mail templates", | ||
) | ||
self.assertTrue( | ||
"company_id" in TreeView.arch, | ||
"The company_id field should appear in the tree view for mail templates", | ||
) | ||
self.assertTrue( | ||
"company_id" in SearchView.arch, | ||
"The company_id field should appear in the search view for mail templates", | ||
) | ||
|
||
def test_field_accessibility(self): | ||
# Create a user without access to the field | ||
restricted_user = self.env["res.users"].create( | ||
{ | ||
"name": "Restricted User", | ||
"login": "restricted_user", | ||
"email": "[email protected]", | ||
"groups_id": [(6, 0, [self.env.ref("base.group_user").id])], | ||
} | ||
) | ||
|
||
# Create a mail template as the restricted user | ||
mail_template = ( | ||
self.env["mail.template"] | ||
.with_user(restricted_user) | ||
.create( | ||
{ | ||
"name": "Test Template", | ||
"subject": "Test", | ||
"body_html": "<p>Test Body</p>", | ||
} | ||
) | ||
) | ||
self.assertFalse(mail_template.company_id) | ||
|
||
def test_default_company_id(self): | ||
"""Test that the company_id field defaults to False if not set.""" | ||
template_without_company = self.env["mail.template"].create( | ||
{"name": "No Company Template"} | ||
) | ||
self.assertFalse( | ||
template_without_company.company_id, | ||
"The company_id field should be empty by default if not explicitly set", | ||
) |