Browse Source

First commit

deisy 5 years ago
commit
a5fe701917

+ 2 - 0
__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+import controllers

+ 23 - 0
__openerp__.py

@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+{
+    'name': "Widgets para el dashboard de Bienstar ",
+    'author': "Eiru",
+    'website': "https://www.eiru.com.py",
+    'category': 'Uncategorized',
+    'version': '2.0',
+    'depends': [
+        'base',
+        'account',
+        'sale',
+        'eiru_reports_dashboard',
+    ],
+    'data': [
+        'data/charts_data.xml',
+        'template.xml',
+    ],
+    'qweb': [
+        'static/src/xml/*.xml',
+        'static/src/xml/widgets/*.xml',
+
+    ]
+}

+ 1 - 0
controllers/__init__.py

@@ -0,0 +1 @@
+import main

+ 12 - 0
controllers/helpers/__init__.py

@@ -0,0 +1,12 @@
+# -*- coding: utf-8 -*-
+
+from company import get_company_info
+from ir_module_module import get_ir_module_widget
+from pos_order import get_pos_order_widget
+from pos_order import get_pos_order_widget_own
+from widget_list import get_widget_list
+from res_user import get_user_info
+from res_partner import get_res_partner
+from res_store import get_res_store_widget
+from account_invoice import get_account_invoice
+from account_move_line import get_account_move_line

+ 55 - 0
controllers/helpers/account_invoice.py

@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_account_invoice():
+    user_store = r.env.user.store_id.id
+    user_id = r.env.user.id
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+    query = '''
+        SELECT
+        	invoice.id,
+        	rate.currency_id,
+        	invoice.date_invoice,
+        	invoice.type,
+        	invoice.origin,
+        	invoice.partner_id,
+        	invoice.user_id,
+        	invoice.amount_total * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]) as invoice_rate,
+            invoice.number
+        FROM account_invoice AS invoice
+        LEFT JOIN res_store_journal_rel AS journal
+        ON journal.journal_id = invoice.journal_id
+        LEFT JOIN res_currency_rate AS rate
+        ON rate.currency_id = invoice.currency_id
+        LEFT JOIN res_company AS company
+        ON company.id = invoice.company_id
+        WHERE invoice.state = 'open'
+        AND journal.store_id = ''' + str(user_store) + ''' AND invoice.user_id = ''' + str(user_id) + '''
+        GROUP BY
+        	invoice.id,
+        	rate.currency_id,
+        	invoice.date_invoice,
+        	invoice.type,
+        	invoice.origin,
+        	invoice.amount_total,
+        	invoice.partner_id,
+        	invoice.user_id,
+            invoice.amount_total
+    '''
+
+    r.cr.execute(query,(tuple([company_currency_rate])))
+
+    return [
+        {
+            'invoice_id': j[0],
+            'currency_id': j[1],
+            'date': j[2],
+            'type': j[3],
+            'origin': j[4],
+            'customer_id':j[5],
+            'user_id':j[6],
+            'amount':j[7],
+            'number':j[8],
+
+        } for j in r.cr.fetchall()
+    ]

+ 42 - 0
controllers/helpers/account_move_line.py

@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_account_move_line():
+    user_store = r.env.user.store_id.id
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+    query = '''
+        SELECT
+        	move.id,
+        	move_line.id,
+        	account.id,
+            move.name,
+        	move_line.debit,
+        	move_line.credit,
+        	move_line.date_maturity,
+        	move_line.reconcile_ref,
+            account.type,
+            move_line.reconcile_partial_id
+        FROM account_move AS move
+        LEFT JOIN account_move_line AS move_line
+        ON move_line.move_id = move.id
+        LEFT JOIN account_account AS account
+        ON account.id = move_line.account_id
+        ORDER BY move_line.date_maturity
+    '''
+
+    r.cr.execute(query)
+
+    return [
+        {
+            'move_id': j[0],
+            'move_line_id': j[1],
+            'account_id': j[2],
+            'name': j[3],
+            'debit': j[4],
+            'credit': j[5],
+            'date_maturity': j[6],
+            'reconcile_ref':j[7],
+            'type':j[8],
+            'reconcile_partial_id':j[9],
+        } for j in r.cr.fetchall()
+    ]

