Skip to content

Commit

Permalink
Improve and add tests for multi_company_disable
Browse files Browse the repository at this point in the history
  • Loading branch information
tarteo committed Jan 25, 2024
1 parent 629ce6a commit c11cf7c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions multi_company_disable/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ class ResCompany(models.Model):
_inherit = "res.company"

@api.model_create_multi
def create(self, vals_list): # pylint: disable=method-required-super
raise AccessError(_("Multi-company is disabled"))
def create(self, vals_list):
res = super().create(vals_list)
if not self.env.is_superuser():
raise AccessError(_("Multi-company is disabled"))
return res

@api.ondelete(at_uninstall=False)
def _unlink_prevent(self):
raise AccessError(_("Multi-company is disabled"))
if not self.env.is_superuser():
raise AccessError(_("Multi-company is disabled"))
1 change: 1 addition & 0 deletions multi_company_disable/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_prevent_crud
10 changes: 10 additions & 0 deletions multi_company_disable/tests/test_prevent_crud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo.exceptions import AccessError
from odoo.tests.common import TransactionCase


class TestPreventCrud(TransactionCase):
def test_creation(self):
with self.assertRaises(AccessError):
with self.with_user("admin"):
self.env["res.company"].create({"name": "My company"})
self.env["res.company"].create({"name": "My company 2"})

0 comments on commit c11cf7c

Please sign in to comment.