summaryrefslogtreecommitdiff
path: root/addons/sale_timesheet/static/src/js/sale_project_kanban_controller.js
blob: 2c252c6f95e163e48b066292ea10b47c362a6b3f (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
odoo.define('sale_timesheet.sale_project_kanban_controller', function (require) {
"use strict";

var core = require('web.core');
var ProjectKanbanController = require('project.project_kanban');
var session = require('web.session');

var QWeb = core.qweb;

// YTI TODO : Master remove file

var SaleProjectKanbanController = ProjectKanbanController.include({

    //--------------------------------------------------------------------------
    // Private
    //--------------------------------------------------------------------------

    _showCreateSOButton: async function () {
        var self = this;
        this.activeProjectIds = this.initialState.context.active_ids;

        if (!this.activeProjectIds || this.activeProjectIds.length !== 1) {
            this.showCreateSaleOrder = false;
            return;
        }
        var canCreateSO = await session.user_has_group('sales_team.group_sale_salesman');
        if (canCreateSO) {
            await this._rpc({
                model: 'project.project',
                method: 'search_count',
                args: [[
                    ["id", "in", this.activeProjectIds],
                    ["bill_type", "=", "customer_project"],
                    ["sale_order_id", "=", false],
                    ["allow_billable", "=", true],
                    ["allow_timesheets", "=", true],
                ]],
            }).then(function (projectCount) {
                self.showCreateSaleOrder = projectCount !== 0;
            });
        } else {
            this.showCreateSaleOrder = false;
        }
    },

    //--------------------------------------------------------------------------
    // Handlers
    //--------------------------------------------------------------------------

    /**
     * @private
     * @param {MouseEvent} ev
     */
    _onCreateSaleOrder: function (ev) {
        ev.preventDefault();
        this.do_action('sale_timesheet.project_project_action_multi_create_sale_order', {
            additional_context: {
                'active_id': this.activeProjectIds && this.activeProjectIds[0],
                'active_model': "project.project",
            },
            on_close: async () => await this.reload()
        });
    },
});

return SaleProjectKanbanController;

});