+ 49 - 0
controllers/helpers/company.py

@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_company_info():
+    user_company = r.env.user.company_id.id
+    user_store = r.env.user.store_id.id
+    query = '''
+    SELECT
+        company.id,
+        company.name,
+        currency.id,
+        currency.name,
+        currency.symbol,
+        currency.decimal_places,
+        currency.decimal_separator,
+        currency.thousands_separator,
+        currency.symbol_position,
+        store.name AS store,
+        partner.ruc AS company_ruc
+    FROM res_company AS company
+    LEFT JOIN res_currency AS currency
+    ON company.currency_id = currency.id
+    LEFT JOIN res_store AS store
+    ON store.id = ''' + str(user_store) + '''
+    LEFT JOIN res_partner AS partner
+    ON partner.id = company.partner_id
+    WHERE currency.active = true
+    AND company.id = ''' + str(user_company) + '''
+    '''
+
+    r.cr.execute(query)
+
+    return [
+        {
+            'id': j[0],
+            'name': j[1],
+            'currency_id':{
+                'id':  j[2],
+                'name':  j[3],
+                'symbol':  j[4],
+                'decimal_places':  j[5],
+                'decimal_separator':  j[6],
+                'thousands_separator':  j[7],
+                'symbol_position':  j[8],
+            },
+            'store': j[9],
+            'ruc': j[10],
+        } for j in r.cr.fetchall()
+    ]

+ 17 - 0
controllers/helpers/ir_module_module.py

@@ -0,0 +1,17 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_ir_module_widget():
+    query = '''
+    SELECT name
+    FROM ir_module_module
+    WHERE state = 'installed'
+    '''
+
+    r.cr.execute(query)
+
+    return [
+        {
+            'name': j[0],
+        } for j in r.cr.fetchall()
+    ]

+ 89 - 0
controllers/helpers/pos_order.py

@@ -0,0 +1,89 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_pos_order_widget():
+    user_store = r.env.user.store_id.id
+
+    validate = '''
+        SELECT EXISTS(
+            SELECT table_name
+            FROM information_schema.columns
+            WHERE table_schema='public'
+                AND table_name='pos_order')
+    '''
+
+    query = '''
+        SELECT pos.create_date, pos.name, pos.partner_id, pos.user_id, SUM(line.price_subtotal_incl) as amount
+        FROM pos_order as pos
+        LEFT JOIN res_store_journal_rel as journal
+        ON journal.journal_id = pos.sale_journal
+        LEFT JOIN pos_order_line AS line
+        ON line.order_id = pos.id
+        --LEFT JOIN res_partner AS partner
+        --ON partner.id = pos.partner_id
+        WHERE TO_CHAR(pos.date_order,'YYYY-MM') = TO_CHAR(current_date,'YYYY-MM')
+        AND journal.store_id = ''' + str(user_store) + '''
+        GROUP BY pos.create_date, pos.partner_id, pos.user_id, pos.name
+    '''
+
+    r.cr.execute(validate)
+    for j in r.cr.fetchall():
+        band = j[0]
+
+    if band == True:
+        r.cr.execute(query)
+        return [
+            {
+                'date': j[0],
+                'name': j[1],
+                'customer_id': j[2],
+                'user_id': j[3],
+                'amount': j[4],
+            } for j in r.cr.fetchall()
+        ]
+    else:
+        return []
+
+def get_pos_order_widget_own():
+    user_store = r.env.user.store_id.id
+    user_id = r.env.user.id
+
+    validate = '''
+        SELECT EXISTS(
+            SELECT table_name
+            FROM information_schema.columns
+            WHERE table_schema='public'
+                AND table_name='pos_order')
+    '''
+
+    query = '''
+        SELECT pos.create_date, pos.name, pos.partner_id, pos.user_id, SUM(line.price_subtotal_incl) as amount
+        FROM pos_order as pos
+        LEFT JOIN res_store_journal_rel as journal
+        ON journal.journal_id = pos.sale_journal
+        LEFT JOIN pos_order_line AS line
+        ON line.order_id = pos.id
+        --LEFT JOIN res_partner AS partner
+        --ON partner.id = pos.partner_id
+        WHERE TO_CHAR(pos.date_order,'YYYY-MM') = TO_CHAR(current_date,'YYYY-MM')
+        AND journal.store_id = ''' + str(user_store) + ''' AND pos.user_id = ''' + str(user_id) + '''
+        GROUP BY pos.create_date, pos.partner_id, pos.user_id, pos.name
+    '''
+
+    r.cr.execute(validate)
+    for j in r.cr.fetchall():
+        band = j[0]
+
+    if band == True:
+        r.cr.execute(query)
+        return [
+            {
+                'date': j[0],
+                'name': j[1],
+                'customer_id': j[2],
+                'user_id': j[3],
+                'amount': j[4],
+            } for j in r.cr.fetchall()
+        ]
+    else:
+        return []

