|
@@ -0,0 +1,186 @@
|
|
|
+(function() {
|
|
|
+
|
|
|
+ var QWeb = openerp.web.qweb;
|
|
|
+ openerp.widgetInstance = null;
|
|
|
+ openerp.PayslipUtility = {};
|
|
|
+
|
|
|
+ openerp.PayslipUtility = openerp.Widget.extend({
|
|
|
+ template: 'payslip_add.FaultsWidget',
|
|
|
+ /* init */
|
|
|
+ init: function (parent) {
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+ /* Start */
|
|
|
+ start: function () {
|
|
|
+ var self = this;
|
|
|
+ var addFaults = this.$el.find('.add-faults');
|
|
|
+ var editFaults = this.$el.find('.edit-faults');
|
|
|
+ var refreshFaults = this.$el.find('.refresh-faults');
|
|
|
+
|
|
|
+ // create
|
|
|
+ addFaults.click(function() {
|
|
|
+ self.fectchAddFaults();
|
|
|
+ });
|
|
|
+ // Edit/ unlink
|
|
|
+ editFaults.click(function() {
|
|
|
+ });
|
|
|
+ // Update
|
|
|
+ refreshFaults.click(function(){
|
|
|
+ self.fectchRecomputeSheet();
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* Actualizar ID */
|
|
|
+ updateId: function(id) {
|
|
|
+ var self = this;
|
|
|
+ self.id = id;
|
|
|
+ },
|
|
|
+ /* Description: Recargar el Widget */
|
|
|
+ reloadLine: function() {
|
|
|
+ openerp.parentInstance.reload();
|
|
|
+ },
|
|
|
+ /* Description: Función para remover el modal */
|
|
|
+ removeModal: function() {
|
|
|
+ $('.expired-account-modal').remove();
|
|
|
+ $('.modal-backdrop').remove();
|
|
|
+ },
|
|
|
+ /* ---------------------------------------------------------------------
|
|
|
+ * Description: Recalcular faltas de funcionario
|
|
|
+ * -------------------------------------------------------------------*/
|
|
|
+ /* Description: Función Inicial para recalcular las faltas*/
|
|
|
+ fectchRecomputeSheet: function() {
|
|
|
+ var self= this;
|
|
|
+ self.$el.find('.refresh-faults').attr("disabled", true);
|
|
|
+ self.recomputeSheet().then(function(results) {
|
|
|
+ return results;
|
|
|
+ }).then(function(){
|
|
|
+ self.$el.find('.refresh-faults').removeAttr("disabled");
|
|
|
+ self.reloadLine()
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /* Description: Función para recalcular las faltas */
|
|
|
+ recomputeSheet: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var recomputePayslip = new openerp.web.Model('hr.payslip');
|
|
|
+
|
|
|
+ recomputePayslip.call('recompute_sheet',[ self.id ],{
|
|
|
+ context: new openerp.web.CompoundContext()
|
|
|
+ }).then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ /* ---------------------------------------------------------------------
|
|
|
+ * Description: Crear Faltas
|
|
|
+ * -------------------------------------------------------------------*/
|
|
|
+ /* Description: Función Inicial Add Faltas */
|
|
|
+ fectchAddFaults: function() {
|
|
|
+ var self = this;
|
|
|
+ self.showPayslipAddFaults();
|
|
|
+ },
|
|
|
+ /* Description: Adicionar Faltas (Modal) */
|
|
|
+ showPayslipAddFaults: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer =$.Deferred();
|
|
|
+ var results = true;
|
|
|
+
|
|
|
+ var modal = QWeb.render('EiruPayslipAddFaults');
|
|
|
+ $('.openerp_webclient_container').after(modal);
|
|
|
+ $('.expired-account-modal').modal();
|
|
|
+ // Close modal
|
|
|
+ $('.expired-account-modal').on('hidden.bs.modal', function (e) {
|
|
|
+ results = false;
|
|
|
+ defer.resolve(results)
|
|
|
+ self.removeModal(e);
|
|
|
+ });
|
|
|
+ // Add faults
|
|
|
+ $('.expired-account-modal').find('.add-faults').click(function(e) {
|
|
|
+ var details = $('.expired-account-modal').find('.payslip-details').val();
|
|
|
+ var number = $('.expired-account-modal').find('.payslip-number-days').val();
|
|
|
+
|
|
|
+ if (!details){
|
|
|
+ openerp.web.notification.do_warn("Atención","Definir un motivo de la falta .");
|
|
|
+ $('.expired-account-modal').find('.payslip-details').css('border-color','red');
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ $('.expired-account-modal').find('.payslip-details').css('border-color','#ccc');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (number <= 0){
|
|
|
+ openerp.web.notification.do_warn("Atención","Días no trabajado, debe ser mayor que 0.");
|
|
|
+ $('.expired-account-modal').find('.payslip-number-days').css('border-color','red');
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ $('.expired-account-modal').find('.payslip-number-days').css('border-color','#ccc');
|
|
|
+ }
|
|
|
+ self.joinPayslipFaults(number, details).then(function(results){
|
|
|
+ return results;
|
|
|
+ }).then(function(results){
|
|
|
+ self.reloadLine()
|
|
|
+ if (!results)
|
|
|
+ results = false;
|
|
|
+ });
|
|
|
+ defer.resolve(results);
|
|
|
+ self.removeModal(e);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ /* Description: Función para agregar nueva falta y hacer el calculo de faltas en la nomina */
|
|
|
+ joinPayslipFaults: function(faultsCount, faultsDescri) {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var payslip = new openerp.web.Model('hr.payslip');
|
|
|
+
|
|
|
+ payslip.call('join_payslip_faults',[
|
|
|
+ {
|
|
|
+ id: self.id,
|
|
|
+ faultsDays: faultsCount,
|
|
|
+ faultsDescri: faultsDescri
|
|
|
+ }
|
|
|
+ ], {
|
|
|
+ context: new openerp.web.CompoundContext()
|
|
|
+ }).then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ /* ---------------------------------------------------------------------
|
|
|
+ * Description: Editar/Remover Faltas
|
|
|
+ * -------------------------------------------------------------------*/
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ if (openerp.web && openerp.web.FormView) {
|
|
|
+ openerp.web.FormView.include({
|
|
|
+ load_record: function(record) {
|
|
|
+ this._super.apply(this, arguments);
|
|
|
+
|
|
|
+ if (this.model !== 'hr.payslip')
|
|
|
+ return;
|
|
|
+
|
|
|
+ if (this.$el.find('.oe_form_sheet.oe_form_sheet_width').closest('.modal-content.openerp').length !== 0)
|
|
|
+ return;
|
|
|
+
|
|
|
+ openerp.parentInstance = this;
|
|
|
+
|
|
|
+ if (openerp.widgetInstance) {
|
|
|
+ openerp.widgetInstance.updateId(record.id);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.$el.find('.payslip-add-faults').length !== 0 )
|
|
|
+ return;
|
|
|
+
|
|
|
+ openerp.widgetInstance = new openerp.PayslipUtility(this);
|
|
|
+
|
|
|
+ var elemento = this.$el.find('.oe_notebook_page');
|
|
|
+ elemento = elemento.find('.payslip-utility-add-faults');
|
|
|
+
|
|
|
+ openerp.widgetInstance.appendTo(elemento);
|
|
|
+ openerp.widgetInstance.updateId(record.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+})();
|