Skip to content

Commit

Permalink
[14.0] ir_config_parameter_multi_company implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscraciungabriel committed Nov 23, 2023
1 parent a0dcc9f commit df9e4cf
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 0 deletions.
1 change: 1 addition & 0 deletions ir_config_parameter_multi_company/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions ir_config_parameter_multi_company/__manifest__.py
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,
}
2 changes: 2 additions & 0 deletions ir_config_parameter_multi_company/models/__init__.py
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 ir_config_parameter_multi_company/models/ir_config_company.py
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 ir_config_parameter_multi_company/models/ir_config_parameter.py
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)



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
1 change: 1 addition & 0 deletions ir_config_parameter_multi_company/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_ir_config_parameter_multi_company
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"
)
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>

0 comments on commit df9e4cf

Please sign in to comment.