function invoice_today_counters (widget) { "use strict"; var model = openerp; widget.InvoiceTodayCountersWidget = widget.Base.extend({ template: 'InvoiceTodayCounters', irModelData: [], accountInvoice: [], events: { 'click a': 'showCustomers', 'click h2': 'showCustomers', }, init: function (parent) { this._super(parent, { width : 3, height: 2 }); }, start: function () { var self = this; self.fetchInitial(); }, fetchInitial: function() { var self = this; self.$el.find('#morosidad').block({ message: null, overlayCSS: { backgroundColor: '#FAFAFA' } }); self.$el.find('.widget-content.widget-loading').css('display','flex'); self.fetchAccountInvoice().then(function (accountInvoice) { return accountInvoice; }).then(function (accountInvoice) { self.accountInvoice=accountInvoice; return self.fetchGetModelId(); }).then(function(irModelData) { self.irModelData=irModelData; return self.fetchReduceInvoice(self.accountInvoice); }); }, // getModelId fetchGetModelId: function() { var self = this; var defer = $.Deferred(); var irModelData = new model.web.Model('ir.model.data'); var getObtjectReference = irModelData.get_func('get_object_reference'); getObtjectReference('account', 'invoice_form').then(function(results) { defer.resolve(results); }); return defer; }, // Invoice fetchAccountInvoice: function() { var self = this; var defer = $.Deferred(); var hoy = moment().format('YYYY-MM-DD'); var fields = ['id', 'residual']; var domain = [['type', '=', 'out_invoice'], ['state', 'in', ['open','paid']], ['date_invoice', '=', hoy]]; var accountInvoice = new model.web.Model('account.invoice'); accountInvoice.query(fields).filter(domain).all().then(function (results) { defer.resolve(results); }); return defer; }, fetchReduceInvoice: function (accountInvoice) { var self = this; var fecha = new Date(); var cat = 0; if (accountInvoice.length > 0) { cat = accountInvoice.length; } self.$el.find('.widget-content.widget-loading').css('display','none'); self.$el.find('.widget-content').find('a').text(accounting.formatNumber(cat, ".", ",")); self.$el.find('#morosidad').unblock(); }, showCustomers: function (e) { var self = this; if (self.accountInvoice.length === 0) { model.web.notification.do_warn("AtenciĆ³n","Sin datos"); return } var hoy = moment().format('YYYY-MM-DD'); this.do_action({ name: "Facturas realizadas hoy", type: 'ir.actions.act_window', res_model: "account.invoice", views: [[false, 'list'],[self.irModelData[1],'form']], target: 'current', domain: [['type', '=', 'out_invoice'], ['state', 'in', ['open','paid']], ['date_invoice', '=', hoy]], context: {}, }); } }); }