Skip to Content
Menu
This question has been flagged
1 Reply
2241 Views

Where (and how) I am able to use existing database to insert specific custom configuration.
Lets say that I have a custom configuration per tenant (database) - for example different api kyes etc ... Where I can store this in the database?

Is there designated place in the database which can be used for this purpose? Or I need to create a model with specific columns where I will have only one row inserted with all my custom configuration data per database?

Avatar
Discard
Best Answer

Hi Mersed,

Usually you do this in Odoo within a configuration menu. This configuration menu is connected to a transient model. The data itself is then saved on the company level, meaning you have one configuration per company (per database).
You can find a good and detailed example in Odoo 12 under the "sales" module at https://github.com/odoo/odoo/blob/12.0/addons/sale/models/res_config_settings.py

In short you have a custom model for your settings like this:

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models


class ResConfigSettings(models.TransientModel):
    _inherit = 'res.config.settings'

    sale_note = fields.Text(related='company_id.sale_note', string="Terms & Conditions", readonly=False)

You inherit the res.company model to store your custom settings on it:

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models, _


class ResCompany(models.Model):
    _inherit = "res.company"

    sale_note = fields.Text(string='Default Terms and Conditions', translate=True)

You create a view to add your own custom settings:

<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <record id="res_config_settings_view_form" model="ir.ui.view">
        <field name="name">res.config.settings.view.form.inherit.your_module</field>
        <field name="model">res.config.settings</field>
        <field name="priority" eval="10"/>
        <field name="inherit_id" ref="base.res_config_settings_view_form" />
        <field name="arch" type="xml">
            <xpath expr="//div[hasclass('settings')]" position="inside">
              <div class="app_settings_block o_not_app" data-string="Your config" string="YourConfig" data-key="your_key">
                  <h2>Your custom config here</h2>
              </div>
            </xpath>
        </field>
    </record>

Regards,
Yenthe

Avatar
Discard
Author

In this specific case, having in mind that it will be used for the multitenant/multidatabase background api communication - the frontend will not be needed. I understand the point of company settings and will try that for sure. Thank you for follow up!

Related Posts Replies Views Activity
0
Dec 24
2
0
Dec 24
23
1
Dec 24
110
2
Dec 24
385
0
Dec 24
32