invoice_today_counters.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. function invoice_today_counters (widget) {
  2. "use strict";
  3. var model= openerp;
  4. widget.InvoiceTodayCountersWidget = widget.Base.extend({
  5. template: 'InvoiceTodayCounters',
  6. events: {
  7. 'click a': 'showCustomers',
  8. 'click h2': 'showCustomers',
  9. },
  10. init: function (parent) {
  11. this._super(parent, {
  12. width : 3,
  13. height: 2
  14. });
  15. },
  16. start: function () {
  17. var self = this;
  18. self.fetchInitial();
  19. },
  20. fetchInitial: function(){
  21. var self = this;
  22. self.$el.find('#morosidad').block({
  23. message: null,
  24. overlayCSS: {
  25. backgroundColor: '#FAFAFA'
  26. }
  27. });
  28. self.$el.find('.widget-content.widget-loading').css('display','flex');
  29. self.fetchAccountInvoice().then(function (accountInvoice) {
  30. return accountInvoice;
  31. }).then(function (accountInvoice) {
  32. return self.fetchReduceInvoice(accountInvoice);
  33. });
  34. },
  35. // Invoice
  36. fetchAccountInvoice: function() {
  37. var self = this;
  38. var defer = $.Deferred();
  39. var hoy =moment().format('YYYY-MM-DD');
  40. var fields = ['id', 'residual'];
  41. var domain = [['type', '=', 'out_invoice'], ['state', 'in', ['open','paid']], ['date_invoice', '=', hoy]];
  42. var accountInvoice = new model.web.Model('account.invoice');
  43. accountInvoice.query(fields).filter(domain).all().then(function (results){
  44. defer.resolve(results);
  45. });
  46. return defer;
  47. },
  48. fetchReduceInvoice: function (accountInvoice) {
  49. var self = this;
  50. var fecha = new Date();
  51. var cat = 0;
  52. if (accountInvoice.length > 0){
  53. cat = accountInvoice.length;
  54. }
  55. self.$el.find('.widget-content.widget-loading').css('display','none');
  56. self.$el.find('.widget-content').find('a').text(accounting.formatNumber(cat, ".", ","));
  57. // self.$el.find('.widget-footer').find('span').text("Facturas Creadas en "+ fecha.getDate() + "/" + (fecha.getMonth() + 1) + "/" + fecha.getFullYear());
  58. self.$el.find('#morosidad').unblock();
  59. },
  60. showCustomers: function (e) {
  61. var hoy =moment().format('YYYY-MM-DD');
  62. this.do_action({
  63. name:"Facturas realizadas hoy",
  64. type: 'ir.actions.act_window',
  65. res_model: "account.invoice",
  66. views: [[false, 'list'],[false,'form']],
  67. target: 'new',
  68. domain: [['type', '=', 'out_invoice'], ['state', 'in', ['open','paid']], ['date_invoice', '=', hoy]],
  69. context: {},
  70. flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
  71. });
  72. }
  73. });
  74. }