This question has been flagged
2 Replies
4907 Views

Hi !

I added a custom field in the general settings but I can't save the field. When I take a look at the field in DB, it is always set to False

python file:

from odoo import fields, models, api

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

mm_access_token = fields.Char("MM access token")

xml file:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="res_config_settings_mm" model="ir.ui.view">
<field name="name">res.config.settings.view.mattermost</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base_setup.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@id='multi_company']" position="after">
<div name="mattermost">
<h2>Mattermost Integration</h2>
<div class="row mt16 o_settings_container" id="multi_branch">
<div class="col-12 col-lg-6 o_setting_box">
<label for="mm_access_token" string="Mattermost Access Token"/>
<field name="mm_access_token" class="oe_inline"/>
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>

Avatar
Discard
Best Answer

Create a field in the res.company and then create a related field in the res config obj.

Ex:

_inherit = 'res.company'
mm_access_token = fields.Char("MM access token")


_inherit = 'res.config.settings'
mm_access_token = fields.Char("MM access token", related='company_id.mm_access_token')

 

Avatar
Discard
Author Best Answer

now I'm getting:

ERROR: column res_company.mm_access_token does not exist

Now in my .py file I have:

class Company(models.Model):
_inherit = 'res.company'

mm_token = fields.Char("Mattermost token")

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

mm_access_token = fields.Char("MM access token", related='company_id.mm_token')

When I update the module with the -u, I dont have any error but the field does not appear anymore in the config view
Avatar
Discard