summaryrefslogtreecommitdiff
path: root/addons/crm/static/src/js/crm_kanban.js
blob: dbc50064c7a9ffa6b99c9baeea0b1ad3824a73f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
odoo.define('crm.crm_kanban', function (require) {
    "use strict";

    /**
     * This Kanban Model make sure we display a rainbowman
     * message when a lead is won after we moved it in the
     * correct column and when it's grouped by stage_id (default).
     */

    var KanbanModel = require('web.KanbanModel');
    var KanbanView = require('web.KanbanView');
    var viewRegistry = require('web.view_registry');

    var CrmKanbanModel = KanbanModel.extend({
        /**
         * Check if the kanban view is grouped by "stage_id" before checking if the lead is won
         * and displaying a possible rainbowman message.
         * @override
         */
        moveRecord: async function (recordID, groupID, parentID) {
            var result = await this._super(...arguments);
            if (this.localData[parentID].groupedBy[0] === this.defaultGroupedBy[0]) {
                const message = await this._rpc({
                    model: 'crm.lead',
                    method : 'get_rainbowman_message',
                    args: [[parseInt(this.localData[recordID].res_id)]],
                });
                if (message) {
                    this.trigger_up('show_effect', {
                        message: message,
                        type: 'rainbow_man',
                    });
                }
            }
            return result;
        },
    });

    var CrmKanbanView = KanbanView.extend({
        config: _.extend({}, KanbanView.prototype.config, {
            Model: CrmKanbanModel,
        }),
    });

    viewRegistry.add('crm_kanban', CrmKanbanView);

    return {
        CrmKanbanModel: CrmKanbanModel,
        CrmKanbanView: CrmKanbanView,
    };

});