123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- 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: {},
- });
- }
- });
- }
|