function invoice_today_counters (widget) { "use strict"; var model= openerp; widget.InvoiceTodayCountersWidget = widget.Base.extend({ template: 'InvoiceTodayCounters', 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) { return self.fetchReduceInvoice(accountInvoice); }); }, // 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('.widget-footer').find('span').text("Facturas Creadas en "+ fecha.getDate() + "/" + (fecha.getMonth() + 1) + "/" + fecha.getFullYear()); self.$el.find('#morosidad').unblock(); }, showCustomers: function (e) { 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'],[false,'form']], target: 'new', domain: [['type', '=', 'out_invoice'], ['state', 'in', ['open','paid']], ['date_invoice', '=', hoy]], context: {}, flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}}, }); } }); }