Skip to content

Commit

Permalink
[MIG] mail_template_multi_company: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HeliconiaSolutions committed Dec 26, 2024
1 parent ba0a8c3 commit 30f40de
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 3 deletions.
1 change: 1 addition & 0 deletions mail_template_multi_company/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------
Expand Down
4 changes: 2 additions & 2 deletions mail_template_multi_company/__init__.py
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")
2 changes: 1 addition & 1 deletion mail_template_multi_company/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Mail Template Multi Company",
"version": "16.0.1.0.0",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/multi-company",
Expand Down
1 change: 1 addition & 0 deletions mail_template_multi_company/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions mail_template_multi_company/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Andrea Stirpe &lt;<a class="reference external" href="mailto:a.stirpe&#64;onestein.nl">a.stirpe&#64;onestein.nl</a>&gt;</li>
<li>Alberto Nieto de Pablos &lt;<a class="reference external" href="mailto:alberto.nieto&#64;braintec.com">alberto.nieto&#64;braintec.com</a>&gt;
(<a class="reference external" href="https://braintec.com">https://braintec.com</a>)</li>
<li><a class="reference external" href="https://www.heliconia.io">Heliconia Solutions Pvt. Ltd.</a></li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
1 change: 1 addition & 0 deletions mail_template_multi_company/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_mail_template
92 changes: 92 additions & 0 deletions mail_template_multi_company/tests/test_mail_template.py
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",
)

0 comments on commit 30f40de

Please sign in to comment.