在odoo10中为状态栏添加颜色

Add colurs to statusbar in odoo10

需要在odoo10可用的openerp版本中在状态栏中添加颜色 例如:<field name = 'state' widget=statusbar clickabe= 'True' statubar_colors='{"new": "blue"}'>

如何在odoo10的状态栏中添加颜色

状态栏中的不同状态需要不同的颜色 例如:蓝色代表草稿,绿色代表进度,红色代表取消

这个功能很久以前就从 Odoo 中删除了。

https://github.com/odoo/odoo/issues/5987

https://github.com/odoo/odoo/pull/11199

如果您需要添加此功能,则必须为其创建一个新的小部件。

有两种解决方案可以满足您的要求:

  1. 如果只有一个表单视图需要这种行为,很简单:

只需添加 style 标签即可击败 Odoo

生成的 css selector
        <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 selector 因为它是在 Odoo selector 之后加载的,它是使用的那个,请注意我的状态裸按钮有 .disabled class 因为它是 readonly 我认为你必须改变 clickabe= 'True' 意味着它不是只读的。

  1. 如果你想在这里为你的所有模型使用它,你需要使用 css file 并将其添加到 assets_backend 模板,确保你的 selector beat Odoo select或.
   <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>

现在我不知道你想怎么改变颜色在这里,你需要处理 CSS 到 select 正确的元素 , 例如,如果你想让状态栏颜色 blue 仅当 "new" 值为 selected 时,幸运的是你 Odoo 显示属性 data-value 中的值 selected 不会因翻译而改变。

   .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;
    }

这是在 Odoo 11 中,当我检查元素时,这是我注意到的:

  • 状态是 selected 有 class btn-primary 其余的有 btn-default
  • 只读属性 disabled="disabled" 和 class disabled

只是为了展示这项工作这是我所拥有的屏幕截图,你可能会有一些副作用,当你在 popup 中打开一些 record 和这个 form 仍然显示在网页中,如果它有 statuswidget,这也会影响显示的记录,因为 style tag 将被 删除form 视图从网页中删除

编辑:

假设您的 selection 有两个值:新的、有效的

如果 selected 并且对绿色 fi selected

这将是新的蓝色
<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" .....>

这一切都是关于 select 由 data-value 在该领域进行的,希望你明白了。这比处理 javascript.

更容易
 inherit_id="web.assets_backend"

根据需要添加样式,您也可以在 css

中添加样式