|
@@ -12,15 +12,19 @@
|
|
|
bankStatement: [],
|
|
|
accountJournal :[],
|
|
|
statementOpen: [],
|
|
|
-
|
|
|
+
|
|
|
+ statementConfig: [],
|
|
|
+ resUser: [],
|
|
|
+ statementUser: [],
|
|
|
|
|
|
init: function(parent) {
|
|
|
this._super(parent);
|
|
|
this.buttons = parent.$buttons;
|
|
|
},
|
|
|
+
|
|
|
|
|
|
start: function () {
|
|
|
- var self = this;
|
|
|
+ var self = this
|
|
|
this.$el.click(function() {
|
|
|
self.fetchInitial();
|
|
|
});
|
|
@@ -39,42 +43,87 @@
|
|
|
self.$el.css('display','flex');
|
|
|
});
|
|
|
},
|
|
|
+
|
|
|
|
|
|
updateId: function(id) {
|
|
|
var self = this;
|
|
|
self.id = id;
|
|
|
},
|
|
|
+
|
|
|
|
|
|
reloadPage: function() {
|
|
|
openerp.parentInstanceStatementTransfer.reload();
|
|
|
},
|
|
|
+
|
|
|
|
|
|
removeModal: function() {
|
|
|
$('.expired-account-modal').remove();
|
|
|
$('.modal-backdrop').remove();
|
|
|
},
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ fetchGetUserLogin: function(){
|
|
|
+ var bankStatementUser = new instanceWeb.Model('account.bank.statement');
|
|
|
+ return bankStatementUser.call('eiru_transfers_get_user', {
|
|
|
+ context: new instanceWeb.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchStatementConfigTransfer: function() {
|
|
|
+ var fields = ['id','name','transfer_user_ids','transfer_statement_ids','transfer_negative_amount'];
|
|
|
+ var domain = [['active', '=', true]];
|
|
|
+ var statementConfig = new openerp.web.Model('account.bank.statement.config');
|
|
|
+ return statementConfig.query(fields).filter(domain).all();
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
fetchInitial: function() {
|
|
|
var self = this;
|
|
|
self.fetchBankStatement(self.id).then(function(bankStatement) {
|
|
|
return bankStatement;
|
|
|
}).then(function(bankStatement) {
|
|
|
self.bankStatement = bankStatement;
|
|
|
- if (!bankStatement || !bankStatement.length)
|
|
|
- return false;
|
|
|
+ return self.fetchStatementConfigTransfer();
|
|
|
+ }).then(function(statementConfig){
|
|
|
+ self.statementConfig = statementConfig;
|
|
|
+ return self.fetchGetUserLogin();
|
|
|
+ }).then(function(resUser) {
|
|
|
+ self.resUser = resUser;
|
|
|
+ if (!!self.statementConfig.length && !!self.resUser.length && !!self.bankStatement.length) {
|
|
|
+ var statementConfig = self.statementConfig[0];
|
|
|
+ var resUser = self.resUser[0];
|
|
|
+ var statementUser = self.bankStatement[0];
|
|
|
+
|
|
|
+ if (!(_.contains(statementConfig.transfer_statement_ids, statementUser.typeStatement))) {
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "El tipo caja no tiene permiso para realizar transferencia.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!(_.contains(statementConfig.transfer_user_ids, resUser.id))) {
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "El usuario no tiene permiso para realizar transferencia.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (bankStatement[0].amount <= 0) {
|
|
|
- instanceWeb.notification.do_warn("Atencion", "La caja seleccionada no tiene saldo disponible.");
|
|
|
- return false;
|
|
|
+ if (self.bankStatement[0].amount <= 0) {
|
|
|
+ if (!self.statementConfig.length){
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "La caja seleccionada no tiene saldo disponible.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!self.statementConfig[0].transfer_negative_amount){
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "La caja seleccionada no tiene saldo disponible.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
self.fetchAccountJournal(self.id).then(function(accountJournal) {
|
|
|
return accountJournal;
|
|
|
}).then(function(accountJournal) {
|
|
|
self.accountJournal = accountJournal;
|
|
|
if (!accountJournal[0].statementJournal.length){
|
|
|
- instanceWeb.notification.do_warn("Atencion", "No tienes ninguna caja chica abierta.");
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "No tienes ninguna caja abierta.");
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
return self.showModalTransfer();
|
|
|
});
|
|
|
});
|
|
@@ -130,7 +179,7 @@
|
|
|
var statementAmount = $('.expired-account-modal').find('.statement-amount');
|
|
|
var statementAmountSymbol = $('.expired-account-modal').find('.statement-amount-symbol');
|
|
|
var selectedJournal = $('.expired-account-modal').find('.selected-Journal');
|
|
|
- var statementOpen = $('.expired-account-modal').find('.statement-open');
|
|
|
+ var statementOpen = $('.expired-account-modal').find('.statement-open-selected');
|
|
|
var amountTransfer = $('.expired-account-modal').find('.amount-transfer');
|
|
|
var amountTransferSymbol = $('.expired-account-modal').find('.amount-transfer-symbol');
|
|
|
var refTransfer = $('.expired-account-modal').find('.ref-transfer');
|
|
@@ -169,14 +218,15 @@
|
|
|
|
|
|
amountTransfer.focusout(function(e) {
|
|
|
var amountAvailable = accounting.unformat(statementAmount.val(),currency.decimalSeparator);
|
|
|
- var amount = accounting.unformat(amountTransfer.val(),currency.decimalSeparator);
|
|
|
+ var amount = Math.abs(accounting.unformat(amountTransfer.val(),currency.decimalSeparator));
|
|
|
|
|
|
- if (amountAvailable < amount) {
|
|
|
+ if (amountAvailable < amount && !self.statementConfig[0].transfer_negative_amount) {
|
|
|
instanceWeb.notification.do_warn("Atencion", "El valor a transferir supera el saldo disponible de la caja .");
|
|
|
amountTransfer.css('border-color','red');
|
|
|
amountTransfer.focus();
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
amountTransfer.val(accounting.formatNumber( amount,currency.decimalPlaces, currency.thousandsSeparator, currency.decimalSeparator));
|
|
|
});
|
|
|
|
|
@@ -209,11 +259,20 @@
|
|
|
amountTransfer.focus();
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
if (amountAvailable < amount) {
|
|
|
- instanceWeb.notification.do_warn("Atencion", "El valor a transferir supera el saldo disponible de la caja .");
|
|
|
- amountTransfer.css('border-color','red');
|
|
|
- amountTransfer.focus();
|
|
|
- return false;
|
|
|
+ if (!self.statementConfig.length){
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "El valor a transferir supera el saldo disponible de la caja .");
|
|
|
+ amountTransfer.css('border-color','red');
|
|
|
+ amountTransfer.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!self.statementConfig[0].transfer_negative_amount){
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "El valor a transferir supera el saldo disponible de la caja .");
|
|
|
+ amountTransfer.css('border-color','red');
|
|
|
+ amountTransfer.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
amountTransfer.css('border-color','#ccc');
|
|
|
|