如何在odoo10中添加状态栏的颜色,该功能也适用于openerp版本
例如:<field name='state' widget='statusbar' clickable='True' statusbar_colors='{"new": "blue"}'>
如何为odoo10中的状态栏添加颜色:
您需要为不同状态添加不同的颜色。例如:草稿状态为蓝色、进行中状态为绿色、取消状态为红色。
只需添加 style
标签即可覆盖 Odoo
生成的 css选择器
<style>
.o_form_view .o_form_statusbar > .o_statusbar_status > .o_arrow_button.btn-primary.disabled {
background: yellow;
}
.o_form_view .o_form_statusbar > .o_statusbar_status > .o_arrow_button.btn-primary.disabled::after {
border-left-color: yellow;
}
</style>
...
...
<field name ="state" widget="statusbar">
在这里,我使用了相同的css选择器
,因为它是在Odoo选择器
之后加载的,所以它是被使用的。请注意,我的状态栏按钮具有.disabled
类,因为它是只读
。我认为你需要改变那个clickabe='True'
,这意味着它不是只读的。
css文件
并将其添加到assets_backend模板中,确保您的选择器击败了Odoo选择器。 <template id="assets_backend" name="backend" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/your_addon_name/static/src/css/your_css_file_name.css"/>
</xpath>
</template>
.o_form_view .o_form_statusbar > .o_statusbar_status > .o_arrow_button.btn-primary.disabled[data-value="new"] {
background: blue;
}
.o_form_view .o_form_statusbar > .o_statusbar_status > .o_arrow_button.btn-primary.disabled[data-value="new"]::after {
border-left-color: blue;
}
btn-primary
,其余状态则具有btn-default
readonly
具有属性disabled="disabled"
和类disabled
popup
中打开一些record
并且这个form
仍然显示在网页中时,如果它有一个status
裸widget
,那么这也会影响到所显示的记录,因为当从网页中删除form
视图时,style tag
将被删除。
编辑:
假设你的选择有两个值:新的,有效的
如果选择了“新的”,则将其颜色变为蓝色;如果选择了“有效的”,则将其颜色变为绿色。
<style>
.o_form_view .o_form_statusbar > .o_statusbar_status > .o_arrow_button.btn-primary.disabled[data-value="new"] {
background: blue;
}
.o_form_view .o_form_statusbar > .o_statusbar_status > .o_arrow_button.btn-primary.disabled[data-value="new"]::after {
border-left-color: blue;
}
.o_form_view .o_form_statusbar > .o_statusbar_status > .o_arrow_button.btn-primary.disabled[data-value="progress"] {
background: blue;
}
.o_form_view .o_form_statusbar > .o_statusbar_status > .o_arrow_button.btn-primary.disabled[data-value="progress"]::after {
border-left-color: blue;
}
.o_form_view .o_form_statusbar > .o_statusbar_status > .o_arrow_button.btn-primary.disabled[data-value="cancel"] {
background: red;
}
.o_form_view .o_form_statusbar > .o_statusbar_status > .o_arrow_button.btn-primary.disabled[data-value="cancel"]::after {
border-left-color: red;
}
</style>
...
...
...
<field name="state" .....>
这完全是关于通过 data-value
选择字段。希望你明白了。这比处理JavaScript更容易。
这个功能很久以前就从Odoo中移除了。
https://github.com/odoo/odoo/issues/5987
https://github.com/odoo/odoo/pull/11199
如果您需要添加此功能,您将需要为其创建一个新的小部件。
inherit_id="web.assets_backend"
按需添加样式,您也可以在CSS中设置样式