openerp.eiru_payslip_generator = function(instance, local) { local.widgetInstance = null; local.parentInstance = null; local.PayslipGeneratorWidget = instance.Widget.extend({ template: 'eiru_payslip_generator.PayslipWidget', id: undefined, init: function(parent) { this._super(parent); this.buttons = parent.$buttons; }, start: function() { var self = this; this.$el.click(function() { self.fectchInitial() }); self.buttons.click(function(e) { /* E (Editar) */ if (e.target.accessKey === 'E') self.$el.css('display','none'); /* C (Crear) */ if (e.target.accessKey === 'C') self.$el.css('display','none'); /* S (Guarrdar) */ if (e.target.accessKey === 'S') self.$el.css('display','flex'); /* D (Cancelar) */ if (e.target.accessKey === 'D') self.$el.css('display','flex'); }); }, updateId: function(id) { var self = this; self.id = id; }, fectchInitial: function() { var self = this; self.fectchGenerateNomina().then(function(payslip) { return payslip; }).then(function(payslip) { local.parentInstance.reload(); if (!payslip) instance.web.notification.do_warn("AtenciĆ³n","No existe nomina para ser generada, en el periodo seleccionado"); }) }, fectchGenerateNomina: function() { var self = this; var defer = $.Deferred(); var hr_payslip = new instance.web.Model('hr.payslip'); hr_payslip.call('generate_payroll_eiru',[self.id], { context: new instance.web.CompoundContext() }).then(function(results) { defer.resolve(results); }); return defer; }, }); if (instance.web && instance.web.FormView) { instance.web.FormView.include({ load_record: function(record) { this._super.apply(this, arguments); if (this.model !== 'hr.payslip.run') return; local.parentInstance = this; if (local.widgetInstance) { local.widgetInstance.updateId(record.id); } if (this.$el.find('.eiru-payslip').length !== 0 ) return; local.widgetInstance = new local.PayslipGeneratorWidget(this); var elemento = this.$el.find('.oe_form_sheet.oe_form_sheet_width'); elemento = elemento.find('.oe_right.oe_button_box.eiru-payslip-generator'); local.widgetInstance.appendTo(elemento); local.widgetInstance.updateId(record.id); } }); } }