我正在使用odoo 10.我有一个客户视图,在该客户表单视图中,我还在one2many树视图中显示与该特定客户关联的所有订单(可编辑)。
我想要做的是我想在one2many树视图中显示一个按钮,但我只想根据条件更改该按钮的颜色。
这是我尝试过但不起作用。
<record id="amgl.customer_form" model="ir.ui.view">
<field name="name">Customer</field>
<field name="model">amgl.customer</field>
<field name="arch" type="xml">
<form string="Create New Customer" duplicate="0">
<sheet>
<group colspan="4">
<group>
<field name="is_admin" invisible="1"/>
<field name="is_custodian" invisible="1"/>
<field name="is_vault" invisible="1"/>
<field name="is_o2m" invisible="1"/>
<field name="is_goldstar" invisible="1"/>
<field name="custodian_edit" invisible="1"/>
<field name="first_name"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
<field name="last_name"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
<field name="account_number"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
<field name="gst_account_number" string="GoldStar Account Number"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)], 'invisible':[('is_goldstar','=',False)]}"/>
</group>
<group>
<field name="date_opened"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
<field name="account_type"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
<field name="custodian_id" options='{"no_open": True}'
attrs="{'readonly':[('is_admin','=', False)]}"/>
<field name="customer_notes"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
</group>
</group>
<notebook>
<!--CURRENT INVENTORY-->
<page string="CURRENT INVENTORY">
<field name="customer_order_lines2"
attrs="{'readonly':['|',('is_custodian','=', True),('is_o2m','=', False)]}"
context="{'default_is_deposit_related': True,'group_by':'products'}"
groups="amgl.group_amark_admins,amgl.group_amark_vault,amgl.group_amark_custodian,amgl.group_amark_sub_admins"
domain="[('state','=','completed')]" default_order='state desc'
widget="one2many_list">
<h4 style="float:right;">
<field name="total_received_quantity"/>
</h4>
<tree open="false" editable="bottom"
groups="amgl.group_amark_admins,amgl.group_amark_vault,amgl.group_amark_custodian,amgl.group_amark_sub_admins">
<field name="is_deposit_related" invisible="1"/>
<field name="is_vault_edit" invisible="1"/>
<field name="is_admin" invisible="1"/>
<field style="color:red !important;" name="products" attrs="{'readonly':[('is_vault_edit','=', True)]}"/>
<field name="commodity"/>
<field name="total_received_quantity"
attrs="{'readonly':[('is_vault_edit','=', True)]}" class="oe_edit_only"
col_border="1" string="Received"/>
<field name="temp_received_weight" class="oe_edit_only" col_border="1"/>
<field name="date_received" attrs="{'readonly':[('is_vault_edit','=', True)]}"
class="oe_edit_only" col_border="1"/>
<field name="state" invisible="1"/>
<field name="notes_boolean" invisible="1"/>
<button attrs="{'invisible':[('notes_boolean','=', False)]}" type="object" name="add_notes" class="btn btn-primary btn-sm o_list_button_add">
<i class="fa-lg fa-pencil-square"></i>
</button>
<button attrs="{'invisible':[('notes_boolean','=', True)]}" type="object" name="add_notes" class="btn btn-default">
<i class="fa-lg fa-pencil-square"></i>
</button>
<!--<button colors="red: notes_boolean is True" name="add_notes" type="object"-->
<!--string="Add Notes" icon="fa-lg fa-pencil-square" class="btn btn-primary btn-sm o_list_button_addhlight"/>-->
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
答案 0 :(得分:3)
您正在做的是使用attrs
无法更改按钮属性的正确解决方案
因此,您需要创建两个具有相同name
和label
的按钮,并显示或隐藏其中一个按钮
根据条件。
但是此代码无法在树上运行,因为Odoo不会占用您的class attribute
或style attribute
无论你在那里放置什么,如果你检查浏览器中的按钮元素,你会发现
两个按钮是相同的,类是相同的,你的类不存在,没有样式属性。
我不知道为什么Odoo开发者决定这样做。
我之前需要做的就是在css
中添加backend_assets
,在树中选择一个按钮
使用data-field attribute equal the name of the method
查看,因为该属性在翻译中不会更改。
/* make button color red in temporary exit tree view.*/
.openerp .oe_list_content [data-field='cancel_entry'] button{
background-color: red !important;
color: white !important;
}
您会注意到,树视图中的按钮只会更改此属性。 所以如果你想做这样的事情,你需要创建两个方法
@api.multi
def add_notes_red(self): # i added _red to make sure no one else will name he's method like this
pass
@api.multi
def add_notes_green(self):
return self.add_notes_red() # because it does the same thing just call the orignal method
并在您的自定义CSS文件中
/* make button color red.*/
.openerp .oe_list_content [data-field='add_notes_red'] button{
background-color: red !important;
color: white !important;
}
/* make button color green.*/
.openerp .oe_list_content [data-field='add_notes_green'] button{
background-color: green !important;
color: white !important;
}
注意:不要忘记在backend_assets模板中使用css文件。