Skip to content
Extraits de code Groupes Projets
Valider 71aadd15 rédigé par Benjamin's avatar Benjamin
Parcourir les fichiers

add graph tresorerie

parent ce4a2ec2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -22,6 +22,6 @@ ...@@ -22,6 +22,6 @@
'data/ir_module_category.xml' 'data/ir_module_category.xml'
], ],
'qweb': [ 'qweb': [
'static/src/xml/lefilament_tdb.xml', 'static/src/xml/*.xml',
], ],
} }
...@@ -179,5 +179,16 @@ class LeFilamentTdb(models.Model): ...@@ -179,5 +179,16 @@ class LeFilamentTdb(models.Model):
return res return res
@api.model
def tresorerie(self):
self._cr.execute("""SELECT to_char(date_trunc('month', date),'YYYY-MM') as mois,
sum(case when amount > 0 then amount else 0 end ) as entree,
sum(case when amount < 0 then amount else 0 end ) as sortie,
sum(amount) as variation
from account_bank_statement_line
group by date_trunc('month', date)
order by date_trunc('month', date);""")
tresorerie = self._cr.dictfetchall()
return tresorerie
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
/*.section-data th { background-color: #F0F0F0; } /*.section-data th { background-color: #F0F0F0; }
.table > tbody > tr.section-data > td, .table > tbody > tr.section-data th { border-top: 1px solid #000 !important; }*/ .table > tbody > tr.section-data > td, .table > tbody > tr.section-data th { border-top: 1px solid #000 !important; }*/
.yeardashboard { background-color: #F7F7F7; padding: 20px; min-height: 100%; } .yeardashboard { padding: 20px; min-height: 100%; }
.yeardashboard h3 { margin: 10px 15px; font-size: 20px; font-weight: 400; border-bottom: 1px solid #ddd; color: #5E6975; } .yeardashboard h3 { margin: 10px 15px; font-size: 20px; font-weight: 400; border-bottom: 1px solid #ddd; color: #5E6975; }
.card { background-color: #fff; color: #73879C; padding: 20px; margin: 10px 0; } .card { background-color: #fff; color: #73879C; padding: 20px; margin: 10px 0; }
.card a { color: inherit; } .card a { color: inherit; }
......
odoo.define('lefilament_tdb.tresorerie', function (require) {
"use strict";
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 TresorerieView = Widget.extend({
template: 'Tresorerie',
init: function() {
var result = this._super.apply(this, arguments);
return result;
},
willStart: function() {
var deferred = new jQuery.Deferred();
var self = this;
this.values = {};
var dash_model = new Model('lefilament.dashboard');
dash_model.call('tresorerie')
.then(function(results) {
self.values = results;
deferred.resolve();
});
return jQuery.when(this._super.apply(this, arguments),deferred);
},
start: function() {
return this.render_chart();
},
render_chart: function(chart) {
self = this;
/////////////////////////////////////////
// Trésorerie -> Bar Chart //
/////////////////////////////////////////
this.ctx = this.$el.find('#tresorerie')[0].getContext('2d');
var entree = [];
var sortie = [];
var variation = [];
var treso = [];
var labels = [];
var tabLength = this.values.length - 1;
_.each(this.values, function(value, key) {
if (key == 0 ) {
treso.push(value.variation);
} else {
var amount = treso[key-1] + value.variation;
treso.push(amount);
}
});
for (var i = (tabLength-11); i < tabLength+1 ; i++) {
entree.push(this.values[i].entree);
sortie.push(this.values[i].sortie * (-1) );
variation.push(this.values[i].variation);
labels.push(this.values[i].mois);
}
console.log(treso.slice(tabLength-11, tabLength+1));
var datasets = [
{ label: 'Trésorerie', data: treso.slice(tabLength-11, tabLength+1), backgroundColor: 'transparent',borderColor: '#5E8ED5' },
{ label: 'Variation', data: variation, backgroundColor: 'rgba(255, 197, 98, 0.3)',borderColor: '#FFC562' },
{ label: 'Entrées', data: entree, backgroundColor: 'rgba(81, 210, 183, 0.3)', borderColor: '#51d2b7' },
{ label: 'Sorties', data: sortie, backgroundColor: 'rgba(249, 96, 117, 0.3)', borderColor: '#F96075' },
];
// var label = 'Année ' + moment(Date.now()).format('YYYY');
this.targetData = {
labels : labels,
datasets : datasets
};
// 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',
// callbacks: {
// label: function(tooltipItems, data) {
// return (tooltipItems.xLabel * self.target / 100000).toLocaleString('fr', { maximumFractionDigits: 2 }) + ' K€';
// }
// }
// },
// responsive: true,
// }
var myLineChart = new Chart(this.ctx, { type: 'line', data: this.targetData, } );
},
render_monetary: function(value) {
value = value.toLocaleString('fr', { maximumFractionDigits: 0 }) + '';
return value;
},
render_keur: function(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;
},
render_monetary_color: function(value) {
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 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','=','out_invoice']],
target:'current',
name: 'Factures en cours',
context: context
})
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
})
this.do_action(action);
},
});
core.action_registry.add('lefilament_tdb.tresorerie', TresorerieView);
});
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="Tresorerie">
<div class="card">
<p class="card-number">
Trésorerie sur 12 mois
</p>
<hr/>
<canvas id="tresorerie" width="auto" height="100"></canvas>
</div>
</t>
</templates>
\ No newline at end of file
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<script type="text/javascript" src="/lefilament_tdb/static/src/lib/tableexport.js"></script> <script type="text/javascript" src="/lefilament_tdb/static/src/lib/tableexport.js"></script>
<script type="text/javascript" src="/lefilament_tdb/static/src/js/lefilament_tdb.js"></script> <script type="text/javascript" src="/lefilament_tdb/static/src/js/lefilament_tdb.js"></script>
<script type="text/javascript" src="/lefilament_tdb/static/src/js/dashboard_year.js"></script> <script type="text/javascript" src="/lefilament_tdb/static/src/js/dashboard_year.js"></script>
<script type="text/javascript" src="/lefilament_tdb/static/src/js/tresorerie.js"></script>
</xpath> </xpath>
</template> </template>
......
...@@ -21,11 +21,18 @@ ...@@ -21,11 +21,18 @@
<field name="tag">lefilament_tdb.dashboard_year</field> <field name="tag">lefilament_tdb.dashboard_year</field>
</record> </record>
<record id="action_tresorerie" model="ir.actions.client">
<field name="name">Trésorerie</field>
<field name="tag">lefilament_tdb.tresorerie</field>
<field name="target">new</field>
</record>
<menuitem id="lefilament_dashboard_menu" name="Dashboard" sequence="10" groups="group_dashboard"/> <menuitem id="lefilament_dashboard_menu" name="Dashboard" sequence="10" groups="group_dashboard"/>
<menuitem id="lefilament_dashboard_report" parent="lefilament_dashboard_menu" name="Rapports" sequence="1"/> <menuitem id="lefilament_dashboard_report" parent="lefilament_dashboard_menu" name="Rapports" sequence="1"/>
<menuitem id="lefilament_dashboard_report_month" parent="lefilament_dashboard_report" name="Mensuel" sequence="2" action="action_home_page"/> <menuitem id="lefilament_dashboard_report_month" parent="lefilament_dashboard_report" name="Mensuel" sequence="2" action="action_home_page"/>
<menuitem id="lefilament_dashboard_report_year" parent="lefilament_dashboard_report" name="Annuel" sequence="1" action="action_year_page" /> <menuitem id="lefilament_dashboard_report_year" parent="lefilament_dashboard_report" name="Annuel" sequence="1" action="action_year_page" />
<menuitem id="lefilament_tresorerie" parent="lefilament_dashboard_report" name="Trésorerie" sequence="3" action="action_tresorerie" />
<menuitem id="lefilament_dashboard_conf" parent="lefilament_dashboard_menu" name="Configuration" sequence="10"/> <menuitem id="lefilament_dashboard_conf" parent="lefilament_dashboard_menu" name="Configuration" sequence="10"/>
<menuitem id="lefilament_dashboard_datas" parent="lefilament_dashboard_conf" name="Données" action="lefilament_dashboard_action" sequence="10"/> <menuitem id="lefilament_dashboard_datas" parent="lefilament_dashboard_conf" name="Données" action="lefilament_dashboard_action" sequence="10"/>
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter