odoo - 在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')
解决方案
您可以在不使用模板的情况下做到这一点。只需添加到 xml attrs="{'invisible': #your_domain}" 中的自定义文本字段,它就可以完成这项工作。
<field name="customtext" attrs="{'invisible':[('checkbox_customtext', '=', False)]}"/>
推荐阅读
- vue.js - 在另一个 GET 请求中访问响应
- css - Atom 编辑器中的平滑插入符号动画
- javascript - document.querySelector('.header--input').value vs e.target.value
- xamarin.mac - xamarin.mac 添加 netstandard 库但构建错误
- perl - 如何让 ansible playbook 为我的 perlscript.pl 输入,其中包含
? - c# - 使用自定义数据库表在 asp.net core 2.2 中实现社交登录而不使用身份
- python-3.x - 具有多个依赖项的 tox.ini 环境
- java - 如何解决这个 NullPointerException 问题?
- python - 具有相对频率或密度曲线的计数图
- google-app-engine - 为什么 gcloud components update 命令总是显示重启命令