首页 > 解决方案 > 在odoo的产品页面上添加复选框字段

问题描述

我在产品页面上添加了一个复选框当 (checkbox_customtext) 字段为 TRUE 时 (customtext) 字段应出现在网站上 当 False 字段消失时我编写了代码但不起作用请帮我解决问题 py xml 文件

<odoo>
<template id="website_insert_customtext" inherit_id="website_sale.address">
    <xpath expr="//div[@id='div_phone']" position="after">


                        <!--hier is not working-->
            <figure t-foreach="product_template" t-as="o" t-if="o.checkbox_customtext == True"  class="snip1533">

                <div t-attf-class="form-group #{error.get('customtext') and 'has-error' or ''} col-md-6"
                     id="div_custom_text">
                    <label class="control-label" for="customtext">Custom Text ( Only For Tactical vest )</label>
                    <input name="customtext" class="form-control"
                           t-att-value="'customtext' in checkout and checkout['customtext']"/>
                </div>



            </figure>
    </xpath>
</template>

通过 .py 从 odoo 导入模型、字段

类 ProductTemplate(models.Model): _inherit = 'product.template'

checkbox_customtext = fields.Boolean('Add Custom field', default=True, )

类 ResPartner(models.Model): _inherit = 'sale.order'

customtext = fields.Char('Custom Text')

标签: odooodoo-10

解决方案


您可以在不使用模板的情况下做到这一点。只需添加到 xml attrs="{'invisible': #your_domain}" 中的自定义文本字段,它就可以完成这项工作。

<field name="customtext" attrs="{'invisible':[('checkbox_customtext', '=', False)]}"/>


推荐阅读