|  | @@ -0,0 +1,300 @@
 | 
	
		
			
				|  |  | +(function() {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    openerp.widgetInstanceStatementLineUnlink = null;
 | 
	
		
			
				|  |  | +    openerp.parentInstanceStatementLineUnlink = {};
 | 
	
		
			
				|  |  | +    var QWeb = openerp.web.qweb;
 | 
	
		
			
				|  |  | +    var instanceWeb = openerp.web;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    openerp.EiruStatementLineUnlink = openerp.Widget.extend({
 | 
	
		
			
				|  |  | +        template: 'EiruStatementUtility.LineUnlink',
 | 
	
		
			
				|  |  | +        id: undefined,
 | 
	
		
			
				|  |  | +        buttons: undefined,
 | 
	
		
			
				|  |  | +        bankStatement: [],
 | 
	
		
			
				|  |  | +        resUser: [],
 | 
	
		
			
				|  |  | +        statementConfig: [],
 | 
	
		
			
				|  |  | +        cashBoxTransfer: [],
 | 
	
		
			
				|  |  | +        /* init */
 | 
	
		
			
				|  |  | +        init: function(parent) {
 | 
	
		
			
				|  |  | +            this._super(parent);
 | 
	
		
			
				|  |  | +            this.buttons = parent.$buttons;
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        /* start */
 | 
	
		
			
				|  |  | +        start: function () {
 | 
	
		
			
				|  |  | +            var self = this
 | 
	
		
			
				|  |  | +            this.$el.click(function() {
 | 
	
		
			
				|  |  | +                // self.fetchInitial();
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            self.buttons.click(function(e) {
 | 
	
		
			
				|  |  | +                /* C (Crear) */
 | 
	
		
			
				|  |  | +                if (e.target.accessKey === 'C')
 | 
	
		
			
				|  |  | +                    self.$el.css('display','none');
 | 
	
		
			
				|  |  | +                /* E (Editar) */
 | 
	
		
			
				|  |  | +                if (e.target.accessKey === 'E')
 | 
	
		
			
				|  |  | +                    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');
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        /* Actualizar Id de la visat actual  */
 | 
	
		
			
				|  |  | +        updateId: function(id) {
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            self.id = id;
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        /* Reload Page*/
 | 
	
		
			
				|  |  | +        reloadPage: function() {
 | 
	
		
			
				|  |  | +             openerp.parentInstanceStatementLineUnlink.reload();
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        /* Description: Función para remover el modal */
 | 
	
		
			
				|  |  | +        removeModal: function() {
 | 
	
		
			
				|  |  | +            $('.expired-account-modal').remove();
 | 
	
		
			
				|  |  | +            $('.modal-backdrop').remove();
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        /*Get User*/
 | 
	
		
			
				|  |  | +        fetchGetUserLogin: function(){
 | 
	
		
			
				|  |  | +            var bankStatementUser = new instanceWeb.Model('account.bank.statement');
 | 
	
		
			
				|  |  | +            return bankStatementUser.call('eiru_transfers_get_user', {
 | 
	
		
			
				|  |  | +                context: new instanceWeb.CompoundContext()
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        /* statement Config */
 | 
	
		
			
				|  |  | +        fetchStatementConfigTransfer: function() {
 | 
	
		
			
				|  |  | +            var fields = ['id', 'name', 'delete_transfer_user_ids'];
 | 
	
		
			
				|  |  | +            var domain = [['active', '=', true]];
 | 
	
		
			
				|  |  | +            var statementConfig = new openerp.web.Model('account.bank.statement.config');
 | 
	
		
			
				|  |  | +            return statementConfig.query(fields).filter(domain).all();
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        /* Método inicial */
 | 
	
		
			
				|  |  | +        fetchInitial: function() {
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            self.fetchBankStatement(self.id).then(function(bankStatement) {
 | 
	
		
			
				|  |  | +                return bankStatement;
 | 
	
		
			
				|  |  | +            }).then(function(bankStatement) {
 | 
	
		
			
				|  |  | +                self.bankStatement = bankStatement;
 | 
	
		
			
				|  |  | +                return self.fetchStatementConfigTransfer();
 | 
	
		
			
				|  |  | +            }).then(function(statementConfig){
 | 
	
		
			
				|  |  | +                self.statementConfig = statementConfig;
 | 
	
		
			
				|  |  | +                return self.fetchGetUserLogin();
 | 
	
		
			
				|  |  | +            }).then(function(resUser) {
 | 
	
		
			
				|  |  | +                self.resUser = resUser;
 | 
	
		
			
				|  |  | +                if (!self.statementConfig.length){
 | 
	
		
			
				|  |  | +                    instanceWeb.notification.do_warn("Atencion", "No estas autorizado a realizar esta operación, no existe configuración de caja.");
 | 
	
		
			
				|  |  | +                    return  false;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (!self.resUser.length){
 | 
	
		
			
				|  |  | +                    instanceWeb.notification.do_warn("Atencion", "No estas autorizado a realizar esta operación.");
 | 
	
		
			
				|  |  | +                    return  false;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (!self.bankStatement.length) {
 | 
	
		
			
				|  |  | +                    instanceWeb.notification.do_warn("Atencion", "No estas autorizado a realizar esta operación.");
 | 
	
		
			
				|  |  | +                    return  false;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (!(_.contains(self.statementConfig[0].delete_transfer_user_ids, self.resUser[0].id))){
 | 
	
		
			
				|  |  | +                    instanceWeb.notification.do_warn("Atencion", "El usuario no tiene autorización para eliminar las transferencia.");
 | 
	
		
			
				|  |  | +                    return false;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                self.fetchCashBoxTransfer(self.id).then(function(cashBoxTransfer){
 | 
	
		
			
				|  |  | +                    return cashBoxTransfer;
 | 
	
		
			
				|  |  | +                }).then(function(cashBoxTransfer){
 | 
	
		
			
				|  |  | +                    self.cashBoxTransfer = cashBoxTransfer;
 | 
	
		
			
				|  |  | +                    if (!self.cashBoxTransfer.length) {
 | 
	
		
			
				|  |  | +                        instanceWeb.notification.do_warn("Atencion", "La caja no tiene ninguna transferencia.");
 | 
	
		
			
				|  |  | +                        return false;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    return self.showModalTransfer();
 | 
	
		
			
				|  |  | +                })
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        /* Account bank Statement */
 | 
	
		
			
				|  |  | +        fetchBankStatement: function(id) {
 | 
	
		
			
				|  |  | +            var bankStatement = new instanceWeb.Model('account.bank.statement');
 | 
	
		
			
				|  |  | +            return bankStatement.call('get_account_bank_statement_utility',[id], {
 | 
	
		
			
				|  |  | +                context: new instanceWeb.CompoundContext()
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        /* cash_box_transfer*/
 | 
	
		
			
				|  |  | +        fetchCashBoxTransfer: function(id) {
 | 
	
		
			
				|  |  | +            var cashBoxTransfer = new instanceWeb.Model('account.bank.statement');
 | 
	
		
			
				|  |  | +            return cashBoxTransfer.call('eiru_transfers_get_chas_box_transfer',[id], {
 | 
	
		
			
				|  |  | +                context: new instanceWeb.CompoundContext()
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        /*filter line transfer selected*/
 | 
	
		
			
				|  |  | +        filterRowTransfer: function(id){
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            return _.filter(self.cashBoxTransfer, function(item){
 | 
	
		
			
				|  |  | +                return item.id === id;
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        /*Modal  Transfer */
 | 
	
		
			
				|  |  | +        showModalTransfer: function() {
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            var defer =$.Deferred();
 | 
	
		
			
				|  |  | +            var results = true;
 | 
	
		
			
				|  |  | +            var rowSelected = [];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var modal = QWeb.render('ModalStatementUtility.TransferDeleted',{
 | 
	
		
			
				|  |  | +                cashBoxTransfer: self.cashBoxTransfer
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            $('.openerp_webclient_container').after(modal);
 | 
	
		
			
				|  |  | +            $('.expired-account-modal').modal();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var statementOutput = $('.expired-account-modal').find('.statement-output');
 | 
	
		
			
				|  |  | +            var statementInput = $('.expired-account-modal').find('.statement-input');
 | 
	
		
			
				|  |  | +            var transferRef = $('.expired-account-modal').find('.transfer-ref');
 | 
	
		
			
				|  |  | +            var transferAmount = $('.expired-account-modal').find('.transfer-amount');
 | 
	
		
			
				|  |  | +            var transferAmountSymbol = $('.expired-account-modal').find('.transfer-amount-symbol');
 | 
	
		
			
				|  |  | +            var refTransferDeleted = $('.expired-account-modal').find('.ref-transfer-deleted');
 | 
	
		
			
				|  |  | +            /* Table */
 | 
	
		
			
				|  |  | +            var tableRow = $('.expired-account-modal').find('.table-tbody').find('tr');
 | 
	
		
			
				|  |  | +            var buttonDeleted = $('.expired-account-modal').find('.button-deleted')
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            buttonDeleted.attr("disabled", true);
 | 
	
		
			
				|  |  | +            refTransferDeleted.attr("disabled", true);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            /* Seleccionar  fila */
 | 
	
		
			
				|  |  | +            tableRow.click(function (e) {
 | 
	
		
			
				|  |  | +                row_export = $(e.target);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                buttonDeleted.attr("disabled", true);
 | 
	
		
			
				|  |  | +                refTransferDeleted.attr("disabled", true);
 | 
	
		
			
				|  |  | +                tableRow.removeClass('table-row-select');
 | 
	
		
			
				|  |  | +                $(e.target).closest('tr').addClass('table-row-select');
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                var idRow = parseInt(($(e.target).closest('tr').children()[0].textContent).trim())
 | 
	
		
			
				|  |  | +                rowSelected = self.filterRowTransfer(idRow).shift();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                statementOutput.val('')
 | 
	
		
			
				|  |  | +                statementInput.val('')
 | 
	
		
			
				|  |  | +                transferRef.val('')
 | 
	
		
			
				|  |  | +                transferAmount.val(0)
 | 
	
		
			
				|  |  | +                transferAmountSymbol.text("")
 | 
	
		
			
				|  |  | +                refTransferDeleted.val('')
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (!rowSelected){
 | 
	
		
			
				|  |  | +                    tableRow.removeClass('table-row-select');
 | 
	
		
			
				|  |  | +                    return false;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if ( rowSelected.outputStatement.typeJournal === 'cash' ) {
 | 
	
		
			
				|  |  | +                    if (rowSelected.outputStatement.state !== 'open') {
 | 
	
		
			
				|  |  | +                        instanceWeb.notification.do_warn("Atencion", "No podes continuar con esa operación, la caja origen no esta abierta");
 | 
	
		
			
				|  |  | +                        tableRow.removeClass('table-row-select');
 | 
	
		
			
				|  |  | +                        return false;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if (rowSelected.inputStatement.state !== 'open')  {
 | 
	
		
			
				|  |  | +                        instanceWeb.notification.do_warn("Atencion", "No podes continuar con esa operación, la caja destino no esta abierta");
 | 
	
		
			
				|  |  | +                        tableRow.removeClass('table-row-select');
 | 
	
		
			
				|  |  | +                        return false;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if ( rowSelected.outputStatement.typeJournal === 'bank' ){
 | 
	
		
			
				|  |  | +                    if (rowSelected.outputStatement.state === 'confirm'){
 | 
	
		
			
				|  |  | +                        instanceWeb.notification.do_warn("Atencion", "No podes continuar con esa operación, la caja origen no esta abierta");
 | 
	
		
			
				|  |  | +                        tableRow.removeClass('table-row-select');
 | 
	
		
			
				|  |  | +                        return false;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if (rowSelected.inputStatement.state === 'confirm') {
 | 
	
		
			
				|  |  | +                        instanceWeb.notification.do_warn("Atencion", "No podes continuar con esa operación, la caja destino no esta abierta");
 | 
	
		
			
				|  |  | +                        tableRow.removeClass('table-row-select');
 | 
	
		
			
				|  |  | +                        return false;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                statementOutput.val(rowSelected.outputStatement.name)
 | 
	
		
			
				|  |  | +                statementInput.val(rowSelected.inputStatement.name)
 | 
	
		
			
				|  |  | +                transferRef.val(rowSelected.ref)
 | 
	
		
			
				|  |  | +                transferAmount.val(accounting.formatNumber(rowSelected.amount, rowSelected.outputStatement.currency.decimalPlaces, rowSelected.outputStatement.currency.thousandsSeparator,rowSelected.outputStatement.currency.decimalSeparator))
 | 
	
		
			
				|  |  | +                transferAmountSymbol.text(rowSelected.outputStatement.currency.symbol)
 | 
	
		
			
				|  |  | +                refTransferDeleted.val('')
 | 
	
		
			
				|  |  | +                buttonDeleted.removeAttr("disabled");
 | 
	
		
			
				|  |  | +                refTransferDeleted.removeAttr("disabled");
 | 
	
		
			
				|  |  | +                refTransferDeleted.focus();
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            buttonDeleted.click(function(e) {
 | 
	
		
			
				|  |  | +                if (!refTransferDeleted.val()) {
 | 
	
		
			
				|  |  | +                    instanceWeb.notification.do_warn("Atencion", "Debes ingresar un motivo para continuar.");
 | 
	
		
			
				|  |  | +                    refTransferDeleted.css('border-color','red');
 | 
	
		
			
				|  |  | +                    refTransferDeleted.focus();
 | 
	
		
			
				|  |  | +                    return false;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                refTransferDeleted.css('border-color','#ccc');
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (!rowSelected){
 | 
	
		
			
				|  |  | +                    instanceWeb.notification.do_warn("Atencion", "Debes seleccionar una transferencia para continuar.");
 | 
	
		
			
				|  |  | +                    tableRow.focus()
 | 
	
		
			
				|  |  | +                    return false;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                var unlinkTransfer ={
 | 
	
		
			
				|  |  | +                    'statementId': self.id,
 | 
	
		
			
				|  |  | +                    'transferId': rowSelected.id,
 | 
	
		
			
				|  |  | +                    'comment': !!refTransferDeleted.val() ? refTransferDeleted.val() : ''
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                self.unlinkTransfer(unlinkTransfer).then(function(transfer){
 | 
	
		
			
				|  |  | +                    return transfer;
 | 
	
		
			
				|  |  | +                }).then(function(transfer){
 | 
	
		
			
				|  |  | +                    self.reloadPage();
 | 
	
		
			
				|  |  | +                    self.removeModal(e);
 | 
	
		
			
				|  |  | +                    if (!transfer)
 | 
	
		
			
				|  |  | +                        results = false;
 | 
	
		
			
				|  |  | +                })
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                defer.resolve(results);
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            /* Click Cerrar */
 | 
	
		
			
				|  |  | +            $('.expired-account-modal').on('hidden.bs.modal', function(e) {
 | 
	
		
			
				|  |  | +                results = false;
 | 
	
		
			
				|  |  | +                defer.resolve(results);
 | 
	
		
			
				|  |  | +                self.removeModal(e);
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            return defer;
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        /* Unlink transfer */
 | 
	
		
			
				|  |  | +        unlinkTransfer: function(values){
 | 
	
		
			
				|  |  | +            var bankStatementTransfer = new instanceWeb.Model('account.bank.statement');
 | 
	
		
			
				|  |  | +            return bankStatementTransfer.call('unlink_transfer',[values], {
 | 
	
		
			
				|  |  | +                context: new instanceWeb.CompoundContext()
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    if (openerp.web && openerp.web.FormView) {
 | 
	
		
			
				|  |  | +        openerp.web.FormView.include({
 | 
	
		
			
				|  |  | +            load_record: function(record) {
 | 
	
		
			
				|  |  | +                this._super.apply(this, arguments);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (this.model !== 'account.bank.statement')
 | 
	
		
			
				|  |  | +                    return;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                openerp.parentInstanceStatementLineUnlink = this;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (openerp.widgetInstanceStatementLineUnlink) {
 | 
	
		
			
				|  |  | +                    openerp.widgetInstanceStatementLineUnlink.updateId(record.id);
 | 
	
		
			
				|  |  | +                    if (this.$el.find('.button-statement-line-unlink').length !== 0 )
 | 
	
		
			
				|  |  | +                        return ;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (this.$el.find('.button-statement-line-unlink').length !== 0 )
 | 
	
		
			
				|  |  | +                    return;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                openerp.widgetInstanceStatementLineUnlink = new openerp.EiruStatementLineUnlink(this);
 | 
	
		
			
				|  |  | +                var element =this.$el.find('.oe_form').find('.eiru-statement-utility');
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                openerp.widgetInstanceStatementLineUnlink.appendTo(element[0]);
 | 
	
		
			
				|  |  | +                openerp.widgetInstanceStatementLineUnlink.updateId(record.id);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +})();
 |