Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
6606 Lượt xem

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>

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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')

 

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 4 24
1537
1
thg 4 25
940
Odoo Server Error Đã xử lý
1
thg 4 25
1087
0
thg 11 24
1344
0
thg 10 24
1417