invoice_today_counters.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. function invoice_today_counters (widget) {
  2. "use strict";
  3. var model = openerp;
  4. widget.InvoiceTodayCountersWidget = widget.Base.extend({
  5. template: 'InvoiceTodayCounters',
  6. irModelData: [],
  7. accountInvoice: [],
  8. events: {
  9. 'click a': 'showCustomers',
  10. 'click h2': 'showCustomers',
  11. },
  12. init: function (parent) {
  13. this._super(parent, {
  14. width : 3,
  15. height: 2
  16. });
  17. },
  18. start: function () {
  19. var self = this;
  20. self.fetchInitial();
  21. },
  22. fetchInitial: function() {
  23. var self = this;
  24. self.$el.find('#morosidad').block({
  25. message: null,
  26. overlayCSS: {
  27. backgroundColor: '#FAFAFA'
  28. }
  29. });
  30. self.$el.find('.widget-content.widget-loading').css('display','flex');
  31. self.fetchAccountInvoice().then(function (accountInvoice) {
  32. return accountInvoice;
  33. }).then(function (accountInvoice) {
  34. self.accountInvoice=accountInvoice;
  35. return self.fetchGetModelId();
  36. }).then(function(irModelData) {
  37. self.irModelData=irModelData;
  38. return self.fetchReduceInvoice(self.accountInvoice);
  39. });
  40. },
  41. // getModelId
  42. fetchGetModelId: function() {
  43. var self = this;
  44. var defer = $.Deferred();
  45. var irModelData = new model.web.Model('ir.model.data');
  46. var getObtjectReference = irModelData.get_func('get_object_reference');
  47. getObtjectReference('account', 'invoice_form').then(function(results) {
  48. defer.resolve(results);
  49. });
  50. return defer;
  51. },
  52. // Invoice
  53. fetchAccountInvoice: function() {
  54. var self = this;
  55. var defer = $.Deferred();
  56. var hoy = moment().format('YYYY-MM-DD');
  57. var fields = ['id', 'residual'];
  58. var domain = [['type', '=', 'out_invoice'], ['state', 'in', ['open','paid']], ['date_invoice', '=', hoy]];
  59. var accountInvoice = new model.web.Model('account.invoice');
  60. accountInvoice.query(fields).filter(domain).all().then(function (results) {
  61. defer.resolve(results);
  62. });
  63. return defer;
  64. },
  65. fetchReduceInvoice: function (accountInvoice) {
  66. var self = this;
  67. var fecha = new Date();
  68. var cat = 0;
  69. if (accountInvoice.length > 0) {
  70. cat = accountInvoice.length;
  71. }
  72. self.$el.find('.widget-content.widget-loading').css('display','none');
  73. self.$el.find('.widget-content').find('a').text(accounting.formatNumber(cat, ".", ","));
  74. self.$el.find('#morosidad').unblock();
  75. },
  76. showCustomers: function (e) {
  77. var self = this;
  78. if (self.accountInvoice.length === 0) {
  79. model.web.notification.do_warn("Atención","Sin datos");
  80. return
  81. }
  82. var hoy = moment().format('YYYY-MM-DD');
  83. this.do_action({
  84. name: "Facturas realizadas hoy",
  85. type: 'ir.actions.act_window',
  86. res_model: "account.invoice",
  87. views: [[false, 'list'],[self.irModelData[1],'form']],
  88. target: 'current',
  89. domain: [['type', '=', 'out_invoice'], ['state', 'in', ['open','paid']], ['date_invoice', '=', hoy]],
  90. context: {},
  91. });
  92. }
  93. });
  94. }