+ 21 - 0
controllers/helpers/res_partner.py

@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_res_partner():
+    query = '''
+        SELECT
+            partner.id,
+            partner.name,
+            partner.active
+        FROM res_partner AS partner WHERE partner.customer = true
+    '''
+
+    r.cr.execute(query)
+
+    return [
+        {
+            'id': j[0],
+            'name': j[1],
+            'active':j[2]
+        } for j in r.cr.fetchall()
+    ]

+ 18 - 0
controllers/helpers/res_store.py

@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_res_store_widget():
+    query = '''
+    SELECT  id,
+            name
+    FROM res_store
+    '''
+
+    r.cr.execute(query)
+
+    return [
+        {
+            'id': j[0],
+            'name': j[1],
+        } for j in r.cr.fetchall()
+    ]

+ 22 - 0
controllers/helpers/res_user.py

@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_user_info():
+    query = '''
+    SELECT
+        users.id,
+        partner.name
+    FROM res_users AS users
+    LEFT JOIN res_partner AS partner
+    ON partner.id = users.partner_id
+    WHERE users.active = true
+    '''
+
+    r.cr.execute(query)
+
+    return [
+        {
+            'id': j[0],
+            'name': j[1],
+        } for j in r.cr.fetchall()
+    ]

+ 27 - 0
controllers/helpers/widget_list.py

@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_widget_list():
+    user_id = r.env.user.id
+    query = '''
+        SELECT
+        	--users.id,
+        	--partner.name,
+        	chart.name
+        FROM res_users AS users
+        --LEFT JOIN res_partner AS partner
+        --ON partner.id = users.partner_id
+        LEFT JOIN chart_list_users_rel AS chart_rel
+        ON chart_rel.user_id = users.id
+        LEFT JOIN chart_list AS chart
+        ON chart.id = chart_rel.chart_id
+        WHERE users.id = ''' + str(user_id) + '''
+    '''
+
+    r.cr.execute(query)
+
+    return [
+        {
+            'name': j[0],
+        } for j in r.cr.fetchall()
+    ]

+ 47 - 0
controllers/main.py

@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+from openerp import http
+from werkzeug.wrappers import Response
+from werkzeug.datastructures import Headers
+from gzip import GzipFile
+from StringIO import StringIO as IO
+import simplejson as json
+import helpers as hp
+import logging
+
+LOGGER = logging.getLogger(__name__)
+GZIP_COMPRESSION_LEVEL = 9
+
+def make_gzip_response(data=None, status=200):
+    gzip_buffer = IO()
+
+    with GzipFile(mode='wb', compresslevel=GZIP_COMPRESSION_LEVEL, fileobj=gzip_buffer) as gzip_file:
+        gzip_file.write(json.dumps(data))
+
+    value = gzip_buffer.getvalue()
+    gzip_buffer.close()
+
+    headers = Headers()
+    headers.add('Content-Encoding', 'gzip')
+    headers.add('Vary', 'Accept-Encoding')
+    headers.add('Content-Length', len(value))
+
+    return Response(value, status=status, headers=headers, content_type='application/json')
+
+class DashboardController3(http.Controller):
+
+    @http.route('/dashboard-widgets3', auth='user', methods=['GET', 'POST'])
+    def getWidgetList(self, **kw):
+        return make_gzip_response({
+            'widgets': hp.get_widget_list(),
+        })
+
+    @http.route('/dashboard-RankingMorosos', auth='user', methods=['GET', 'POST'])
+    def getRankingMorosos(self, **kw):
+
+        return make_gzip_response({
+            'company': hp.get_company_info(),
+            'partner': hp.get_res_partner(),
+            'orders':hp.get_pos_order_widget(),
+            'invoices':hp.get_account_invoice(),
+            'moveLine':hp.get_account_move_line(),
+        })

+ 15 - 0
data/charts_data.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+
+        <!--
+        =============================================================
+            RANKING DE MOROSOS
+        =============================================================
+        -->
+        <record model="chart.list" id="widget_ranking_morosos">
+            <field name="name">RankingMorosos</field>
+        </record>
+
+    </data>
+</openerp>

BIN
static/description/icon.png


+ 102 - 0
static/src/js/chart.js

@@ -0,0 +1,102 @@
+function DashboardChart3(widget) {
+  "use strict";
+
+  var model = openerp;
+
+  widget.DashboardChartWidget3 = widget.Base.extend({
+
+    BuildBarChart3: function (name,label,body,CurrencyBase) {
+      var self = this;
+      Chart.scaleService.updateScaleDefaults('linear', {
+        ticks: {
+          callback: function(tick) {
+            return tick.toLocaleString('de-DE');
+          }
+        }
+      });
+
+      Chart.defaults.global.tooltips.callbacks.label = function(tooltipItem, data) {
+        var dataset = data.datasets[tooltipItem.datasetIndex];
+        var datasetLabel = dataset.label || '';
+        return datasetLabel +  dataset.data[tooltipItem.index].toLocaleString('de-DE');
+      };
+
+      var color = [];
+          color.push('#BCCEF4');
+          color.push('#A9E5E3');
+          color.push('#A0D995');
+          color.push('#C5D084');
+          color.push('#FAE187');
+          color.push('#FFBD82');
+          color.push('#FFA8B8');
+          color.push('#E5BEDD');
+          color.push('#C4ABFE');
+          color.push('#D8D8D8');
+          color.push('#F04155');
+          color.push('#FF823A');
+          color.push('#F2F26F');
+          color.push('#FFF7BD');
+          color.push('#95CFB7');
+          color.push('#C6EA69');
+          color.push('#20A377');
+          color.push('#655DDD');
+          color.push('#C95CE8');
+          color.push('#E5A877');
+          // #554236, #F77825, #D3CE3D, #F1EFA5, #60B99A, #96F29A, #EA919A, #E3B3F9, #58B501, #C93A24
+
+
+      var chartData = {
+        labels: label,
+        datasets: [{
+          label: false,
+          type: 'horizontalBar',
+          backgroundColor: color,
+          data: body,
+          fill: true,
+        }]
+      };
+
+      var chart = new Chart($(name),{
+        type: 'horizontalBar',
+        data: chartData,
+        options: {
+          responsive: true,
+          responsiveAnimationDuration:10,
+          maintainAspectRatio:false,
+          title: {
+            display: false,
+          },
+          hover: {
+            mode: 'nearest',
+            intersect: true
+          },
+          legend: {
+            display: false,
+          },
+          layout: {
+            padding: {
+              top: 0,
+              bottom: 0,
+              left : 0,
+              rigth: 0,
+            }
+          },
+
+          tooltips: {
+
+            callbacks: {
+              label: function(tooltipItem, data) {
+                var label = data.datasets[tooltipItem.datasetIndex].label || '';
+                if (label) {
+                  label += ': ';
+                }
+                label += accounting.formatMoney(tooltipItem.xLabel, CurrencyBase.label, CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator);
+                return label;
+              }
+            }
+          }
+        }
+      });
+    },
+  });
+}

+ 28 - 0
static/src/js/dashboard.js

@@ -0,0 +1,28 @@
+function dashboard_reporting_widget3 (instance, widget) {
+  "use strict";
+
+  var widgets = widget;
+
+  instance.eiru_reports_dashboard.DashboardReportingWidget = instance.eiru_reports_dashboard.DashboardReportingWidget.extend({
+
+    RenderWidgets: function () {
+      var self = this;
+      this._super.apply(this, arguments);
+
+      var ChartList = self.Widgets;
+
+      // CHART VENTA POR VENDEDOR CON OBJETIVOS
+
+      var chart =  _.flatten(_.filter(ChartList,function (inv) {
+        return inv.name == 'RankingMorosos';
+      }));
+
+      if(chart.length > 0){
+        var RankingMorosos = new widgets.RankingMorosos();
+        RankingMorosos.renderElement();
+        RankingMorosos.start();
+        this.grid.addWidget(RankingMorosos.$el, 0, 0,RankingMorosos.size.width,RankingMorosos.size.height,true);
+      }
+    },
+  });
+}

+ 18 - 0
static/src/js/main.js

@@ -0,0 +1,18 @@
+openerp.eiru_dashboard_bienstar = function (instance) {
+  "use strict";
+  instance.eiru_dashboard_bienstar = {};
+  var dashboard = instance.eiru_dashboard_bienstar;
+
+  widget_reporting_base3(instance, dashboard);
+  dashboard_reporting_widget3(instance, dashboard);
+
+  try{
+
+    DashboardChart3(dashboard);
+    widget_ranking_morosos(dashboard);
+
+  }
+  catch(e){
+    //ERROR
+  }
+}

+ 5 - 0
static/src/js/widget_base.js

@@ -0,0 +1,5 @@
+function widget_reporting_base3 (instance, widget) {
+  "use strict";
+
+  widget.Base = instance.eiru_reports_dashboard.Base.extend({});
+}

+ 284 - 0
static/src/js/widgets/widget_ranking_morosos.js

