Newer
Older
// © 2017 Le Filament (<http://www.le-filament.com>)
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
odoo.define('lefilament_tdb.dashboard_year', function (require) {
var core = require('web.core');
var formats = require('web.formats');
var Model = require('web.Model');
var session = require('web.session');
var Widget = require('web.Widget');
var QWeb = core.qweb;
var _t = core._t;
var _lt = core._lt;
var YearDashboardView = Widget.extend({
template: 'YearDashboard',

Benjamin
a validé
events: {
'click #facture_non_encaisse': function() {
this.facture_non_encaisse();
},
'click #commandes': function() {
this.commandes();
},
'click #pipe_link': function() {
this.pipe();
},
'click #pipe_n1_link': function() {
this.pipe_n1();
},
'click #fournisseur_link': function() {
this.fournisseur();
},
'click #releve': function() {
this.releve();
},

Benjamin
a validé
},
init: function() {
var result = this._super.apply(this, arguments);
return result;
},
willStart: function() {
var deferred = new jQuery.Deferred();
var self = this;
this.values = {};
this.progess = 0;
var dash_model = new Model('lefilament.dashboard');
dash_model.call('retrieve_datas_dashboard')
.then(function(results) {
self.values = results;
self.pfact = (self.values.facture / self.values.target * 100).toFixed(0);
self.pcomm = (self.values.commandes / self.values.target * 100).toFixed(0);
self.ppipe_win = (self.values.pipe_win / self.values.target * 100).toFixed(0);
self.ppipe_to_win = (self.values.pipe_to_win / self.values.target * 100).toFixed(0);
self.ptarg = 100-self.pfact-self.pcomm-self.ppipe_win-self.ppipe_to_win;
self.pfact2 = (self.values.facture);
self.pcomm2 = (self.values.commandes);
self.ppipe2_win = (self.values.pipe_win);
self.ppipe2_to_win = (self.values.pipe_to_win);
self.ptarg2 = self.values.target -self.pfact2-self.pcomm2-self.ppipe2_to_win-self.ppipe2_win;
self.total = ((self.values.facture + self.values.commandes + self.values.pipe_win) / self.values.target * 100).toFixed(0);
self.total2 = self.pfact2 + self.pcomm2 + self.ppipe2_win
self.target = self.values.target
deferred.resolve();
});
return jQuery.when(this._super.apply(this, arguments),deferred);
},
start: function() {
/////////////////////////////////////////
// Etat d'avancement -> Bar Chart //
/////////////////////////////////////////
this.ctx = this.$el.find('#target')[0].getContext('2d');
var dataset_stacked = [
{ label: 'Facturé', data: [this.pfact], backgroundColor: '#8ED8A2', },
{ label: 'Commandes', data: [this.pcomm], backgroundColor: '#F6DCA2', },
{ label: 'Gagné', data: [this.ppipe_win], backgroundColor: '#F6CCA2', },
{ label: 'Pipe', data: [this.ppipe_to_win], backgroundColor: '#F6ACA2', },
{ label: 'To Do', data: [this.ptarg], backgroundColor: '#eee', }];
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
var label = 'Année ' + moment(Date.now()).format('YYYY');
this.targetData = {
labels : [label],
datasets : dataset_stacked
};
var options = {
legend: {
display: false,
},
layout: {
padding: { left:0, right: 0, bottom: 20, top: 20, },
},
scales: {
xAxes: [{
stacked: true,
scaleShowLabels: false,
display : false ,
}],
yAxes: [{
stacked: true,
scaleShowLabels: false,
display : false ,
}]
},
tooltips: {
backgroundColor: 'rgba(255,255,255,0.8)',
titleFontStyle: 'normal',
titleFontColor: '#999',
bodyFontColor: '#777',
return (tooltipItems.xLabel * self.target / 100000).toLocaleString('fr', { maximumFractionDigits: 2 }) + ' K€';
},
responsive: true,
}
var myLineChart = new Chart(this.ctx, { type: 'horizontalBar', data: this.targetData, options } );
},
render_monetary: function(value) {
value = value.toLocaleString('fr', { maximumFractionDigits: 0 }) + ' €';
return value;
},
value = (value/ 1000).toLocaleString('fr', { maximumFractionDigits: 0 }) + ' K€';
return value;
},
render_percent: function(value) {
value = value.toLocaleString('fr', { maximumFractionDigits: 1 }) + ' %';
return value;
},
render_date: function(value) {
var dateFormat = new Date(value);
var new_value = moment(dateFormat).format('Do MMM YYYY');
return new_value;
},

Benjamin
a validé
if (value >= 0)
value = '<span class="positive">'+value.toLocaleString('fr', { maximumFractionDigits: 0 }) + ' €</span>';
else
value = '<span class="negative">'+value.toLocaleString('fr', { maximumFractionDigits: 0 }) + ' €</span>';
return value;
},
facture: function() {
var self = this;
var date = moment().startOf('year').format('YYYY-MM-DD');
console.log(date);
var context = { 'user_id': this.session.uid, }
var action = ({
type: 'ir.actions.act_window',
res_model: 'account.invoice',
view_type: 'form',
view_mode: 'tree,form',
views: [[false, 'list'], [false, 'form']],
domain: [['state','in',['open','paid']],['type','=','out_invoice'],['date_invoice','>=',date]],
this.do_action(action);
},
commandes: function() {
var self = this;
var context = { 'user_id': this.session.uid, }
var action = ({
type: 'ir.actions.act_window',
res_model: 'sale.order',
view_type: 'form',
view_mode: 'tree,form',
views: [[false, 'list'], [false, 'form']],
domain: [['invoice_status','=','to invoice']],
target:'current',
name: 'Commandes en cours',
context: context
})
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
this.do_action(action);
},
pipe: function() {
var self = this;
var deadline = moment().endOf('year').format('YYYY-MM-DD');
var context = { 'user_id': this.session.uid, }
var action = ({
type: 'ir.actions.act_window',
res_model: 'crm.lead',
view_type: 'form',
view_mode: 'tree,form',
views: [[false, 'kanban'], [false, 'list'], [326, 'form']],
domain: [['type','=','opportunity'],['date_deadline','<=', deadline]],
target:'current',
name: 'Pipe',
context: context
})
this.do_action(action);
},
pipe_n1: function() {
var self = this;
var deadline = moment().endOf('year').format('YYYY-MM-DD');
var context = { 'user_id': this.session.uid, }
var action = ({
type: 'ir.actions.act_window',
res_model: 'crm.lead',
view_type: 'form',
view_mode: 'kanban,tree,form',
views: [[false, 'kanban'], [false, 'list'], [326, 'form']],
domain: [['type','=','opportunity'],['date_deadline','>', deadline]],
target:'current',
name: 'Pipe',
context: context
})
this.do_action(action);
},
facture_non_encaisse: function() {
var self = this;
var context = { 'user_id': this.session.uid, }
var action = ({
type: 'ir.actions.act_window',
res_model: 'account.invoice',
view_type: 'form',
view_mode: 'kanban,tree,form',
views: [[false, 'list'], [false, 'form']],
domain: [['state','=','open'],['type','=','out_invoice']],
target:'current',
name: 'Factures en cours',
context: context
})
this.do_action(action);
},
fournisseur: function() {
var self = this;
var context = { 'user_id': this.session.uid, }
var action = ({
type: 'ir.actions.act_window',
res_model: 'account.invoice',
view_type: 'form',
view_mode: 'tree,form',
views: [[false, 'list'], [false, 'form']],
domain: [['state','=','open'],['type','=','in_invoice']],
target:'current',
name: 'Factures fournisseurs en cours',
context: context
})
this.do_action(action);
},
releve: function() {
var self = this;
var context = { 'user_id': this.session.uid, }
var action = ({
type: 'ir.actions.act_window',
res_model: 'account.bank.statement',
view_type: 'form',
view_mode: 'tree,form',
views: [[false, 'list'], [false, 'form']],
// domain: [['state','=','open'],['type','=','in_invoice']],
target:'current',
name: 'Relevés en cours',
context: context
})

Benjamin
a validé
},