missing_product.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. function missing_product (widget) {
  2. "use strict";
  3. var model = openerp;
  4. widget.MissingProductWidget = widget.Base.extend({
  5. template: 'MissingProduct',
  6. stockQuant: [],
  7. productProduct: [],
  8. modelId: [],
  9. events: {
  10. 'click a': 'showCustomers',
  11. 'click h2': 'showCustomers',
  12. },
  13. init: function (parent) {
  14. this._super(parent, {
  15. width: 3,
  16. height: 2
  17. });
  18. },
  19. start: function () {
  20. var self = this;
  21. self.fetchInitial();
  22. },
  23. fetchInitial: function () {
  24. var self = this;
  25. self.$el.find('#morosidad').block({
  26. message: null,
  27. overlayCSS: {
  28. backgroundColor: '#FAFAFA'
  29. }
  30. });
  31. self.$el.find('.widget-content.widget-loading').css('display','flex');
  32. // Iniciar Consultas
  33. self.fetchProductProduct().then(function(productProduct) {
  34. return productProduct;
  35. }).then(function(productProduct) {
  36. self.productProduct = productProduct;
  37. return self.fetchGetModelId();
  38. }).then(function(modelId) {
  39. self.modelId = modelId;
  40. return self.fetchReduceProduct();
  41. });
  42. },
  43. // getModelId
  44. fetchGetModelId: function() {
  45. var self = this;
  46. var defer = $.Deferred();
  47. var irModelData = new model.web.Model('ir.model.data');
  48. var getObtjectReference = irModelData.get_func('get_object_reference');
  49. this.alive(getObtjectReference('product', 'product_normal_form_view')).then(function(results) {
  50. defer.resolve(results);
  51. });
  52. return defer;
  53. },
  54. fetchProductProduct : function(stockQaunt) {
  55. var self = this;
  56. var defer = $.Deferred();
  57. var product_id = _.map(stockQaunt,function(map) {
  58. return map.product_id[0];
  59. });
  60. var fields = ['id', 'name_template', 'qty_available'];
  61. var domain = [['qty_available', '<=', 0],['type', '=', 'product'],['active','=',true]];
  62. var productProduct = new model.web.Model('product.product');
  63. productProduct.query(fields).filter(domain).all().then(function(results) {
  64. defer.resolve(results);
  65. });
  66. return defer;
  67. },
  68. // // Reduce Move line
  69. fetchReduceProduct: function () {
  70. var self = this;
  71. var cantidad;
  72. cantidad = _.countBy(_.map(self.productProduct,function(map) {
  73. return map.id;
  74. }),function(num) {
  75. return num ? 'even': 'odd';
  76. });
  77. if (!cantidad.even) {
  78. cantidad = {};
  79. cantidad.even = 0;
  80. }
  81. self.$el.find('.widget-content.widget-loading').css('display','none');
  82. self.$el.find('.widget-content').find('a').text(cantidad.even);
  83. self.$el.find('#morosidad').unblock();
  84. },
  85. showCustomers: function (e) {
  86. var self = this;
  87. if (self.productProduct.length === 0 ) {
  88. model.web.notification.do_warn("Atención","Sin datos");
  89. return
  90. }
  91. this.do_action({
  92. name: "Listado de productos faltan-tes",
  93. type: 'ir.actions.act_window',
  94. res_model: "product.product",
  95. views: [[false, 'list'],[self.modelId[1],'form']],
  96. target: 'current',
  97. domain: [['type', '=', 'product'],['qty_available','<=',0]],
  98. context: {},
  99. });
  100. }
  101. });
  102. }