Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

tree 加widget=‘kanban_state_selection’



  • 1、如下图,form视图中status字段添加widget=‘kanban_state_selection’,显示的颜色是一样的,如何不同status可以自定义颜色。
    2、怎么在tree视图也可以有同样的效果?加widget没效果。

    0_1527738817007_color.png



  • @hui
    1、这个widgetodoo10的时候还是只是在project模块中自定义的一个widget,而且只是在form,kanban视图中有效果,list视图没有效果的。
    2、这个widget不能通用的,odoo11好像可以通用了。

    我抄写官方的代码,在我需要的模块自定义了一个status_selectionwidget,测试效果可以。主要的js代码如下:

    代码中50-59行代码,就是根据自定义的selectionkey进行颜色的定义。

    这个不是很懂,也不知道哪些是多余的,还有就是这个template用原来的好像不行,复制了一份的。😜

    odoo.define('sps_project.include_form_widget', function (require) {
        'use strict';
    
    var ajax = require('web.ajax');
    var core = require('web.core');
    var crash_manager = require('web.crash_manager');
    var data = require('web.data');
    var datepicker = require('web.datepicker');
    var dom_utils = require('web.dom_utils');
    var Priority = require('web.Priority');
    var ProgressBar = require('web.ProgressBar');
    var Dialog = require('web.Dialog');
    var common = require('web.form_common');
    var formats = require('web.formats');
    var framework = require('web.framework');
    var Model = require('web.DataModel');
    var pyeval = require('web.pyeval');
    var session = require('web.session');
    var utils = require('web.utils');
    
    var _t = core._t;
    var QWeb = core.qweb;
    
    var StatusSelection = common.AbstractField.extend({
        template: "FormSelection",
        events: {
            'click a': function(e) {
                e.preventDefault();
            },
            'mouseup a': function(e) {
                e.stopPropagation();
            },
            'click li': 'set_kanban_selection'
        },
        start: function () {
            // hook on form view content changed: recompute the states, because it may be related to the current stage
            this.view.on('view_content_has_changed', this, function () {
                this.render_value();
            });
            return this._super();
        },
        prepare_dropdown_selection: function() {
            var self = this;
            var _data = [];
            _.map(self.field.selection || [], function(selection_item) {
                var value = {
                    'name': selection_item[0],
                    'tooltip': selection_item[1],
                };
                if (selection_item[0] === 'initial') {
                    value.state_class = 'oe_kanban_status_grey';
                    value.state_name = selection_item[1];
                } else if (selection_item[0] === '1st review') {
                    value.state_class = 'oe_kanban_status_green';
                    value.state_name = selection_item[1];
                } else {
                    value.state_class = 'oe_kanban_status_red';
                    value.state_name = selection_item[1];
                }
                _data.push(value);
            });
            return _data;
        },
        render_value: function() {
            this._super();
            this.states = this.prepare_dropdown_selection();
            var self = this;
    
            // Adapt "FormSelection"
            var current_state = _.find(this.states, function(state) {
                return state.name === self.get('value');
            });
            this.$('.oe_kanban_status')
                .removeClass('oe_kanban_status_red oe_kanban_status_green')
                .addClass(current_state.state_class);
    
            // Render "FormSelection.Items" and move it into "FormSelection"
            var $items = $(QWeb.render('FormSelection.items', {
                states: _.without(this.states, current_state)
            }));
            var $dropdown = this.$el.find('.dropdown-menu');
            $dropdown.children().remove(); // remove old items
            $items.appendTo($dropdown);
        },
        /* setting the value: in view mode, perform an asynchronous call and reload
        the form view; in edit mode, use set_value to save the new value that will
        be written when saving the record. */
        set_kanban_selection: function (ev) {
            var self = this;
            ev.preventDefault();
            var li = $(ev.target).closest('li');
            if (li.length) {
                var value = String(li.data('value'));
                if (this.view.get('actual_mode') === 'view') {
                    var write_values = {};
                    write_values[self.name] = value;
                    return this.view.dataset._model.call(
                        'write', [
                            [this.view.datarecord.id],
                            write_values,
                            self.view.dataset.get_context()
                        ]).done(self.reload_record.bind(self));
                }
                else {
                    return this.set_value(value);
                }
            }
        },
        reload_record: function() {
            this.view.reload();
        },
    
    
    });
    core.form_widget_registry.add('status_selection', StatusSelection);
    
    return {
        StatusSelection: StatusSelection,
        };
    });
    
    
    

Log in to reply