Sélectionner une révision Git
dashboard_year.js 15,30 Kio
// © 2019 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) {
"use strict";
var core = require("web.core");
var session = require("web.session");
var AbstractAction = require("web.AbstractAction");
var YearDashboardView = AbstractAction.extend({
template: "YearDashboard",
jsLibs: ["/web/static/lib/Chart/Chart.js"],
events: {
"click #facture": function (e) {
var fiscalyear = e.target.dataset.fiscalyear;
this.facture(fiscalyear);
},
"click #facture_non_encaisse": function () {
this.facture_non_encaisse();
},
"click #commandes": function () {
this.commandes();
},
"click #pipe_link": function (e) {
var fiscalyearnext = e.target.dataset.fiscalyearnext;
this.pipe(fiscalyearnext);
},
"click #pipe_n1_link": function (e) {
var fiscalyearnext = e.target.dataset.fiscalyearnext;
this.pipe_n1(fiscalyearnext);
},
"click #fournisseur_link": function () {
this.fournisseur();
},
"click #releve": function () {
this.releve();
},
"click #statement_lines": function () {
this.statement_lines();
},
},
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;
this._rpc({
model: "ir.model.data",
method: "xmlid_to_res_id",
args: ["account.view_invoice_form"],
}).then(function (results) {
self.invoice_view_id = results;
});
this._rpc({
model: "ir.model.data",
method: "xmlid_to_res_id",
args: ["lefilament_tdb.view_invoice_tree"],
}).then(function (results) {
self.invoice_tree_id = results;
});
this._rpc({
model: "ir.model.data",
method: "xmlid_to_res_id",
args: ["crm.crm_case_form_view_oppor"],
}).then(function (results) {
self.pipe_view_id = results;
});
this._rpc({
model: "lefilament.dashboard",
method: "retrieve_datas_dashboard",
args: [],
}).then(function (results) {
self.values = results;
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;
if (self.values.target > 0) {
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.ptarg2 =
self.values.target -
self.pfact2;
self.total = (
((self.values.facture +
self.values.commandes +
self.values.pipe_win) /
self.values.target) *
100
).toFixed(0);
} else {
self.pfact = "n/a";
self.pcomm = "n/a";
self.ppipe_win = "n/a";
self.ppipe_to_win = "n/a";
self.ptarg = "n/a";
self.ptarg2 = "n/a";
self.total = "n/a";
}
self.total2 = self.pfact2 + self.pcomm2 + self.ppipe2_win;
self.yeartarget = self.values.target;
deferred.resolve();
});
return jQuery.when(this._super.apply(this, arguments), deferred);
},
start: function () {
return this.render_chart();
},
render_chart: function () {
// ///////////////////////////////////////
// Etat d'avancement -> Bar Chart //
// ///////////////////////////////////////
this.ctx = this.$el.find("#target")[0].getContext("2d");
var yeartarget = this.yeartarget
var ptarg = this.ptarg;
var max_xaxis = 100;
if (this.ptarg < 0) {
ptarg = 0;
max_xaxis = 100 - this.ptarg;
}
var dataset_stacked = [
{label: "Facturé", data: [this.pfact], backgroundColor: "#8ED8A2"},
{label: "À facturer", data: [ptarg], backgroundColor: "#eee"},
];
var label = "Année " + moment(Date.now()).format("YYYY");
this.targetData = {
labels: [label],
datasets: dataset_stacked,
};
var options = {
responsive: true,
legend: {
display: false,
},
layout: {
padding: {left: 0, right: 0, bottom: 20, top: 20},
},
scales: {
xAxes: [
{
stacked: true,
scaleShowLabels: false,
display: true,
ticks: {
max: max_xaxis,
stepSize: 25,
fontSize: 9,
fontColor: "#999",
callback: function (value) {
return value + "%";
},
},
gridLines: {
zeroLineColor: "rgba(0, 0, 0, 0.1)",
drawBorder: false,
tickMarkLength: 2,
},
},
],
yAxes: [
{
stacked: true,
scaleShowLabels: false,
display: false,
},
],
},
tooltips: {
backgroundColor: "rgba(255,255,255,0.8)",
titleFontStyle: "normal",
titleFontColor: "#999",
bodyFontColor: "#777",
callbacks: {
label: function (tooltipItems, data) {
return (
(
(tooltipItems.xLabel * yeartarget) /
100000
).toLocaleString("fr", {maximumFractionDigits: 2}) +
" K€"
);
},
},
},
};
this.chart = new Chart(this.ctx, {
type: "horizontalBar",
data: this.targetData,
options,
});
},
render_monetary: function (value) {
var res = value.toLocaleString("fr", {maximumFractionDigits: 0}) + " €";
return res;
},
render_keur: function (value) {
var res =
(value / 1000).toLocaleString("fr", {maximumFractionDigits: 0}) + " K€";
return res;
},
render_percent: function (value) {
var res = value.toLocaleString("fr", {maximumFractionDigits: 1}) + " %";
return res;
},
render_date: function (value) {
var dateFormat = new Date(value);
var res = moment(dateFormat).format("Do MMM YYYY");
return res;
},
render_monetary_color: function (value) {
if (value >= 0)
var res =
'<span class="positive">' +
value.toLocaleString("fr", {maximumFractionDigits: 0}) +
" €</span>";
else
var res =
'<span class="negative">' +
value.toLocaleString("fr", {maximumFractionDigits: 0}) +
" €</span>";
return res;
},
facture: function (fiscalyear) {
var self = this;
var context = {
user_id: session.uid,
search_default_posted: 1,
};
console.log(self.invoice_tree_id)
console.log(self.invoice_view_id)
var action = {
type: "ir.actions.act_window",
res_model: "account.move",
view_mode: "tree,pivot,graph,form",
views: [
[self.invoice_tree_id, "list"],
[false, "pivot"],
[false, "graph"],
[self.invoice_view_id, "form"],
],
domain: [
["move_type", "in", ["out_invoice", "out_refund"]],
["invoice_date", ">=", fiscalyear],
],
target: "current",
name: "Facturé",
context: context,
};
console.log(action)
this.do_action(action);
},
commandes: function () {
var context = {user_id: session.uid};
var action = {
type: "ir.actions.act_window",
res_model: "sale.order",
view_mode: "tree,form",
views: [
[false, "list"],
[false, "form"],
],
domain: [["invoice_status", "=", "to invoice"]],
target: "current",
name: "Commandes en cours",
context: context,
};
this.do_action(action);
},
pipe: function (fiscalyearnext) {
var context = {user_id: session.uid};
var action = {
type: "ir.actions.act_window",
res_model: "crm.lead",
view_mode: "tree,form",
views: [
[false, "kanban"],
[false, "list"],
[this.pipe_view_id, "form"],
],
domain: [
"|",
["date_deadline", "<=", fiscalyearnext],
["date_deadline", "=", null],
["type", "=", "opportunity"],
],
target: "current",
name: "Pipe",
context: context,
};
this.do_action(action);
},
pipe_n1: function (fiscalyearnext) {
var context = {user_id: session.uid};
var action = {
type: "ir.actions.act_window",
res_model: "crm.lead",
view_mode: "kanban,tree,form",
views: [
[false, "kanban"],
[false, "list"],
[this.pipe_view_id, "form"],
],
domain: [
["type", "=", "opportunity"],
["date_deadline", ">", fiscalyearnext],
],
target: "current",
name: "Pipe",
context: context,
};
this.do_action(action);
},
facture_non_encaisse: function () {
var context = {user_id: session.uid};
var action = {
type: "ir.actions.act_window",
res_model: "account.move",
view_mode: "tree,form",
views: [
[self.invoice_tree_id, "list"],
[false, "pivot"],
[false, "graph"],
[self.invoice_view_id, "form"],
],
domain: [
["state", "=", "posted"],
["payment_state", "in", ["not_paid", "in_payment", "partial"]],
["move_type", "=", "out_invoice"],
],
target: "current",
name: "Factures en cours",
context: context,
};
this.do_action(action);
},
fournisseur: function () {
var context = {user_id: session.uid};
var action = {
type: "ir.actions.act_window",
res_model: "account.move",
view_mode: "tree,form",
views: [
[false, "list"],
[false, "form"],
],
domain: [
["state", "=", "posted"],
["payment_state", "in", ["not_paid", "in_payment", "partial"]],
["move_type", "=", "in_invoice"],
],
target: "current",
name: "Factures fournisseurs en cours",
context: context,
};
this.do_action(action);
},
releve: function () {
var context = {user_id: session.uid};
var action = {
type: "ir.actions.act_window",
res_model: "account.bank.statement",
view_mode: "tree,form",
views: [
[false, "list"],
[false, "form"],
],
target: "current",
name: "Relevés en cours",
context: context,
};
this.do_action(action);
},
statement_lines: function () {
var context = {user_id: session.uid};
var action = {
type: "ir.actions.act_window",
res_model: "account.bank.statement.line",
view_mode: "tree,pivot,graph,form",
views: [
[false, "list"],
[false, "pivot"],
[false, "graph"],
[false, "form"],
],
target: "current",
name: "Lignes de banque",
context: context,
};
this.do_action(action);
},
});
core.action_registry.add("lefilament_tdb.dashboard_year", YearDashboardView);
});