@@ -0,0 +1,284 @@
+function widget_ranking_morosos(widget) {
+  "use strict";
+
+  var Qweb = openerp.web.qweb;
+  var model = openerp;
+
+  widget.RankingMorosos = widget.Base.extend({
+    template: 'RankingMorosos',
+
+    events:{
+      'change #current-state' : 'UpdateChart',
+    },
+
+    init: function (parent) {
+      this._super(parent, {
+        width: 12,
+        height: 8,
+      });
+    },
+
+    start: function () {
+      var self = this;
+      self.fetchInitial();
+    },
+
+    fetchInitial: function(){
+      var self = this;
+      self.fetchDataSQL().then(function (DataSQL) {
+        return DataSQL;
+      }).then(function(DataSQL) {
+        self.ResPartner = DataSQL.partner;
+        self.ResCompany = DataSQL.company;
+        self.AccountInvoice = DataSQL.invoices;
+        return self.fetchAccountMoveLine();
+      }).then(function(AccountMoveLine){
+        self.AccountMoveLine = AccountMoveLine;
+        return self.MorososRanking();
+      });
+    },
+
+    fetchDataSQL: function() {
+      var data = $.get('/dashboard-RankingMorosos');
+      return data;
+    },
+
+    fetchAccountMoveLine: function(){
+      var self = this;
+      var defer = $.Deferred();
+      var fields = ['id','name', 'move_id', 'debit', 'credit', 'date_maturity','reconcile_ref','partner_id','amount_residual'];
+      var invoice_numbers = _.flatten(_.map(self.AccountInvoice, function(item){
+        return item.number;
+      }));
+      var domain = [
+        ['move_id','in',invoice_numbers],
+        ['debit','>',0],
+      ];
+
+      var AccountMoveLine = new model.web.Model('account.move.line');
+      AccountMoveLine.query(fields).filter(domain).all().then(function(results){
+        defer.resolve(results);
+      });
+      return defer;
+    },
+
+    getAccountInvoice:function(id) {
+      var self = this;
+      return _.flatten(_.filter(self.AccountInvoice,function (inv) {
+        return inv.customer_id == id && inv.type == 'out_invoice';
+      }));
+    },
+
+    getResPartner:function() {
+      var self = this;
+      return _.flatten(_.filter(self.ResPartner,function (partner) {
+        return partner.active == true;
+      }));
+    },
+
+    getAccountMoveLine: function(number){
+      var self = this;
+      var AccountMoveLine = _.filter(self.AccountMoveLine,function(item){
+        return item.move_id[1] == number & item.debit > 0;
+      });
+
+      var x = AccountMoveLine.length;
+      var i = AccountMoveLine.length;
+      var content =_.map(AccountMoveLine, function(item2){
+        if(item2.date_maturity != false){
+          item2.dues_name= 'Cuota ' + i +' / ' + x;
+          i--;
+          return item2;
+        };
+      });
+      content = _.filter(content,function(item){
+        return item != undefined;
+      })
+      return content;
+    },
+
+    MorososRanking: function(){
+      var self = this;
+      var data = [];
+      var state = $('#current-state').val();
+      var ResPartner = self.getResPartner();
+      _.each(ResPartner, function(item){
+        var info = [];
+        var due_qty=0;
+        var amount=0;
+        var AccountInvoice = self.getAccountInvoice(item.id);
+         _.each(AccountInvoice, function(item){
+           var AccountMoveLine = self.getAccountMoveLine(item.number);
+           var Company = self.ResCompany[0];
+           _.each(AccountMoveLine, function(index){
+             var date;
+             var state = 'Vencido';
+             if(index.reconcile_ref){
+               if(index.amount_residual == 0){
+                 state = 'Pagado';
+               }
+               if(index.amount_residual > 0){
+                 state = 'Amortizado';
+               }
+             }
+             date = moment(index.date_maturity,'YYYY-MM-DD').format('DD/MM/YYYY');
+             if(state != 'Pagado'){
+               if(index.date_maturity < moment().format('YYYY-MM-DD')){
+                 due_qty++;
+                 var days_of_delays =  moment().diff(moment(index.date_maturity), 'days');
+                 amount = amount + index.amount_residual;
+                 info.push({
+                   invoice_id : item.id,
+                   invoice : item.number,
+                   partner_id : item.customer_id,
+                   date : date,
+                   name : index.dues_name,
+                   state : state,
+                   days_of_delays: days_of_delays,
+                 });
+               };
+             };
+           });
+         });
+
+         if(info.length > 0){
+           var max_days_of_delay= info.reduce((max, p) => p.days_of_delays > max ? p.days_of_delays : max, info[0].days_of_delays);
+           data.push({
+             partner_name : item.name,
+             due_qty:due_qty,
+             max_days_of_delay: max_days_of_delay ? max_days_of_delay : 0,
+             amount: amount,
+           })
+         }
+       });
+       self.content = data;
+       self.BuildChart(data);
+     },
+
+     BuildChart: function (ranking){
+       var self = this;
+       var state = $('#current-state').val();
+       var label = [];
+       var body = [];
+       var item;
+       var CurrencyBase = self.ResCompany[0].currency_id;
+
+       ranking.sort(function(a, b){
+         if(state == 'day_of_delay'){
+          var x = a.max_days_of_delay;
+          var y = b.max_days_of_delay;
+        };
+        if(state == 'due_qty'){
+          var x = a.due_qty;
+          var y = b.due_qty;
+        }
+        if(state == 'amount_delay'){
+          var x = a.amount;
+          var y = b.amount;
+        };
+        if (x > y) {
+          return -1;
+        }
+        if (x < y) {
+          return 1;
+        }
+          return 0;
+      });
+
+      for (var i = 0; i < 20; i++) {
+        if (ranking[i]){
+          item = ranking[i];
+        }else{
+          item = {};
+          item.partner_name = "N/A";
+          item.max_days_of_delay=0;
+          item.due_qty=0;
+          item.amount_=0;
+        }
+
+        label.push(item.partner_name.trim());
+        if(state == 'day_of_delay'){
+          body.push(item.max_days_of_delay);
+          CurrencyBase.label = "Días atrasados: ";
+        };
+        if(state == 'due_qty'){
+          body.push(item.due_qty);
+          CurrencyBase.label = "Cuotas vencidas: ";
+        }
+        if(state == 'amount_delay'){
+          CurrencyBase.label = CurrencyBase.symbol;
+          body.push(item.amount);
+        };
+      }
+
+      var name = '.ranking-morosos-chart';
+      var chart = new widget.DashboardChartWidget3(self);
+      chart.BuildBarChart3(name,label,body,CurrencyBase);
+    },
+
+    UpdateChart: function (){
+      var self = this;
+      var state = $('#current-state').val();
+      var label = [];
+      var body = [];
+      var item;
+      var CurrencyBase = self.ResCompany[0].currency_id;
+      var ranking = self.content;
+
+      ranking.sort(function(a, b){
+        if(state == 'day_of_delay'){
+          var x = a.max_days_of_delay;
+          var y = b.max_days_of_delay;
+        };
+        if(state == 'due_qty'){
+          var x = a.due_qty;
+          var y = b.due_qty;
+        }
+        if(state == 'amount_delay'){
+          var x = a.amount;
+          var y = b.amount;
+        };
+        if (x > y) {
+          return -1;
+        }
+        if (x < y) {
+          return 1;
+        }
+        return 0;
+      });
+
+      for (var i = 0; i < 20; i++) {
+        if (ranking[i]){
+          item = ranking[i];
+        }else{
+          item = {};
+          item.partner_name = "N/A";
+          item.max_days_of_delay=0;
+          item.due_qty=0;
+          item.amount=0;
+        }
+
+        label.push(item.partner_name.trim());
+        if(state == 'day_of_delay'){
+          body.push(item.max_days_of_delay);
+          CurrencyBase.label = "Días atrasados: ";
+        };
+        if(state == 'due_qty'){
+          body.push(item.due_qty);
+          CurrencyBase.label = "Cuotas vencidas: ";
+        }
+        if(state == 'amount_delay'){
+          CurrencyBase.label = CurrencyBase.symbol;
+          body.push(item.amount);
+        };
+      }
+
+      $(".ranking-morosos-chart").remove();
+      $(".chart-container-bienstar").html('<canvas class="ranking-morosos-chart" style="padding-top:10px;width:100%"></canvas>');
+
+      var name = '.ranking-morosos-chart';
+      var chart = new widget.DashboardChartWidget3(self);
+      chart.BuildBarChart3(name,label,body,CurrencyBase);
+    }
+  });
+}

