Skip to content

Commit

Permalink
[MIG] fiscal_company_base: Migration to 16.0 (from 12.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Mar 29, 2024
1 parent f4c7c4d commit 6cf2208
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion fiscal_company_base/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{
"name": "CAE - Base",
"version": "12.0.1.2.3",
"version": "16.0.1.0.0",
"category": "CAE",
"summary": "Manage CAE (Cooperatives of Activities and Employment)",
"author": "GRAP",
Expand Down
3 changes: 0 additions & 3 deletions fiscal_company_base/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class ResCompany(models.Model):
string="Integrated Companies",
)

@api.multi
def _compute_other_fiscal_child_ids(self):
for company in self:
companies = self.search(
Expand Down Expand Up @@ -96,15 +95,13 @@ def create(self, vals):
company._propagate_access_right()
return company

@api.multi
def write(self, vals):
res = super().write(vals)
if vals.get("fiscal_type", False) == "fiscal_child":
self._propagate_access_right()
return res

# Private section
@api.multi
def _propagate_access_right(self):
"""Give access to the given fiscal child companies to all the
users that have access to the fiscal mother company"""
Expand Down
2 changes: 0 additions & 2 deletions fiscal_company_base/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ def create(self, vals):
user._propagate_access_right()
return user

@api.multi
def write(self, vals):
res = super().write(vals)
if vals.get("company_ids", False):
self._propagate_access_right()
return res

# Private function section
@api.multi
def _propagate_access_right(self):
"""If a user has access to a fiscal_mother company, so he'll have
access to all the child_company"""
Expand Down
16 changes: 8 additions & 8 deletions fiscal_company_base/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def setUp(self):
def test_01_res_users_propagate_access_right_create(self):
"""[Functional Test] A new user with access to mother company must
have access to child companies"""
new_user = self.ResUsers.sudo(user=self.user_accountant).create(
new_user = self.ResUsers.with_user(user=self.user_accountant).create(
{
"name": "new_user",
"login": "[email protected]",
Expand Down Expand Up @@ -71,7 +71,7 @@ def test_03_res_company_check_contraint_fail_01(self):
"""[Contraint Test] Try to create a company with
'fiscal_type != 'child' and and a mother company."""
with self.assertRaises(ValidationError):
self.ResCompany.sudo(user=self.user_accountant).create(
self.ResCompany.with_user(user=self.user_accountant).create(
{
"name": "new_company",
"fiscal_type": "normal",
Expand All @@ -83,15 +83,15 @@ def test_04_res_company_check_contraint_fail_02(self):
"""[Contraint Test] Try to create a company with
'fiscal_type != 'child' and and a mother company."""
with self.assertRaises(ValidationError):
self.ResCompany.sudo(user=self.user_accountant).create(
self.ResCompany.with_user(user=self.user_accountant).create(
{
"name": "new_company_1",
"fiscal_type": "fiscal_mother",
"fiscal_company_id": self.mother_company.id,
}
)
with self.assertRaises(ValidationError):
self.ResCompany.sudo(user=self.user_accountant).create(
self.ResCompany.with_user(user=self.user_accountant).create(
{
"name": "new_company_2",
"fiscal_type": "normal",
Expand All @@ -103,7 +103,7 @@ def test_05_res_company_check_contraint_fail_03(self):
"""[Contraint Test] Try to create a company with
'fiscal_type = 'child' without a mother company."""
with self.assertRaises(ValidationError):
self.ResCompany.sudo(user=self.user_accountant).create(
self.ResCompany.with_user(user=self.user_accountant).create(
{
"name": "new_company",
"fiscal_type": "fiscal_child",
Expand All @@ -113,7 +113,7 @@ def test_05_res_company_check_contraint_fail_03(self):

def test_06_res_company_create_child_propagate_success(self):
"""[Contraint Test] Create a child company and check propagation."""
new_company = self.ResCompany.sudo(user=self.user_accountant).create(
new_company = self.ResCompany.with_user(user=self.user_accountant).create(
{
"name": "new_company",
"fiscal_type": "fiscal_child",
Expand All @@ -132,10 +132,10 @@ def test_06_res_company_create_child_propagate_success(self):
def test_07_res_company_write_child_propagate_success(self):
"""[Contraint Test] Create and write a child company and check
propagation."""
new_company = self.ResCompany.sudo(user=self.user_accountant).create(
new_company = self.ResCompany.with_user(user=self.user_accountant).create(
{"name": "new_company", "fiscal_type": "normal"}
)
new_company.sudo(user=self.user_accountant).write(
new_company.with_user(user=self.user_accountant).write(
{"fiscal_type": "fiscal_child", "fiscal_company_id": self.mother_company.id}
)

Expand Down

0 comments on commit 6cf2208

Please sign in to comment.