-
-
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.
[14.0] ir_config_parameter_multi_company implementation
- Loading branch information
1 parent
a0dcc9f
commit df9e4cf
Showing
9 changed files
with
126 additions
and
0 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
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,21 @@ | ||
# Copyright (C) 2019 - Today: GRAP (http://www.grap.coop) | ||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
"name": "IR Config Parameter Multi Company", | ||
"summary": "Add res company field in ir config parameter", | ||
"version": "1.0", | ||
"category": "Tools", | ||
"author": "GRAP, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/multi-company", | ||
"license": "AGPL-3", | ||
# "depends": ["web"], | ||
"data": [ | ||
"views/ir_config_parameter_view.xml", | ||
"security/ir.model.access.csv" | ||
], | ||
"images": [ | ||
], | ||
"installable": True, | ||
} |
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,2 @@ | ||
from . import ir_config_parameter | ||
from . import ir_config_company |
21 changes: 21 additions & 0 deletions
21
ir_config_parameter_multi_company/models/ir_config_company.py
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,21 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class IrConfigCompany(models.Model): | ||
_name = "ir.config_parameter_company" | ||
|
||
company_id = fields.Many2one( | ||
"res.company", | ||
string="Company", | ||
required=True, | ||
) | ||
|
||
company_value = fields.Char( | ||
required=True, | ||
string="Value", | ||
) | ||
|
||
config_parameter_id = fields.Many2one( | ||
"ir.config_parameter", | ||
string="Config Parameter", | ||
) |
27 changes: 27 additions & 0 deletions
27
ir_config_parameter_multi_company/models/ir_config_parameter.py
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,27 @@ | ||
from odoo import fields, models, api | ||
|
||
class IrConfigMultiCompany(models.Model): | ||
_inherit = "ir.config_parameter" | ||
|
||
company_value_ids = fields.One2many( | ||
"ir.config_parameter_company", | ||
"config_parameter_id", | ||
string="Company", | ||
required=False, | ||
) | ||
|
||
# how to test? Check here | ||
# https://www.odoo.com/documentation/14.0/developer/reference/cli.html#shell | ||
# https://www.odoo.com/documentation/15.0/developer/reference/backend/testing.html | ||
@api.model | ||
def _get_param(self, key): | ||
params = self.search([('key', '=', key)]) | ||
if params and params.company_value_ids: | ||
values = params.company_value_ids | ||
for value in values: | ||
if value.company_id == self.env.user.company_id: | ||
return value.company_value | ||
return super(IrConfigMultiCompany, self)._get_param(key) | ||
|
||
|
||
|
2 changes: 2 additions & 0 deletions
2
ir_config_parameter_multi_company/security/ir.model.access.csv
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,2 @@ | ||
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" | ||
"access_ir_config_parameter_company_system","ir_config_parameter_company_system","model_ir_config_parameter_company","base.group_system",1,1,1,1 |
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_ir_config_parameter_multi_company |
31 changes: 31 additions & 0 deletions
31
ir_config_parameter_multi_company/tests/test_ir_config_parameter_multi_company.py
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,31 @@ | ||
from odoo.tests import common | ||
|
||
class TestIrConfigParameterMultiCompany(common.TransactionCase): | ||
def test_basic_functionality(self): | ||
record = self.env['ir.config_parameter'].create({"key": "testKey", "value": "testValue"}) | ||
value = record.get_param('testKey') | ||
expected_field_value = "testValue" | ||
self.assertEqual( | ||
value, | ||
expected_field_value | ||
) | ||
|
||
def test_get_params(self): | ||
testCompany = self.env['res.company'].create({"name": "TestCompany"}) | ||
record = self.env['ir.config_parameter'].create({ | ||
"key": "mail.catchall.alias", "value": "testValue", "company_value_ids": [ | ||
(0, 0, {"company_id": self.env.company.id, "company_value": "CurrentCompany"}), | ||
(0, 0, {"company_id": testCompany.id, "company_value": "TestCompany"}) | ||
] | ||
}) | ||
value = record.get_param('mail.catchall.alias') | ||
self.assertEqual( | ||
value, | ||
"CurrentCompany" | ||
) | ||
self.env.user.company_id = testCompany.id | ||
value = record.get_param('mail.catchall.alias') | ||
self.assertEqual( | ||
value, | ||
"TestCompany" | ||
) |
20 changes: 20 additions & 0 deletions
20
ir_config_parameter_multi_company/views/ir_config_parameter_view.xml
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,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="ir_config_parameter_company_form" model="ir.ui.view"> | ||
<field name="name">ir_config_parameter_company_form</field> | ||
<field name="model">ir.config_parameter</field> | ||
<field name="inherit_id" ref="base.view_ir_config_form" /> | ||
<field name="arch" type="xml"> | ||
|
||
<xpath expr="//group" position="inside"> | ||
<field name="company_value_ids"> | ||
<tree string="Company" editable="bottom"> | ||
<field name="company_id" /> | ||
<field name="company_value" /> | ||
</tree> | ||
</field> | ||
</xpath> | ||
|
||
</field> | ||
</record> | ||
</odoo> |