在odoo的产品页面上添加复选框字段

时间:2019-10-04 10:21:37

标签: odoo odoo-10

我在产品页面上添加了一个复选框 如果(checkbox_customtext)字段为TRUE,则(customtext)字段应显示在网站上 假字段何时消失 我写了代码但是没用 请帮我解决问题 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导入模型,字段

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

1 个答案:

答案 0 :(得分:0)

您可以在不使用模板的情况下进行操作。只需将其添加到xml attrs =“ {'invisible':#your_domain}”中的customtext字段中,即可完成工作。

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