如何在没有Odoo数据库存储的xml文件中使用计算字段

问题描述 投票:0回答:1

首先,我创建一个计算字段来继承ir.model像这样:

    from odoo import api, fields, models, _
    from odoo.http import request

    class ir_models(models.Model):
      _inherit = 'ir.model'

    website_models = fields.Boolean('Allowed Website Model' ,compute='_is_website_models')

@api.depends('website_models')     
def _is_website_models(self):                 
    for models in self:
        fields = request.env['ir.model.fields'].search([('model_id', '=', models.id)])            
        for field in fields:
            if field.name == 'website_url':
                models.website_models = True

然后我想把这个字段用到xml文件中(进入视图)

    <?xml version="1.0" encoding="utf-8"?>
    <odoo>
    <record id="view_res_config_settings_website_search_ept"      model="ir.ui.view">
    <field name="model">res.config.settings</field>
    <field name="inherit_id" ref="website.res_config_settings_view_form"/>
    <field name="arch" type="xml">
        <xpath expr="//div[@id='languages_setting']" position="after">
            <div class="col-xs-12 col-md-6 o_setting_box" id="model_settings">
                <div class="o_setting_right_pane">
                    <label string="Website Serach"/>
                    <div class="text-muted">
                         <b>Configure Models Name</b>                             
                    </div>
                    <field name="model_id" widget="many2many_tags" domain="[('website_models', '=', True)]"/>                                                                                                     
                </div>
            </div>
        </xpath>
    </field>
</record>       

但它不能在xml文件中使用,因为该字段不存储在数据库中。然后如何使用它?请给出答案。并感谢先进的帮助。

xml odoo-11
1个回答
0
投票

在使用计算机字段时应在字段参数中提及store = True

website_models = fields.Boolean('Allowed Website Model',compute='_is_website_models',store=True)

它将该字段存储在数据库中。

© www.soinside.com 2019 - 2024. All rights reserved.