+ 25 - 0
static/src/xml/widgets/widget_ranking_morosos.xml

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+  <t t-name="RankingMorosos">
+    <div>
+      <div class="grid-stack-item-content reporting-dashboard ucrm" style="height:610px">
+        <div class="widget-content">
+          <div class="row">
+            <h2 style="margin-top:0px;margin-left:10px;" class="text-center"><small> Ranking de Morosos </small></h2>
+          </div>
+          <div class="state">
+            <label style="float:left; padding:10px;">Ordenar por</label>
+            <select id="current-state" class="form-control form-control-sm" style="width:auto">
+              <option value="day_of_delay">Días atrasados</option>
+              <option value="due_qty">Cantidad de cuotas vencidas</option>
+              <option value="amount_delay">Monto atrasado</option>
+            </select>
+          </div>
+          <div class="chart-container-bienstar center-block" style="padding:10px;height:500px;">
+            <canvas class="ranking-morosos-chart" style="padding-top:10px;width:100%"></canvas>
+          </div>
+        </div>
+      </div>
+    </div>
+  </t>
+</template>

+ 14 - 0
template.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+  <data>
+    <template id="eiru_dashboard_bienstar_assets" inherit_id="eiru_assets.assets">
+      <xpath expr="." position="inside">
+        <script type="text/javascript" src="/eiru_dashboard_bienstar/static/src/js/chart.js"/>
+        <script type="text/javascript" src="/eiru_dashboard_bienstar/static/src/js/widget_base.js" />
+        <script type="text/javascript" src="/eiru_dashboard_bienstar/static/src/js/widgets/widget_ranking_morosos.js"/>
+        <script type="text/javascript" src="/eiru_dashboard_bienstar/static/src/js/dashboard.js"/>
+        <script type="text/javascript" src="/eiru_dashboard_bienstar/static/src/js/main.js"/>
+      </xpath>
+    </template>
+  </data>
+</openerp>