Browse Source

Modulo para registrar pagos desde facturas.

sebas 3 years ago
commit
7f123d613a

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+*.pyc

+ 3 - 0
README.md

@@ -0,0 +1,3 @@
+# Eiru payments invoices
+
+Modulo para registrar pagos y cobro desde la factura de cliente o proveedor.

+ 2 - 0
__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+import models

+ 22 - 0
__openerp__.py

@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+{
+    'name': 'Eiru payments invoices',
+    'author': 'Adrielso Kunert Bueno',
+    'category': 'Account',
+    'version': '1.1.0',
+    'depends': [
+        'base',
+        'account',
+        'currency_utility',
+        'account_voucher_comment',
+        'eiru_invoiceid_voucher',
+    ],
+    'data': [
+        'views/templates.xml',
+        'views/eiru_payments_invoices.xml',
+    ],
+    'qweb': [
+        'static/src/xml/*.xml',
+        'static/src/xml/modal/*.xml',
+    ],
+}

+ 2 - 0
models/__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+import account_invoices

+ 527 - 0
models/account_invoices.py

@@ -0,0 +1,527 @@
+# -*- coding: utf-8 -*-
+from openerp import models, fields, tools, api
+from datetime import datetime
+from pytz import timezone
+import simplejson
+
+DATE_FORMAT = '%Y-%m-%d'
+
+class AccountInvoice(models.Model):
+    _inherit = 'account.invoice'
+
+    '''
+        Get Move Line Customer
+    '''
+    def get_move_line_credit(self, invoice):
+        decimal_precision = self.env['decimal.precision'].precision_get('Account')
+        if (not invoice):
+            return false
+
+        return [{
+            'id': line.id,
+            'amountResidual': line.amount_residual,
+            'credit': line.credit,
+            'debit': line.debit,
+            'dateMaturity': line.date_maturity,
+            'invoice': invoice.id,
+            'amountCurrency': line.amount_currency if line.amount_currency > 0 else line.debit,
+            'amountResidualCurrency': line.amount_residual_currency,
+            'currencyAmount': [{
+                'id': currency.id,
+                'displayName': currency.display_name,
+                'symbol': currency.symbol,
+                'rateSilent': currency.rate_silent,
+                'rate': currency.rate,
+                'thousandsSeparator': currency.thousands_separator,
+                'decimalSeparator': currency.decimal_separator,
+                'decimalPlaces': currency.decimal_places,
+                'position': currency.position,
+                'base': currency.base,
+                'accuracy': currency.accuracy,
+                'rounding': currency.rounding,
+                'amountCurencyResidual': round((line.amount_residual_currency * (currency.rate_silent / invoice.currency_id.rate_silent)), decimal_precision)
+            } for currency in self.env['res.currency'].search([('active', '=', True)])]
+        } for line in invoice.move_id.line_id.sorted(key=lambda r: r.id) if (line.amount_residual > 0 and line.state != "draft" and line.credit <= 0)]
+
+    '''
+        Get Currency paymsntes
+    '''
+    @api.model
+    def get_currency_payments_invoices(self):
+        return [{
+            'id': currency.id,
+            'name': currency.name,
+            'symbol': currency.symbol,
+            'rate_silent': currency.rate_silent,
+            'base': currency.base,
+            'decimalSeparator': currency.decimal_separator,
+            'decimalPlaces': currency.decimal_places,
+            'thousandsSeparator': currency.thousands_separator,
+            'symbolPosition': currency.symbol_position,
+            'rate': currency.rate
+        } for currency in self.env['res.currency'].search([('active','=', True)])]
+
+    '''
+        Get Move Line supplier
+    '''
+    def get_move_line_debit(self, invoice):
+        decimal_precision = self.env['decimal.precision'].precision_get('Account')
+        if (not invoice):
+            return false
+
+        return [{
+            'id': line.id,
+            'amountResidual': line.amount_residual,
+            'credit': line.credit,
+            'debit': line.debit,
+            'dateMaturity': line.date_maturity,
+            'invoice': invoice.id,
+            'amountCurrency': abs(line.amount_currency) if (abs(line.amount_currency) > 0) else line.credit,
+            'amountResidualCurrency': line.amount_residual_currency,
+            'currencyAmount': [{
+                'id': currency.id,
+                'displayName': currency.display_name,
+                'symbol': currency.symbol,
+                'rateSilent': currency.rate_silent,
+                'rate': currency.rate,
+                'thousandsSeparator': currency.thousands_separator,
+                'decimalSeparator': currency.decimal_separator,
+                'decimalPlaces': currency.decimal_places,
+                'position': currency.position,
+                'base': currency.base,
+                'accuracy': currency.accuracy,
+                'rounding': currency.rounding,
+                'amountCurencyResidual': round((line.amount_residual_currency * (currency.rate / invoice.currency_id.rate)), decimal_precision)
+            } for currency in self.env['res.currency'].search([('active', '=', True)])]
+        } for line in invoice.move_id.line_id.sorted(key=lambda r: r.id) if (line.amount_residual > 0 and line.state != "draft" and line.debit <= 0)]
+
+    '''
+        Get Move Line
+    '''
+    @api.model
+    def get_moveline_invoice(self, id):
+        accountInvoice = self.env['account.invoice'].browse(id)
+        if (not accountInvoice):
+            return False
+
+        if (accountInvoice.type in ('out_invoice', 'in_refund')):
+            return self.get_move_line_credit(accountInvoice)
+        if (accountInvoice.type in ('out_refund', 'in_invoice')):
+            return self.get_move_line_debit(accountInvoice)
+
+    @api.model
+    def get_bank_payments(self):
+        resBankPayments = []
+        for bankPayments in self.env['res.bank.payments'].search([('bank_payments_type_id.code', '!=', 'TJ')], order='id'):
+            amountReceipt = 0
+            amountPayment = 0
+            amountBalance = 0
+            amountCashed = 0
+            amountRenegotiated = 0
+
+            for line in bankPayments.payments_line:
+                amountReceipt +=  line.type_operation in ('receipt') and line.amount or 0
+                amountPayment += line.type_operation in ('payment') and line.amount or 0
+                amountBalance += line.type_operation in ('balance') and line.amount or 0
+                amountCashed += line.type_operation in ('cashed') and line.amount or 0
+                amountRenegotiated += line.type_operation in ('renegotiated') and line.amount or 0
+
+            resBankPayments.append({
+                'id': bankPayments.id,
+                'number': bankPayments.number,
+                'amountTotal': bankPayments.amount_total,
+                'dateMaturity': bankPayments.date_maturity,
+                'bankId': bankPayments.bank_id.id,
+                'bankPaymentsTypeId': bankPayments.bank_payments_type_id.id,
+                'numberCta': bankPayments.number_cta,
+                'nameHolder': bankPayments.name_holder,
+                'state': bankPayments.state,
+                'amountReceipt': amountReceipt,
+                'amountPayment': amountPayment,
+                'amountBalance': amountBalance,
+                'amountCashed': amountCashed,
+                'amountRenegotiated': amountRenegotiated,
+                'chequeTypeId': bankPayments.cheque_type_id.id
+            });
+
+        return resBankPayments
+
+    '''
+        Get User
+    '''
+    @api.model
+    def get_user_login(self):
+        return [{
+            'id': user.id,
+            'name': user.name
+        } for user in self.env.user]
+
+    '''
+        get Statement
+    '''
+    @api.model
+    def get_statement(self):
+        BankStatement = []
+        for statement in self.env['account.bank.statement'].search([('state','!=','confirm'),('user_id','=',self.env.user.id)]):
+
+            if (statement.journal_id.type == 'cash' and statement.state =='draft'):
+                continue
+
+            BankStatement.append({
+                'id': statement.id,
+                'name': statement.name,
+                'journalID': statement.journal_id.id,
+                'userId': statement.user_id.id,
+                'date': statement.date,
+                'createDate': statement.create_date,
+                'periodId': statement.period_id.id,
+                'state': statement.state,
+                'journalType': statement.journal_id.type
+            })
+
+        return BankStatement
+
+
+    '''
+        Get All res_bank_payments_type.
+    '''
+    @api.model
+    def get_bank_payment_type(self):
+        self.env.cr.execute("SELECT id FROM res_bank_payments_type")
+        return [{
+            'id': line.id,
+            'name': line.name,
+            'code': line.code,
+            'journal_ids': map(lambda x: x.id, line.journal_ids),
+            'allow_duplicate_operation': line.allow_duplicate_operation,
+            'fields_allowed': simplejson.loads(line.fields_allowed)
+        }for line in self.env['res.bank.payments.type'].browse(map(lambda x: x['id'], self.env.cr.dictfetchall()))]
+
+    '''
+        GET account interest line
+    '''
+    @api.model
+    def eiru_payments_account_interest_line(self,moveLine):
+        return [{
+            'id': line.id,
+            'amountInterest': line.amount_interest,
+            'expiredDays': line.expired_days,
+            'state': line.state,
+            'moveLineId': line.move_line_id.id,
+            'invoice': [{
+                'id': accountInvoice.id,
+                'number': accountInvoice.number,
+                'state': accountInvoice.state,
+            } for accountInvoice in self.env['account.invoice'].browse(line.invoice.id)],
+            'interest': [{
+                'id': line.interest_id.id,
+                'name': line.interest_id.name,
+                'state': line.interest_id.state,
+            } for interest in self.env['account.interest'].browse(line.interest_id.id)],
+        } for line in self.env['account.interest.line'].search([('move_line_id.id', 'in', moveLine)])]
+
+    '''
+          ____                    ____                                  _
+         / ___|  __ ___   _____  |  _ \ __ _ _   _ _ __ ___   ___ _ __ | |_ ___
+         \___ \ / _` \ \ / / _ \ | |_) / _` | | | | '_ ` _ \ / _ \ '_ \| __/ __|
+          ___) | (_| |\ V /  __/ |  __/ (_| | |_| | | | | | |  __/ | | | |_\__ \
+         |____/ \__,_| \_/ \___| |_|   \__,_|\__, |_| |_| |_|\___|_| |_|\__|___/
+                                             |___/
+    '''
+    '''
+        check_module Installed
+    '''
+    def check_module(self, module_name):
+        '''
+            Método para verificar si los modulo están instalado
+            :param module_name : Nombre del moduloself.
+            :return:  True 'Modulo instalado', False 'no instalado'
+        '''
+        module = self.env['ir.module.module'].search([('name', '=', module_name), ('state', '=', 'installed')])
+        return len(module) != 0
+    '''
+        Get invoice
+    '''
+    def get_invoice(self, invoiceId):
+        return self.env['account.invoice'].browse(invoiceId)
+
+    '''
+        Get Period
+    '''
+    def get_period(self, date_server):
+        return self.env['account.period'].search([('date_start','<=', date_server), ('date_stop', '>=', date_server)])
+
+    '''
+        Get timezone
+    '''
+    def get_timezone(self):
+        tz_name = self._context.get('tz') or self.env.user.tz
+        return timezone(tz_name)
+
+    '''
+        Get server date
+    '''
+    def get_server_datetime(self):
+        return datetime.now(self.get_timezone()).strftime(DATE_FORMAT)
+
+    '''
+        get Statement Config
+    '''
+    def getStatementConfig(self, id):
+        return self.env['account.bank.statement.config'].browse(id)
+
+    '''
+        Create Voucher
+    '''
+    def create_voucher_invoice(self, period, invoice, company_id, amountPayments, date_server, journalId, move_line_Ids, customerId, voucherName, voucherObs, voucherSeq):
+        ## Get Journal
+        journal_id = self.env['account.journal'].browse(int(journalId))
+        currency_id = journal_id.default_credit_account_id.currency_id.id or journal_id.default_credit_account_id.company_currency_id.id
+        # Get Move Lines
+        move_line = self.env['account.move.line'].browse(move_line_Ids).sorted(key=lambda r: r.id)
+        ### res.partner
+        customerId = self.env['res.partner']._find_accounting_partner(invoice.partner_id)
+        ### decimal.precision
+        decimal_precision = self.env['decimal.precision'].precision_get('Account')
+        ### Currencies (company/ Journal)
+        company_currency = self.env.user.company_id.currency_id
+        currencyVocuher = self.env['res.currency'].browse(currency_id)
+        ### Create Line  Voucher   'seq_invoice': invoice.seq_invoice
+        line_ids = []
+        amount = round(float(amountPayments), decimal_precision)
+
+        for line in move_line:
+            amount_residual = line.amount_residual
+            if (company_currency.id != currencyVocuher.id):
+                amount_residual = round((amount_residual * (currencyVocuher.rate / company_currency.rate)), decimal_precision)
+
+            line_ids.append([0, False, {
+                'date_due': line.date_maturity,
+                'account_id': line.account_id.id,
+                'date_original': line.move_id.date,
+                'move_line_id': line.id,
+                'amount_original': abs(line.credit or line.debit or 0.0),
+                'amount_unreconciled': abs(line.amount_residual),
+                'amount':  min(abs(amount), abs(amount_residual)),
+                'reconcile': True if abs(amount_residual) == min(abs(amount), abs(amount_residual)) else False,
+                'currency_id': currency_id
+            }])
+            amount -= min(abs(amount), amount_residual)
+
+
+        amountResidual = round(float(amountPayments), decimal_precision)
+        values = {
+                'name': voucherName,
+                'reference': invoice.number,
+                'type': invoice.type in ('out_invoice','out_refund') and 'receipt' or 'payment',
+                'journal_id': journal_id.id,
+                'company_id': company_id,
+                'pre_line': True,
+                'amount': invoice.type in ('out_refund', 'in_refund') and -amountResidual or amountResidual,
+                'period_id': period.id,
+                'date': date_server,
+                'partner_id': customerId.id,
+                'account_id': journal_id.default_credit_account_id.id,
+                'currency_id': currency_id,
+                'line_cr_ids': invoice.type in ('out_invoice', 'in_refund') and line_ids or [],
+                'line_dr_ids': invoice.type in ('out_refund', 'in_invoice') and line_ids or [],
+                'payment_rate_currency_id': currency_id,
+                'comment_obs': voucherObs,
+                'seq_invoice': voucherSeq
+            }
+        account_voucher = self.env['account.voucher'].create(values)
+        account_voucher.action_move_line_create()
+
+        if (not account_voucher.name):
+            account_voucher.write({'name': account_voucher.number})
+
+        return account_voucher
+
+    '''
+        Change State invoice
+    '''
+    def close_status_invoice(self, invoiceid):
+        invoice = self.env['account.invoice'].search([('id', '=', invoiceid)])
+
+        if invoice.residual <= 0:
+            invoice.confirm_paid()
+        return invoice
+
+    '''
+        Create bank Statement
+    '''
+    def create_bank_statement(self, date_server, user_id, account_voucher, statementId):
+        domain = [('journal_id', '=', account_voucher.journal_id.id),('user_id', '=', user_id)]
+        if (statementId):
+            domain.append(('id', '=', statementId))
+        else:
+            domain.append(('date', '=', date_server))
+
+        bank_statement = self.env['account.bank.statement'].search(domain)
+
+        bank = {
+            'journal_id': account_voucher.journal_id.id,
+            'period_id': account_voucher.period_id.id,
+            'date': date_server,
+            'user_id': user_id,
+            'state': 'open' if account_voucher.journal_id.type == 'cash' else 'draft',
+        }
+        bankStatement = bank_statement
+
+        if bank_statement:
+            if len(bank_statement) != 1:
+                bankStatement = bank_statement[len(bank_statement) -1]
+            bankStatement.button_open()
+        else:
+            bankStatement = bank_statement.create(bank)
+
+        return bankStatement
+
+    '''
+        Create Statamente Line
+    '''
+    def create_bank_statement_line(self, account_voucher, statement):
+        ### Create line bank
+        bank_statement_line = {
+            'name': account_voucher.reference,
+            'partner_id': account_voucher.partner_id.id,
+            'amount': account_voucher.type in ('payment') and  -account_voucher.amount or account_voucher.amount,
+            'voucher_id': account_voucher.id,
+            'journal_id': account_voucher.journal_id.id,
+            'account_id': account_voucher.account_id.id,
+            'journal_entry_id': account_voucher.move_id.id,
+            'currency_id': account_voucher.currency_id.id,
+            'ref': 'NP',
+            'statement_id': statement.id
+        }
+        line_id = self.env['account.bank.statement.line'].create(bank_statement_line)
+
+        return line_id
+
+    '''
+        Bank Line
+    '''
+    def create_bank_paymnets(self, account_voucher, date_server, invoice, bankPayments):
+        bankId = []
+        bankPaymentsType = []
+        bankChequeType = []
+        amountTotal = 0
+        for valor in bankPayments:
+            if (valor == 'bank_id'):
+                bankId = self.env['res.bank'].browse(bankPayments[valor])
+
+            if (valor == 'bank_payments_type_id'):
+                bankPaymentsType = self.env['res.bank.payments.type'].browse(bankPayments[valor])
+
+            if (valor == 'cheque_type_id'):
+                bankChequeType = self.env['res.bank.cheque.type'].browse(bankPayments[valor])
+
+            if(valor == 'amount_total'):
+                amountTotal = bankPayments[valor]
+
+        bankPayments['date'] = date_server
+        bankPayments['state'] = bankPaymentsType.default_state
+        bankPayments['comment'] = 'Np'
+        bankPayments['currency_id'] = account_voucher.currency_id.id
+        bankPayments['customer_id'] = invoice.type in ('out_invoice','in_refund') and account_voucher.partner_id.id or ''
+        bankPayments['supplier_id'] = invoice.type in ('in_invoice','out_refund') and account_voucher.partner_id.id or ''
+        bankPayments['amount_total'] = amountTotal if (amountTotal > 0) else account_voucher.amount
+
+
+
+        paymnets_bank = []
+        if (not bankPaymentsType.allow_duplicate_operation):
+            try:
+                number = bankPayments['number']
+                numberCta = bankPayments['number_cta']
+            except Exception as e:
+                number = None
+                numberCta = None
+            paymnets_bank = self.env['res.bank.payments'].search([ ('number', '=', number), ('bank_id', '=', bankId.id), ('number_cta', '=', numberCta)])
+
+        if (paymnets_bank):
+            bankPayments = []
+            # ventas/rectific. compras/gastos
+            if (invoice.type in ('out_invoice','in_refund')):
+                bankPayments = {
+                    'partner_id': invoice.type in ('out_invoice','in_refund') and account_voucher.partner_id.id or ''
+                }
+
+            ## Compras/gastos/rectific. ventas
+            if (invoice.type in ('in_invoice','out_refund')):
+                bankPayments = {
+                    'supplier_id': invoice.type in ('in_invoice','out_refund') and account_voucher.partner_id.id or ''
+                }
+
+            if (bankPayments):
+                paymnets_bank.write(bankPayments)
+
+        else:
+            paymnets_bank = self.env['res.bank.payments'].create(bankPayments)
+
+        return paymnets_bank
+
+    '''
+        Create Bnak Paymnets Line
+    '''
+    def create_bank_paymnets_line(self, voucher, bank_payments, bank_statement_line, bank_statement, date_server, invoice):
+        account_voucher = self.env['account.voucher'].browse(voucher.id)
+        res_bank_payments = self.env['res.bank.payments'].browse(bank_payments.id)
+        statement_line = self.env['account.bank.statement.line'].browse(bank_statement_line.id)
+        statement = self.env['account.bank.statement'].browse(bank_statement.id)
+
+        bank_line = {
+            'amount': abs(account_voucher.amount) ,
+            'date': date_server,
+            'bank_payments_id': res_bank_payments.id,
+            'statement_line_id': bank_statement_line.id,
+            'statement_id': bank_statement.id,
+            'type_operation': invoice.type in ('out_invoice','in_refund') and 'receipt' or 'payment',
+            'amount_currency' : 0.00,
+            'currency_id' : account_voucher.currency_id.id
+        }
+
+        paymnets_line = self.env['res.bank.payments.line'].create(bank_line)
+
+        return paymnets_line
+
+    '''
+        Save payments
+    '''
+    @api.model
+    def save_payments_invoice(self, values):
+        ## Date Server
+        date_server = self.get_server_datetime()
+        ### Usuer
+        resUser = self.env.user.id
+        ### Compania
+        resCompany = self.env.user.company_id.id
+        ### Invoice
+        accountInvoice = self.get_invoice(values['invoiceId'])
+        if (not accountInvoice):
+            return False
+        ### Period
+        accountPeriod = self.get_period(date_server)
+        if (not accountPeriod):
+            return False
+        ### Create.
+        ##### Vocuher.
+        voucher = self.create_voucher_invoice(accountPeriod, accountInvoice, resCompany, values['amountPayments'], values['datePayments'], values['JournalId'], values['moveLines'], values['partnerId'], values['voucherName'], values['voucherObs'], values['voucherSeq'])
+        ### Close invoice.
+        closeInvoice = self.close_status_invoice(values['invoiceId'])
+
+        ### Create bank Statement
+        bank_statement = self.create_bank_statement(date_server, resUser, voucher, values['statementId'])
+        ### Create bank statement Line
+        bank_statement_line = self.create_bank_statement_line(voucher, bank_statement)
+        ### Verify Type Operations 'journal_ids'
+
+        if ((self.check_module('eiru_bank_payments_references')) and (values['JournalType'] == 'bank') and (values['bankPayments'])):
+            typeOperation = self.env['res.bank.payments.type'].search(([('journal_ids', 'in', values['JournalId'])]))
+            if (typeOperation):
+                bank_payments =  self.create_bank_paymnets(voucher, date_server, accountInvoice, values['bankPayments'])
+                bank_payments_Line = self.create_bank_paymnets_line(voucher, bank_payments, bank_statement_line, bank_statement, date_server, accountInvoice)
+
+        return {
+            'process': True
+        }

BIN
static/description/icon.png


+ 249 - 0
static/src/css/style.css

@@ -0,0 +1,249 @@
+.eiru-payments-invoices {
+    width: auto;
+    float: left;
+}
+.payments-invoice-hr {
+    border: 0px;
+    margin-top: 5px;
+    margin-bottom: 5px;
+}
+/* Table  */
+.select-move-payments {
+    height: 20px !important;
+    margin: 0px;
+}
+.payments-invoice-table{
+    margin-top: 0px !important;
+}
+.expired-account-modal  .modal-head-wrapper-payments-invoice {
+    width: 100%;
+}
+.expired-account-modal .modal-item-paymnets-invoice {
+    width: 100%;
+    height: 110px;
+    overflow-y: auto;
+}
+.expired-account-modal .payments-invoice-table table tbody tr {
+    height: 35px;
+}
+.expired-account-modal .payments-invoice-table table thead tr {
+    height: 40px !important;
+}
+/*id*/
+.expired-account-modal .payments-invoice-table table tbody tr td:nth-child(1){
+    display: none;
+}
+.expired-account-modal table thead tr th:nth-child(1){
+    display: none;
+}
+/* checkbox */
+.expired-account-modal .payments-invoice-table table tbody tr td:nth-child(2){
+    width: 33px ;
+}
+.expired-account-modal .payments-invoice-table table thead tr th:nth-child(2){
+    width: 33px;
+}
+/* date-Maturity */
+.expired-account-modal .payments-invoice-table table tbody tr td:nth-child(3){
+    width: 110px;
+    font-size: 12pt;
+    padding-left: 10px;
+    padding-top: 8px;
+}
+.expired-account-modal .payments-invoice-table table thead tr th:nth-child(3){
+    width: 505px;
+    padding-left: 10px;
+    font-size: 14pt;
+    font-weight: bold;
+}
+.expired-account-modal .payments-invoice-table table tbody tr td:nth-child(4){
+    width: 379 ;
+    font-size: 10pt;
+    padding-left: 10px;
+    padding-top: 8px;
+    color: red;
+}
+/* Total */
+.expired-account-modal .payments-invoice-table table tbody tr td:nth-child(5){
+    width: 150px ;
+    padding-right: 10px;
+    text-align: right;
+    font-size: 12pt;
+    padding-top: 8px;
+}
+.expired-account-modal .payments-invoice-table table thead tr th:nth-child(4){
+    width: 150px;
+    padding-right: 10px;
+    text-align: right;
+    font-size: 14pt;
+    font-weight: bold;
+}
+/* date-Maturity */
+.expired-account-modal .payments-invoice-table table tbody tr td:nth-child(6){
+    width: 150px ;
+    padding-right: 10px;
+    text-align: right;
+    font-size: 12pt;
+    padding-top: 8px;
+}
+.expired-account-modal .payments-invoice-table table thead tr th:nth-child(5){
+    width: 150px;
+    padding-right: 10px;
+    text-align: right;
+    font-size: 14pt;
+    font-weight: bold;
+}
+.payments-invoice-label {
+    width: 100px;
+    height: 30px;
+    font-size: 14px;
+    padding-top: 5px;
+    padding-left: 5px;
+}
+.payments-invoice-group {
+    width: calc(100% - 100px);
+    height: 30px;
+    padding-left: 5px;
+    padding-right: 5px;
+    float: right;
+}
+.invoice-payment-label{
+    width: 160px;
+}
+.invoice-payment-input-date{
+    width: calc(100% - 160px);
+}
+.payments-invoice-input {
+    width: calc(100% - 30px);
+    height: 30px;
+    float: left;
+    font-size: 12pt;
+    text-align: right;
+}
+.payments-invoice-symbol{
+    width: 30px;
+    height: 30px;
+    float: right;
+    text-align: center;
+    font-size: 16pt;
+    border: 1px solid #ccc;
+    background: #e3e3e3;
+}
+.invoice-payment-label-select {
+    width: 150px;
+}
+.invoice-payment-input-select {
+    width: calc(100% - 150px);
+}
+.invoice-payment-input{
+    width: 100%;
+}
+.from-title-h3 {
+    font-size: 9pt !important;
+    margin-top: 0px;
+    margin-bottom: 10px;
+    padding-left: 12px;
+    color: #ccc;
+}
+.input-date{
+    text-align: left;
+}
+.type-select-bank {
+    display: none;
+}
+.select-type-bank{
+    display: none;
+}
+.select-type-bank-card{
+    display: none;
+}
+.ammount-returned {
+    display: none;
+}
+.paymnets-invoice-header{
+    font-size: 12pt;
+    padding-bottom: 10px;
+    padding-top: 10px;
+}
+/* button */
+.paymnets-invoice-footer{
+    padding-top: 10px;
+    padding-bottom: 10px;
+}
+.payments-invoice-button {
+    font-size: 12pt !important;
+    width: 130px;
+    height: 35px;
+}
+.widget-content.widget-loading-payments {
+    position: absolute;
+    width: 100%;
+    height: 100%;
+    color : #000;
+    display: none;
+    z-index: 1100;
+    background: #8080806b;
+    align-items: center;
+    justify-content: center;
+}
+.bank-select {
+    height: 30px !important;
+    font-size: 14pt;
+    color: #555;
+}
+.bank-name-holder {
+    height: 30px !important;
+    font-size: 14pt;
+    color: #555;
+}
+.bank-number-cta {
+    height: 30px !important;
+    font-size: 14pt;
+    color: #555;
+}
+.bank-number-cta-origen {
+    height: 30px !important;
+    font-size: 14pt;
+    color: #555;
+}
+
+.bank-number {
+    height: 30px !important;
+    font-size: 14pt;
+    color: #555;
+}
+.ui-autocomplete  {
+    max-height: 100px;
+    overflow-y: auto;
+}
+.ui-helper-hidden-accessible {
+    display: none;
+}
+/* disabled */
+.select-bank-id {
+    display: none;
+}
+.select-number-cta {
+    display: none;
+}
+.select-number-cta-origin {
+    display: none;
+}
+.select-number {
+    display: none;
+}
+.select-check-type-id {
+    display: none;
+}
+.select-amount-total {
+    display: none;
+}
+.select-date-maturity {
+    display: none;
+}
+.select-name-holder {
+    display: none;
+}
+.statement-config {
+    display: none;
+}

+ 1345 - 0
static/src/js/eiru_payments_invoices.js

@@ -0,0 +1,1345 @@
+(function() {
+
+    openerp.widgetInstancePaymentsInvoices = null;
+    openerp.parentInstancePaymentsInvoices = {};
+    var QWeb = openerp.web.qweb;
+    var instanceWeb = openerp.web;
+
+    openerp.EiruPaymentsInvoices = openerp.Widget.extend({
+        template: 'eiruPaymentsInvoices.Invoices',
+        id: undefined,
+        buttons: undefined,
+        accountInvoice: [],
+        resPartner: [],
+        accountJournal: [],
+        resCompany: [],
+        resCurrency: [],
+        currencySelect: [],
+        ResUser: [],
+        statementOpen: [],
+        /*Move*/
+        accountMoveLine: [],
+        moveLine:[],
+        movePayments: [],
+        /* bank */
+        resBankType: [],
+        resBank: [],
+        bankPayments: [],
+        resBankChequeType: [],
+        fieldsAllowed: [],
+        /* account interes */
+        interestLine: [],
+        interestConfig: [],
+        /* statementConfig */
+        statementConfig: [],
+        /* Module Cheque */
+        eiruBankPaymentsReferences: [],
+        eiruAccountBankStatementUtility: [],
+        eiruAccountInterest: [],
+        /* 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.parentInstancePaymentsInvoices.reload();
+        },
+        /* Description: Función para remover el modal */
+        removeModal: function() {
+            $('.expired-account-modal').remove();
+            $('.modal-backdrop').remove();
+        },
+        /* Método inicial  */
+        fetchInitial: function() {
+            var self = this;
+            self.fetchAccountInvoice(self.id).then(function(accountInvoice) {
+                return accountInvoice;
+            }).then(function(accountInvoice) {
+                self.accountInvoice = accountInvoice;
+                console.log(accountInvoice);
+                return self.fetchVerifyModule('eiru_bank_payments_references');
+            }).then(function(eiruBankPaymentsReferences) {
+                self.eiruBankPaymentsReferences = eiruBankPaymentsReferences;
+                return self.fetchResPartner();
+            }).then(function(resPartner) {
+                self.resPartner = resPartner;
+                return self.fetchAccountjournal();
+            }).then(function(accountJournal) {
+                self.accountJournal = accountJournal;
+                return self.fetchResCompany();
+            }).then(function(resCompany) {
+                self.resCompany = resCompany;
+                return self.fetchResCurrency();
+            }).then(function(resCurrency) {
+                self.resCurrency = resCurrency;
+                return self.fetchResBanktype();
+            }).then(function(resBankType) {
+                self.resBankType= resBankType;
+                return self.fetchResBankChecktype();
+            }).then(function(resBankChequeType) {
+                self.resBankChequeType = resBankChequeType;
+                return self.fetchResBank();
+            }).then(function(resBank) {
+                self.resBank = resBank;
+                return self.fetchBankPayments();
+            }).then(function(bankPayments) {
+                self.bankPayments = bankPayments;
+                return self.fetchMoveLine();
+            }).then(function(accountMoveLine) {
+                self.accountMoveLine = accountMoveLine;
+                return self.fetchVerifyModule('eiru_account_interest');
+            }).then(function(eiruAccountInterest) {
+                self.eiruAccountInterest = eiruAccountInterest;
+                return self.fetchInterestLine();
+            }).then(function(interestLine) {
+                self.interestLine = interestLine;
+                return self.fetchInterestConfig()
+            }).then(function(interestConfig) {
+                self.interestConfig = interestConfig;
+               return self.fetchVerifyModule('eiru_account_bank_statement_utility');
+            }).then(function(eiruAccountBankStatementUtility) {
+                self.eiruAccountBankStatementUtility = eiruAccountBankStatementUtility;
+                return self.fetchStatementConfig();
+            }).then(function(statementConfig) {
+                self.statementConfig = statementConfig;
+                return self.fetchStatement();
+            }).then(function(statementOpen) {
+                self.statementOpen = statementOpen;
+                return self.generateMoveLine();
+            }).then(function(moveLine) {
+                self.moveLine = moveLine;
+                return self.showModalPayments();
+            });
+        },
+        /* Verificar modulo instalados */
+        fetchVerifyModule: function(module) {
+            if (!module)
+                return [];
+            var moduleModule =new openerp.web.Model('ir.module.module');
+            var fields = ['id', 'name', 'state'];
+            var domain = [['name', '=', module], ['state', '=', 'installed']];
+            return moduleModule.query(fields).filter(domain).all();
+        },
+        /* Account Invoice */
+        fetchAccountInvoice: function(ids) {
+            var accountInvoice = new openerp.web.Model('account.invoice');
+            var fields = ['id', 'number', 'date_invoice', 'amount_total', 'residual', 'partner_id', 'currency_id', 'type' ,'seq_invoice'];
+            var domain = [['id', '=', ids],['state', '=', 'open']];
+            return accountInvoice.query(fields).filter(domain).all();
+        },
+        /* Res partnes */
+        fetchResPartner: function() {
+            var self = this;
+            if (!self.accountInvoice || !self.accountInvoice.length)
+                return;
+            var partnerId = self.accountInvoice[0].partner_id[0];
+            var resPartner = new openerp.web.Model('res.partner');
+            var fields = ['id', 'name','commercial_partner_id'];
+            var domain = [['id', '=', partnerId]];
+            return resPartner.query(fields).filter(domain).all();
+        },
+        /* Account Move Line */
+        fetchMoveLine: function() {
+            var self = this;
+            var invoiceMoveLine = new openerp.web.Model('account.invoice');
+            return invoiceMoveLine.call('get_moveline_invoice',[self.id], {
+                context: new openerp.web.CompoundContext()
+            });
+        },
+        /* Account Interest Line */
+        fetchInterestLine: function() {
+            var self = this;
+            if (!self.eiruAccountInterest.length)
+                return [];
+
+            var moveLineIDS = _.map(self.accountMoveLine, function(map) {
+                return map.id
+            });
+
+            var self = this;
+            var invoiceMoveLine = new openerp.web.Model('account.invoice');
+            return invoiceMoveLine.call('eiru_payments_account_interest_line',[moveLineIDS], {
+                context: new openerp.web.CompoundContext()
+            });
+        },
+        /* GET Interets configurations */
+        fetchInterestConfig: function() {
+            var self = this;
+            if (!self.eiruAccountInterest.length)
+                return [];
+
+            var fields = ['id','name', 'lock_move_line'];
+            var domain = [['active', '=', true]];
+            var accountInterestConfig = new openerp.web.Model('account.interest.config');
+            return accountInterestConfig.query(fields).filter(domain).all();
+        },
+        /* Res bank Paymnets */
+        fetchBankPayments: function() {
+            var self = this;
+            if (!self.eiruBankPaymentsReferences.length)
+                return [];
+
+            var invoiceBankPayments = new openerp.web.Model('account.invoice');
+            return invoiceBankPayments.call('get_bank_payments', {
+                context: new openerp.web.CompoundContext()
+            });
+        },
+        /* Account Journal Type[BANK, CASH]*/
+        fetchAccountjournal: function() {
+            var fields = ['id', 'name', 'code', 'type', 'currency', 'default_debit_account_id', 'default_credit_account_id'];
+            var domain = [['active', '=', true], ['type', 'in', ['bank', 'cash']]];
+            var journalSalario = new openerp.web.Model('account.journal');
+            return journalSalario.query(fields).filter(domain).all();
+        },
+        /* Consultar Compania */
+        fetchResCompany: function() {
+            var fields = ['id','name', 'currency_id'];
+            var domain = [['id', '=', 1]];
+            var resCompanyIds = new openerp.web.Model('res.company');
+            return resCompanyIds.query(fields).filter(domain).all();
+        },
+        /* Consultar Bank Type */
+        fetchResBanktype: function() {
+            var self = this;
+            if (!self.eiruBankPaymentsReferences.length)
+                return [];
+
+            var invoiceBankPayments = new openerp.web.Model('account.invoice');
+            return invoiceBankPayments.call('get_bank_payment_type', {
+                context: new openerp.web.CompoundContext()
+            });
+        },
+        /* Consultar Bank Check Type */
+        fetchResBankChecktype: function() {
+            var self = this;
+            if (!self.eiruBankPaymentsReferences.length)
+                return [];
+
+            var fields = ['id','name', 'code'];
+            var resBnakCheckType = new openerp.web.Model('res.bank.cheque.type');
+            return resBnakCheckType.query(fields).all();
+        },
+        /*Consultar Res Bank */
+        fetchResBank: function() {
+            var self = this;
+            if (!self.eiruBankPaymentsReferences.length)
+                return [];
+
+            var fields = ['id', 'name', 'ruc'];
+            var resBank = new openerp.web.Model('res.bank');
+            return resBank.query(fields).all();
+        },
+        /* Consultar Moneda Activas */
+        fetchResCurrency: function() {
+            var invoicesCurrencyPayments = new openerp.web.Model('account.invoice');
+            return invoicesCurrencyPayments.call('get_currency_payments_invoices', {
+                context: new openerp.web.CompoundContext()
+            });
+        },
+        /* statement Config */
+        fetchStatementConfig: function() {
+            var self = this;
+            if (!self.eiruAccountBankStatementUtility.length)
+                return [];
+
+            var fields = ['id','name', 'active', 'import_statement_payments'];
+            var domain = [['active', '=', true]];
+            var statementConfig = new openerp.web.Model('account.bank.statement.config');
+            return statementConfig.query(fields).filter(domain).all();
+        },
+        /* Get User */
+        fetchStatement: function(){
+            var invoiceStatement = new openerp.web.Model('account.invoice');
+            return invoiceStatement.call('get_statement', {
+                context: new openerp.web.CompoundContext()
+            });
+        },
+        /* Generar las cuotas a pagar */
+        generateMoveLine: function() {
+            var self = this;
+            var moveLine  = [];
+            var newMoveLine= [];
+            var defer = $.Deferred();
+            var currencyInvoice = self.getCurrency(self.accountInvoice[0].currency_id[0]).shift();
+            _.each(self.accountMoveLine, function(line){
+                moveLine.push({
+                    'id': line.id,
+                    'dateMaturity': moment(line.dateMaturity).format('DD/MM/YYYY'),
+                    'debit': line.amountCurrency,
+                    'residual': line.amountResidualCurrency,
+                    'currencyAmount': line.currencyAmount,
+                    'debitFormat': accounting.formatMoney((line.amountCurrency), currencyInvoice.symbol,currencyInvoice.decimalPlaces, currencyInvoice.thousandsSeparator, currencyInvoice.decimalSeparator),
+                    'residualFormat': accounting.formatMoney((line.amountResidualCurrency), currencyInvoice.symbol, currencyInvoice.decimalPlaces, currencyInvoice.thousandsSeparator, currencyInvoice.decimalSeparator)
+                });
+            });
+
+            newMoveLine = _.sortBy(moveLine, function(item){return new Date(item.dateMaturity.trim())});
+            defer.resolve(newMoveLine);
+            return defer;
+        },
+        /* Get Move Line */
+        getMoveLine: function(ids) {
+            var self = this;
+            return _.filter(self.moveLine, function(line){
+                return _.contains(ids, line.id);
+            });
+        },
+        /* Get Move Line Currency */
+        getMoveLineCurrency: function(currencyAmount, idCurrency) {
+            return _.filter(currencyAmount, function(currency){
+                return currency.id === idCurrency;
+            });
+        },
+        /* Generar lista de cuotas seleccionadas */
+        generateSelectTotal:function(idSelect, idCurrency){
+            var self = this;
+            var movePayments = [];
+            var moveCurrency = [];
+            var residual = 0;
+            var move = self.getMoveLine(idSelect);
+
+            if (!move.length){
+                return movePayments;
+            }
+
+            _.each(move, function(line){
+                moveCurrency = self.getMoveLineCurrency(line.currencyAmount, idCurrency.id).shift();
+                residual += moveCurrency.amountCurencyResidual;
+            });
+
+            movePayments.push({
+                'ids': idSelect,
+                'amountResidual': residual,
+                'amountResidualFormat': instanceWeb.formatCurrency(residual, idCurrency),
+                'currencySymbol': idCurrency.symbol,
+                'currencyRate': idCurrency.rate
+            });
+            return movePayments;
+        },
+        /* getCurrency ['filtra la moneda por id'']*/
+        getCurrency: function(id) {
+            var self = this;
+             return _.filter(self.resCurrency, function(item) {
+                 return item.id === id;
+             });
+        },
+        /* Obtener la monedad sobre el diario seleccionada */
+        getCurrencySelect: function(id) {
+            var self = this;
+            var currency = [];
+            if (!id)
+                id = self.resCompany[0].currency_id[0];
+
+            currency = self.getCurrency(id);
+            return currency;
+        },
+        /* Get Journal*/
+        getJournal: function(code) {
+             var self = this;
+             return _.filter(self.accountJournal, function(item) {
+                 return item.code === code;
+             });
+        },
+        /* GET fields filter */
+        getBankTypeFieldsAllowed: function(name) {
+            var self =  this;
+            return _.contains(self.fieldsAllowed, name);
+        },
+        /*Get Bnak */
+        getResBank: function(id) {
+            var self= this;
+            return _.filter(self.resBank, function(bank) {
+                return bank.id === id;
+            });
+        },
+        /* Select Journal Change */
+        getSelectedJournal: function(code) {
+            var self = this;
+            var currencySelect = []
+            var journal = self.getJournal(code).shift();
+            var company = self.resCompany;
+
+            if (!journal)
+                return [];
+
+            if (!journal.currency) {
+                currencySelect = self.getCurrency(company[0].currency_id[0]);
+            }else {
+                currencySelect = self.getCurrency(journal.currency[0]);
+            }
+            self.currencySelect = currencySelect;
+            return currencySelect;
+        },
+        /* verificar si existe el numero de chueque */
+        checkNumber: function(bankId, numberCta, number) {
+            /**
+             * [verificar si existe el numero de cheque en 'res.bank.paymnets' ]
+             * :param bankId: id de banco (res_bank.id).
+             * :param numberCta: numero de cuneta(res_bank_payments.number_cta).
+             * :param number: numero de cheque/boleta/vale (res_bank_payments.number)
+             * :return : [Objeto] si existe datos que satisfacer el filtro, vacio si no.
+             */
+            var self = this;
+            if (!self.bankPayments)
+                return [];
+            /* filtar  bank Payments */
+            return _.filter(self.bankPayments, function(item) {
+                return item.bankId === bankId && item.numberCta === numberCta && item.number === number;
+            });
+        },
+        /*Obtener cajas del diario seleccionado */
+        getStatementeJournal: function(journalId) {
+            var self = this;
+            return _.filter(self.statementOpen, function(item){
+                return item.journalID === journalId;
+            });
+        },
+        /* filter type bank operation */
+        filterTypeOperationBank: function(journal_id){
+            var self = this;
+            return _.filter(self.resBankType, function(item){
+                return _.contains(item.journal_ids, journal_id)
+            });
+        },
+        /* Get bank */
+        getTypeOperation(id){
+            var self = this;
+            return _.filter(self.resBankType, function(item){
+                return item.id === id;
+            });
+        },
+        /* get cheque type */
+        getBankChequeType: function(id){
+            var self= this;
+            return _.filter(self.resBankChequeType, function(item){
+                return item.id === id;
+            });
+        },
+        /* FIlter Line interest */
+        filterInterestLineId:function(moveId){
+            var self = this;
+            return _.filter(self.interestLine, function(item) {
+                return item.moveLineId === moveId;
+            });
+        },
+        /**
+         * [ showModalPayments ]
+         */
+        showModalPayments: function() {
+            var self = this;
+            var defer =$.Deferred();
+            var results = true;
+            var accountJournal = self.accountJournal;
+            var moveSelected = [];
+            var selectTotal = [];
+            var currencyId = [];
+            var idRow = [];
+
+            var bankId = undefined;
+            var numberName = 'Nº Comprobante';
+            var amountBalanceBank = undefined;
+            var typePayments = undefined;
+
+            accountJournal.unshift({
+                'name': "",
+                'code': ""
+            });
+
+            var modal = QWeb.render('eiruPaymentsInvoices.Modal',{
+                moveLine: self.moveLine,
+                journal: accountJournal,
+            });
+            $('.openerp_webclient_container').after(modal);
+            $('.expired-account-modal').modal();
+
+            /* Button */
+            var savePaymentsButton = $('.expired-account-modal').find('.save-payments-button');
+            /* Table */
+            var tableRow = $('.expired-account-modal').find('.table-tbody').find('tr');
+            /* Monto total a pagar  - symbol*/
+            var amountTotal = $('.expired-account-modal').find('.amount-total');
+            var amountTotalSymbol = $('.expired-account-modal').find('.amount-total-symbol');
+            /* fecha de operación*/
+            var dateOperation = $('.expired-account-modal').find('.date-operation');
+            /* Diario */
+            var journalSelect = $('.expired-account-modal').find('.journal-select');
+            /* Monto a pagar - symbolo */
+            var amountPayments = $('.expired-account-modal').find('.amount-payments');
+            var amountPaymentsSymbol = $('.expired-account-modal').find('.amount-payments-symbol');
+            /* Caja */
+            var statementSelect = $('.expired-account-modal').find('.statement-select');
+            /* Tipo de operación bancaria */
+            var bankTypeSelect = $('.expired-account-modal').find('.bank-type-select');
+            /* banking operation */
+            var bankingOperation = $('.expired-account-modal').find('.eiru-banking-operation');
+            /* Disabled paymentsAmount */
+            amountPayments.attr("disabled", true);
+            /* Date Now */
+            dateOperation.val(moment().format("YYYY-MM-DD"));
+            /* Desabilitar Chech de la Table */
+            var dateMin = undefined;
+            var rowselect = undefined;
+            var dateSelect = undefined;
+
+            /*get currency invoices*/
+            var currencyInvoice = self.getCurrencySelect(self.accountInvoice[0].currency_id[0]).shift();
+            if (currencyInvoice) {
+                amountTotalSymbol.text(currencyInvoice.symbol);
+                amountPaymentsSymbol.text(currencyInvoice.symbol);
+            }
+
+            /* Disabled Chech Moveline */
+            _.each(tableRow, function(tr) {
+                var ckechk = ($($(tr).children()[1]).find('.select-move-payments'))[0].checked;
+                var dateMatu = new Date(($(tr).children()[2].textContent).trim());
+                if (!ckechk) {
+                    if (!dateMin) {
+                        dateMin = dateMatu.getTime();
+                    } else {
+                        $($(tr).children()[1]).find('.select-move-payments').attr("disabled", true);
+                    }
+                }
+
+                var idMove = parseInt(($(tr).children()[0].textContent).trim());
+                if (!!self.interestConfig.length && self.interestConfig[0].lock_move_line) {
+                    var move = self.filterInterestLineId(idMove);
+                    var moveState = _.map(move, function(map) {
+                        return map.state
+                    })
+
+                    if (_.contains(moveState, 'open')) {
+                        ($($(tr).children()[1]).find('.select-move-payments'))[0].checked = false;
+                        $($(tr).children()[1]).find('.select-move-payments').attr("disabled", true);
+                        $($(tr).children()[3]).text("Existe interés sobre la cuota vencida REF("+move[0].interest[0].name+").")
+                    }
+                }
+            });
+
+            /* Selecionar las cuotas */
+            tableRow.click(function(e) {
+                if ($(e.target).index() !== 0)
+                    return;
+
+                idRow = parseInt(($(e.target).closest('tr').children()[0].textContent).trim());
+                if (e.target.checked === true) {
+                    moveSelected.push(idRow);
+
+                    currencyId = self.getCurrencySelect(self.accountInvoice[0].currency_id[0]).shift();
+                    if (journalSelect.val()) {
+                        currencyId = self.getSelectedJournal(journalSelect.val()).shift();
+                    }
+
+                    self.movePayments = self.generateSelectTotal(moveSelected,currencyId);
+
+                    selectTotal = self.movePayments[0];
+                    if (selectTotal) {
+                        /*total a pagar*/
+                        amountTotal.val(selectTotal.amountResidualFormat);
+                        amountTotalSymbol.text(selectTotal.currencySymbol);
+                        /*Monto a pagar */
+                        amountPayments.val(selectTotal.amountResidualFormat);
+                        amountPaymentsSymbol.text(selectTotal.currencySymbol);
+                    }
+
+                    dateMin = undefined;
+                    rowselect = undefined;
+                    dateSelect = undefined;
+
+                   _.each(tableRow, function(tr) {
+                        var dateMatu = new Date(($(tr).children()[2].textContent).trim());
+                        var ckechk = ($($(tr).children()[1]).find('.select-move-payments'))[0].checked;
+                        if (ckechk) {
+                            if (!rowselect) {
+                                rowselect = $($(tr).children()[1]).find('.select-move-payments');
+                                dateSelect = dateMatu.getTime();
+                            } else {
+                                if (dateMatu.getTime() > dateSelect) {
+                                    rowselect.attr("disabled", true);
+                                    rowselect = $($(tr).children()[1]).find('.select-move-payments');
+                                    dateSelect = dateMatu.getTime();
+                                } else {
+                                    $($(tr).children()[1]).find('.select-move-payments').attr("disabled", true);
+                                }
+                            }
+                        } else {
+                            if (!dateMin) {
+                                dateMin = dateMatu.getTime();
+                                var moveId = parseInt(($(tr).children()[0].textContent).trim());
+                                $($(tr).children()[1]).find('.select-move-payments').removeAttr("disabled");
+
+                                if (!!self.interestConfig.length && self.interestConfig[0].lock_move_line) {
+                                    var move = self.filterInterestLineId(moveId);
+                                    var moveState = _.map(move, function(map) {
+                                        return map.state;
+                                    });
+                                    if ((_.contains(moveState, 'open'))) {
+                                        $($(tr).children()[1]).find('.select-move-payments').attr("disabled", true);
+                                    }
+                                }
+                            }
+                        }
+                   });
+                } else {
+                    var indexRow = undefined;
+                    _.each(moveSelected, function(input, index) {
+                        if (input === idRow) {
+                            indexRow = index;
+                        }
+                    });
+                    moveSelected.splice(indexRow,1);
+                    if (journalSelect.val()) {
+                        currencyId = self.getSelectedJournal(journalSelect.val()).shift();
+                    }else {
+                        currencyId = self.getCurrencySelect(self.accountInvoice[0].currency_id[0]).shift();
+                    }
+                    self.movePayments = self.generateSelectTotal(moveSelected,currencyId);
+                    selectTotal = self.movePayments[0];
+                    if (selectTotal) {
+                        amountTotal.val(selectTotal.amountResidualFormat);
+                        amountTotalSymbol.text(selectTotal.currencySymbol);
+                        /*Monto a pagar */
+                        amountPayments.val(selectTotal.amountResidualFormat);
+                        amountPaymentsSymbol.text(selectTotal.currencySymbol);
+                    } else {
+                        amountTotal.val(0);
+                        amountTotalSymbol.text(currencyId.symbol);
+                        /*Monto a pagar */
+                        amountPayments.val(0);
+                        amountPaymentsSymbol.text(currencyId.symbol);
+                    }
+
+                    dateMin = undefined;
+                    rowselect = undefined;
+                    dateSelect = undefined;
+                   _.each(tableRow, function(tr) {
+                        var dateMatu = new Date(($(tr).children()[2].textContent).trim());
+                        var ckechk = ($($(tr).children()[1]).find('.select-move-payments'))[0].checked;
+                        if (ckechk) {
+                            rowselect = $($(tr).children()[1]).find('.select-move-payments');
+                            dateSelect = dateMatu.getTime();
+                        } else {
+                            if (rowselect)
+                                rowselect.removeAttr("disabled");
+                            if (!dateMin) {
+                                dateMin = dateMatu.getTime();
+                            } else {
+                                $($(tr).children()[1]).find('.select-move-payments').attr("disabled", true);
+                            }
+                        }
+                   });
+                }
+            });
+
+            /* Cambio en el método de pago */
+            journalSelect.change(function(e) {
+                var journal = [];
+                bankingOperation.empty();
+                statementSelect.val('');
+
+                if (journalSelect.val()) {
+                    journal = self.getJournal(journalSelect.val()).shift();
+                    if (!!journal) {
+                        amountPayments.removeAttr("disabled");
+                        /* statement Open */
+                        if (!!self.eiruAccountBankStatementUtility.length) {
+                            if(!!self.statementConfig.length) {
+                                if (self.statementConfig[0].import_statement_payments === 'manual_import') {
+                                    var statement = self.getStatementeJournal(journal.id);
+                                    /* Generar lista de caja abiertas. */
+                                    $('.expired-account-modal').find('.statement-config').css('display','none');
+                                    statementSelect.empty();
+                                    if (!!statement.length) {
+                                        $('.expired-account-modal').find('.statement-config').css('display','flex');
+                                        var cashboxOpen = '<option value=""></option>';
+                                        _.each(statement, function(item) {
+                                            cashboxOpen += '<option value="'+item.id+'">'+item.name+'</option>';
+                                        });
+                                        statementSelect.append(cashboxOpen);
+                                    }
+                                }
+                            }
+                        }
+                        /* Type operación bank */
+                        typeOperationBank = self.filterTypeOperationBank(journal.id);
+                        bankTypeSelect.empty();
+                        self.fieldsBank = [];
+                        $('.expired-account-modal').find('.type-select-bank').css('display','none');
+                        if (!!typeOperationBank.length) {
+                            $('.expired-account-modal').find('.type-select-bank').css('display','flex');
+                            var typeOperation = '<option value=""></option>';
+                            _.each(typeOperationBank, function(item) {
+                                typeOperation += '<option value="'+item.id+'">'+item.name+'</option>';
+                            });
+                            bankTypeSelect.append(typeOperation);
+                        }
+                    }
+                    currencyId = self.getSelectedJournal(journalSelect.val()).shift();
+                } else {
+                    amountPayments.attr("disabled", true);
+                    currencyId = self.getCurrencySelect(self.accountInvoice[0].currency_id[0]).shift();
+                }
+                self.movePayments = self.generateSelectTotal(moveSelected,currencyId);
+                selectTotal = self.movePayments[0];
+                if (selectTotal) {
+                    /*total a pagar*/
+                    amountTotal.val(selectTotal.amountResidualFormat);
+                    amountTotalSymbol.text(selectTotal.currencySymbol);
+                    /*Monto a pagar */
+                    amountPayments.val(selectTotal.amountResidualFormat);
+                    amountPaymentsSymbol.text(selectTotal.currencySymbol);
+                }
+            });
+
+            /* Typo de pago */
+            bankTypeSelect.change(function(e) {
+                bankingOperation.empty();
+                if (!bankTypeSelect.val())
+                    return  false;
+
+                var typeBank = self.getTypeOperation(parseInt(bankTypeSelect.val())).shift();
+                typePayments = typeBank;
+                var fields = '';
+                var cont = 0;
+                var fieldsBank = [];
+
+                _.each(typeBank.fields_allowed, function(item, index) {
+                    if (cont === 0)
+                        fields += '<div class="row">';
+                    cont ++;
+                    var fieldModel = [];
+                    var typeText ="text";
+                    var select = "payments-";
+                    var classField = select.concat(item.name.replace(/_/g, '-'));
+
+                    if (item.string.typeField === 'date')
+                        typeText = "date";
+
+                    fields += '<div class="col-xs-6">';
+                    fields +=    '<label class="payments-invoice-label invoice-payment-label-select">'+item.label+'</label>';
+                    fields +=    '<div class="payments-invoice-group invoice-payment-input-select">';
+
+                    if (item.string.type === 'normal') {
+                        if (item.string.typeField === 'float') {
+                            fields +=       '<input type="'+typeText+'" class="form-control payments-invoice-input amount-currency '+classField+'" value="0"></input>';
+                            fields +=       '<div class="payments-invoice-symbol">';
+                            fields +=          '<span class="input-group-text amount-total-symbol">'+currencyId.symbol+'</span>';
+                            fields +=       '</div>';
+                        }
+                        else {
+                                fields +=       '<input type="'+typeText+'" class="payments-invoice-input invoice-payment-input input-date '+classField+'" ></input>';
+                        }
+                    } else {
+                        var test = item.string.model.split(".");
+                        var newModel = "";
+
+                        _.each(test, function(item, index) {
+                            if (index === 0 ){
+                                newModel = item;
+                            } else {
+                                var newLetter = "";
+                                _.each(item, function(inv, index) {
+                                    if (index === 0) {
+                                        newLetter = inv.toUpperCase();
+                                    }else {
+                                        newLetter = newLetter.concat(inv);
+                                    }
+                                });
+                                newModel = newModel.concat(newLetter);
+                            }
+                        })
+
+                        fieldModel = _.flatten(_.filter(self, function(element, index) {
+                            return index ===  newModel;
+                        }));
+
+                        if (item.string.searchType === 'selection') {
+                            fields += '<select class="payments-invoice-input invoice-payment-input '+classField+'">';
+                            fields +=       '<option value=""></option>';
+                            _.each(fieldModel, function(item) {
+                                fields +=   '<option value="'+item.id+'">'+item.name+'</option>';
+                            });
+
+                            fields += '</select>';
+                        } else {
+                            fields += '<input type="text" class="form-control payments-invoice-input invoice-payment-input input-date ui-autocomplete-input '+classField+'" autocomplete="off" placeholder="'+item.label+'"></input>';
+                        }
+                    }
+                    fields +=    '</div>';
+                    fields += '</div>';
+
+                    if (cont === 2 || (index +1 ) === typeBank.fields_allowed.length) {
+                        fields += '</div>';
+                        cont = 0;
+                    }
+
+                    /* Tyoe Field */
+                    fieldsBank.push({
+                        'field': classField,
+                        'name': item.name,
+                        'required': item.string.required,
+                        'label': item.label,
+                        'type': item.string.typeField,
+                        'model': fieldModel,
+                        'modelAutoComplete': _.map(fieldModel, function(item) {
+                            return {
+                                label: item.id +" - "+ item.name,
+                                value: item.id +" - "+ item.name
+                            };
+                        }),
+                        'searchType': item.string.searchType,
+                    });
+                });
+
+                self.fieldsBank = fieldsBank;
+                bankingOperation.append(fields);
+
+                /*  AutoComplete*/
+                _.each(_.filter(fieldsBank, function(item){return item.searchType === 'autocomplete'}), function(autoComplete) {
+                    var fieldComplete = $('.expired-account-modal').find('.'+autoComplete.field);
+                    fieldComplete.autocomplete({
+                        source: autoComplete.model,
+                        minLength:0,
+                    })
+                })
+
+            });
+
+            /**
+             * [Keyup]
+             */
+            $('.expired-account-modal').keyup(function(e){
+                var nameClas = (($(e.target)[0].className).trim()).split(" ");
+                /* fields Amount Currency */
+                if (_.contains(nameClas, 'amount-currency')) {
+                    var ammountBank = $('.expired-account-modal').find('.'+nameClas[nameClas.length -1]);
+                    if (journalSelect.val()) {
+                            currencyId = self.getSelectedJournal(journalSelect.val()).shift();
+                    } else {
+                            currencyId = self.getCurrencySelect(self.accountInvoice[0].currency_id[0]).shift();
+                    }
+                    var amount_add = instanceWeb.unFormatCurrency(ammountBank.val());
+                    ammountBank.val(instanceWeb.formatCurrency(amount_add,currencyId));
+                    ammountBank.css('border-color','#ccc');
+                }
+                /* AutoComplete */
+                if (_.contains(nameClas, 'ui-autocomplete-input')) {
+                    _.each(_.filter(self.fieldsBank, function(item){return item.searchType === 'autocomplete'}), function(autoComplete) {
+                        if (nameClas[nameClas.length -1] === autoComplete.field) {
+                            var fieldComplete = $('.expired-account-modal').find('.'+autoComplete.field);
+                            fieldComplete.autocomplete({
+                                source: autoComplete.modelAutoComplete,
+                                minLength:0,
+                                select: function(e, ui) {
+                                    var id = undefined;
+                                    if (!!ui.item.value)
+                                        id = ui.item.value.split('-');
+                                },
+                            })
+                        }
+                    });
+                }
+            });
+
+            /**
+             * [focusout]
+             */
+            $('.expired-account-modal').focusout(function(e){
+                var nameClas = (($(e.target)[0].className).trim()).split(" ");
+                /**
+                 * [Verify amount-total]
+                 */
+                if (_.contains(nameClas, 'payments-amount-total')){
+                    var ammountBank = $('.expired-account-modal').find('.'+nameClas[nameClas.length -1])
+
+                    currencyId = self.getCurrencySelect(self.accountInvoice[0].currency_id[0]).shift();
+                    if (journalSelect.val())
+                         currencyId = self.getSelectedJournal(journalSelect.val()).shift();
+
+                    var amount_add = instanceWeb.unFormatCurrency(ammountBank.val());
+                    var paymentsAmount = instanceWeb.unFormatCurrency(amountPayments.val());
+                    var paymentsTotal = instanceWeb.unFormatCurrency(amountTotal.val());
+
+                    if (amount_add <= 0){
+                        openerp.web.notification.do_warn("Atencion", "El valor debe ser mayor que 0");
+                        ammountBank.css('border-color','red');
+                        ammountBank.focus();
+                        return false;
+                    }
+                    if (amount_add < paymentsAmount) {
+                        amountPayments.val(instanceWeb.formatCurrency(amount_add, currencyId));
+                    }
+                    ammountBank.val(instanceWeb.formatCurrency(amount_add, currencyId));
+                }
+                /**
+                * [Verify Bank Selected]
+                */
+                if (_.contains(nameClas, 'payments-bank-id')) {
+                    var bankSelected = $('.expired-account-modal').find('.'+nameClas[nameClas.length -1]);
+                    var valueBank = bankSelected.val();
+                    if (_.contains(nameClas, 'ui-autocomplete-input'))
+                        valueBank = (valueBank.split('-'))[0];
+
+                    if (!bankSelected.val()) {
+                        openerp.web.notification.do_warn("Atencion", "Tienes que seleccionar un banco para continuar.");
+                        bankSelected.css('border-color','red');
+                        bankSelected.focus();
+                        return false;
+                    }
+
+                    var bankValue =  self.getResBank(parseInt(valueBank)).shift();
+                    if (!bankValue) {
+                        openerp.web.notification.do_warn("Atencion", "El banco no existe, ingrese un banco valido.");
+                        bankSelected.css('border-color','red');
+                        bankSelected.focus();
+                        return false;
+                    }
+                    bankSelected.css('border-color','#ccc');
+                    bankId = bankValue.id
+                }
+                /**
+                 * [Verify Cheque type]
+                 */
+                if (_.contains(nameClas, 'payments-cheque-type-id')){
+                    var typeChequeSelected = $('.expired-account-modal').find('.'+nameClas[nameClas.length -1]);
+                    var valuetype = typeChequeSelected.val();
+                    if (_.contains(nameClas, 'ui-autocomplete-input'))
+                        valuetype = (valuetype.split('-'))[0];
+
+                    if (!typeChequeSelected.val()) {
+                        openerp.web.notification.do_warn("Atencion", "Tienes que seleccionar el tipo de cheque para continuar.");
+                        typeChequeSelected.css('border-color','red');
+                        typeChequeSelected.focus();
+                        return false;
+                    }
+
+                    var chequeTypeValue =  self.getBankChequeType(parseInt(valuetype)).shift();
+                    if (!chequeTypeValue) {
+                        openerp.web.notification.do_warn("Atencion", "Tipo de cheque no existe , ingrese un tipo de cheque valido.");
+                        typeChequeSelected.css('border-color','red');
+                        typeChequeSelected.focus();
+                        return false;
+                    }
+                    typeChequeSelected.css('border-color','#ccc');
+                }
+                /**
+                 * [Verify Bank Paymnets]
+                 */
+                if ((_.contains(nameClas, 'payments-bank-id')) || (_.contains(nameClas, 'payments-number')) || (_.contains(nameClas, 'payments-number-cta'))){
+                    var fieldsPayments = _.map(self.fieldsBank, function(map){
+                        return map.field
+                    });
+                    if ((_.contains(fieldsPayments, 'payments-bank-id')) && (_.contains(fieldsPayments, 'payments-number')) && (_.contains(fieldsPayments, 'payments-number-cta'))){
+
+                        var paymentsBankId = $('.expired-account-modal').find('.payments-bank-id');
+                        var paymentsNumber = $('.expired-account-modal').find('.payments-number');
+                        var paymentsNumberCta = $('.expired-account-modal').find('.payments-number-cta');
+
+                        if (!!bankId && !!paymentsNumber.val() && paymentsNumberCta.val() && !(typePayments.allow_duplicate_operation)) {
+                            var chechNumberCh = self.checkNumber(bankId, paymentsNumberCta.val().trim(), paymentsNumber.val().trim()).shift();
+                            self.verifyOperacionBank(chechNumberCh, amountPayments, currencyId, typePayments);
+                        }
+                    }
+                }
+            });
+
+            /* Total a pagar keyup */
+            amountPayments.keyup(function(e) {
+                currencyId = self.getCurrencySelect(self.accountInvoice[0].currency_id[0]).shift();
+                if (journalSelect.val()) {
+                    currencyId = self.getSelectedJournal(journalSelect.val()).shift();
+                }
+
+                if (e.key === currencyId.decimalSeparator && currencyId.decimalPlaces > 0)
+                    return false ;
+
+                var amount_add = instanceWeb.unFormatCurrency(amountPayments.val());
+                amountPayments.val(instanceWeb.formatCurrency(amount_add, currencyId));
+
+                amountPayments.css('border-color','#ccc');
+
+                if (e.keyCode === 13)
+                    savePaymentsButton.focus();
+            });
+            /* focusout */
+            amountPayments.focusout(function(e) {
+                currencyId = self.getCurrencySelect(self.accountInvoice[0].currency_id[0]).shift();
+                if (journalSelect.val()) {
+                    currencyId = self.getSelectedJournal(journalSelect.val()).shift();
+                }
+
+                var amountTotalPayments = instanceWeb.unFormatCurrency(amountPayments.val());
+                var paymentsTotal = instanceWeb.unFormatCurrency(amountTotal.val());
+
+                if (amountTotalPayments <=  0) {
+                    openerp.web.notification.do_warn("Atencion", "El monto a pagar no puede ser 0.");
+                    amountPayments.css('border-color','red');
+                    amountPayments.focus();
+                }
+
+                var fields = "";
+                $('.expired-account-modal').find('.ammount-returned').css('display','none');
+                $('.expired-account-modal').find('.ammount-returned').empty();
+                if (amountTotalPayments > paymentsTotal) {
+                    var returned = (instanceWeb.formatCurrency((amountTotalPayments - paymentsTotal), currencyId));
+                    $('.expired-account-modal').find('.ammount-returned').css('display','flex');
+                    fields +=   '<label class="payments-invoice-label invoice-payment-label-select"> Vuelto </label>';
+                    fields +=   '<div class="payments-invoice-group invoice-payment-input-select">';
+                    fields +=       '<input type="text" class="form-control payments-invoice-input" readonly="readonly" value="'+returned+'"></input>';
+                    fields +=       '<div class="payments-invoice-symbol">';
+                    fields +=           '<span class="input-group-text amount-total-symbol">'+currencyId.symbol+'</span>';
+                    fields +=       '</div>';
+                    fields +=   '</div>';
+                    $('.expired-account-modal').find('.ammount-returned').append(fields);
+                }
+            });
+
+            /* Save Payments */
+            savePaymentsButton.click(function(e) {
+                var savePayments = [];
+                var paymentsAmount = 0;
+                var currencyJournal = [];
+                var journal = [];
+                var chechNumberCh = [];
+
+                /* Verificar si se selecciono algunas cuotas */
+                if (!self.movePayments ||!self.movePayments.length) {
+                    openerp.web.notification.do_warn("Atencion", "Tienes que seleccionar al menos una cuota  para continuar.");
+                    return false;
+                }
+
+                /* Verificar si se seleccionado el método de pago */
+                if (!journalSelect.val()) {
+                    openerp.web.notification.do_warn("Atencion", "Tienes que seleccionar un método de pago para continuar.");
+                    journalSelect.css('border-color','red');
+                    journalSelect.focus();
+                    return false;
+                }
+                journalSelect.css('border-color','#ccc');
+
+                journal = self.getJournal(journalSelect.val());
+                currencyJournal = self.getSelectedJournal(journalSelect.val()).shift();
+                paymentsAmount = instanceWeb.unFormatCurrency(amountPayments.val());
+
+                /* verificar si fue ingresado el monto a pagar */
+                if (paymentsAmount <= 0 ) {
+                    openerp.web.notification.do_warn("Atencion", "El monto a pagar no debe ser 0.");
+                    amountPayments.css('border-color','red');
+                    amountPayments.focus();
+                    return false;
+                }
+                amountPayments.css('border-color','#ccc');
+                /* Verificar Caja */
+                var statement = self.getStatementeJournal(journal[0].id);
+                if (!!self.eiruAccountBankStatementUtility.length){
+                    if (!!self.statementConfig.length) {
+                        if (!!statement.length && !statementSelect.val() && self.statementConfig[0].import_statement_payments === 'manual_import'){
+                            openerp.web.notification.do_warn("Atencion", "Tienes que seleccionar una caja para continuar.");
+                            statementSelect.css('border-color','red');
+                            statementSelect.val();
+                            return false;
+                        }
+                    }
+                }
+                statementSelect.css('border-color','#ccc');
+
+
+                typeOperationBank = self.filterTypeOperationBank(journal[0].id);
+                if (!!typeOperationBank.length && !bankTypeSelect.val()){
+                    openerp.web.notification.do_warn("Atencion", "Tienes que seleccionar el tipo de pago para continuar .");
+                    bankTypeSelect.css('border-color','red');
+                    bankTypeSelect.focus();
+                    return false;
+                }
+                bankTypeSelect.css('border-color','#ccc');
+
+                /**
+                *    [Verificar Datos de Operación bancarias]
+                */
+                var fieldsBankRequired =  self.verifyFields().shift();
+                if (fieldsBankRequired) {
+                    var fields = $('.expired-account-modal').find('.'+fieldsBankRequired.field);
+                    if (fieldsBankRequired.required) {
+                        openerp.web.notification.do_warn("Atencion", "El campo "+fieldsBankRequired.label+" es obligatorio.");
+                        fields.css('border-color','red');
+                        fields.focus();
+                        return false;
+                    }
+                }
+
+                /**
+                *   [Verificar Operacion bancarias]
+                */
+                var fieldsPayments = _.map(self.fieldsBank, function(map){
+                    return map.field
+                });
+                if ((_.contains(fieldsPayments, 'payments-bank-id')) && (_.contains(fieldsPayments, 'payments-number')) && (_.contains(fieldsPayments, 'payments-number-cta'))){
+
+                    var paymentsBankId = $('.expired-account-modal').find('.payments-bank-id');
+                    var paymentsNumber = $('.expired-account-modal').find('.payments-number');
+                    var paymentsNumberCta = $('.expired-account-modal').find('.payments-number-cta');
+
+                    if (!!bankId && !!paymentsNumber.val() && paymentsNumberCta.val() && !(typePayments.allow_duplicate_operation)) {
+                        var chechNumberCh = self.checkNumber(bankId, paymentsNumberCta.val().trim(), paymentsNumber.val().trim()).shift();
+                        if (! self.verifyOperacionBank(chechNumberCh, amountPayments, currencyId, typePayments))
+                            return false;
+                    }
+                }
+                /* */
+                var bankOperation = {};
+                var fiedsConcat = '{';
+                var contobjetc=0
+                _.each(self.fieldsBank, function(item, index, list) {
+                    var fieldwidget = $('.expired-account-modal').find('.'+item.field);
+                    var fieldsValue = undefined;
+                    if(!!fieldwidget.val())
+                        fieldsValue = '"'+fieldwidget.val()+'"';
+
+                    if (_.contains(['many2one', 'many2many', 'one2many'], item.type)) {
+                        fieldsValue = parseInt(fieldwidget.val().trim());
+
+                        if (item.searchType === 'autocomplete') {
+                            var valueFieds = fieldwidget.val().split('-');
+                            fieldsValue = parseInt(valueFieds[0].trim());
+                        }
+                    }
+                    if (_.contains(['float','int'], item.type)){
+                        fieldsValue = instanceWeb.unFormatCurrency(fieldwidget.val());
+                        if (fieldsValue <= 0)
+                            fieldsValue = "";
+                    }
+                    if (!!fieldsValue){
+                        if(contobjetc > 0)
+                            fiedsConcat = fiedsConcat.concat(',');
+                        fiedsConcat = fiedsConcat.concat('"'+item.name+'": '+fieldsValue);
+                        contobjetc++
+                    }
+                });
+                fiedsConcat = fiedsConcat.concat('}');
+                bankOperation = JSON.parse(fiedsConcat)
+
+                if (bankOperation) {
+                    bankOperation.bank_payments_type_id = parseInt(bankTypeSelect.val())
+                }
+
+                /* Save object */
+                savePayments = {
+                    'invoiceId': self.accountInvoice[0].id,
+                    'JournalId': journal[0].id,
+                    'partnerId': self.resPartner[0].id ,
+                    'amountPayments': self.movePayments[0].amountResidual < paymentsAmount ? self.movePayments[0].amountResidual : paymentsAmount,
+                    'moveLines': self.movePayments[0].ids,
+                    'JournalType': journal[0].type,
+                    'statementId': !!statementSelect.val() ? parseInt(statementSelect.val()) : '',
+                    'bankPayments': bankOperation,
+                    'voucherName' : !!($('.expired-account-modal').find('.voucher-name').val()).trim() ?$('.expired-account-modal').find('.voucher-name').val() : '',
+                    'voucherObs' : !!($('.expired-account-modal').find('.voucher-obs').val()).trim() ?$('.expired-account-modal').find('.voucher-obs').val() : '',
+                    'voucherSeq': self.accountInvoice[0].seq_invoice,
+                    'datePayments': dateOperation.val(),
+                };
+                /* Save Payments */
+                $('.expired-account-modal').find('.widget-content.widget-loading-payments').css('display','flex');
+                self.savePaymentsInvoice(savePayments).then(function(resultsPayments) {
+                    return resultsPayments;
+                }).then(function(resultsPayments) {
+                    self.reloadPage();
+                    $('.expired-account-modal').find('.widget-content.widget-loading-payments').css('display','none');
+                    self.removeModal(e);
+                    if (!resultsPayments)
+                        results = false;
+                });
+
+                defer.resolve(results);
+            });
+
+            /* Cerrar */
+            $('.expired-account-modal').on('hidden.bs.modal', function(e) {
+                results = false;
+                defer.resolve(results);
+                self.removeModal(e);
+            });
+
+            return defer;
+        },
+
+        /* Verificar Operation Bank */
+        verifyOperacionBank: function(chechNumberCh, amountPayments, currencyId, typePayments){
+            var self = this;
+            var paymentsChequeTypeId = $('.expired-account-modal').find('.payments-cheque-type-id');
+            var paymentsNameHolder = $('.expired-account-modal').find('.payments-name-holder');
+            var paymentsAmountTotal = $('.expired-account-modal').find('.payments-amount-total');
+            var paymentsDateMaturity = $('.expired-account-modal').find('.payments-date-maturity');
+
+            /* Clear */
+            if (!chechNumberCh) {
+                if (paymentsChequeTypeId.length) {
+                    paymentsChequeTypeId.removeAttr("disabled");
+                    paymentsChequeTypeId.css('background-color', 'white');
+                }
+                if (paymentsNameHolder.length) {
+                    paymentsNameHolder.removeAttr("disabled");
+                    paymentsNameHolder.css('background-color', 'white');
+                }
+                if (paymentsAmountTotal.length) {
+                    paymentsAmountTotal.removeAttr("disabled");
+                    paymentsAmountTotal.css('background-color', 'white');
+                }
+                if (paymentsDateMaturity.length) {
+                    paymentsDateMaturity.val(moment().format("YYYY-MM-DD"));
+                    paymentsDateMaturity.removeAttr("disabled");
+                    paymentsDateMaturity.css('background-color', 'white');
+                }
+                return true
+            }
+
+            if(chechNumberCh.state !== 'available') {
+                openerp.web.notification.do_warn("Atencion", ""+typePayments.name+" no disponible ");
+                return false;
+            }
+            if (paymentsChequeTypeId.length) {
+                var classPayments =((paymentsChequeTypeId[0].className).trim()).split(" ");
+                var typeCheque = chechNumberCh.chequeTypeId;
+
+                if (_.contains(classPayments, 'ui-autocomplete-input')){
+                    var chequeTypeValue =  self.getBankChequeType(parseInt(chechNumberCh.chequeTypeId)).shift();
+                    if (chequeTypeValue)
+                        typeCheque = chequeTypeValue.id+" - "+chequeTypeValue.name;
+                }
+                paymentsChequeTypeId.val(typeCheque);
+                paymentsChequeTypeId.attr("disabled", true);
+                paymentsChequeTypeId.css('background', '#eee');
+            }
+
+            if (paymentsNameHolder.length) {
+                paymentsNameHolder.val(chechNumberCh.nameHolder);
+                paymentsNameHolder.attr("disabled", true);
+                paymentsNameHolder.css('background', '#eee');
+            }
+
+            if (paymentsAmountTotal.length) {
+                paymentsAmountTotal.val(instanceWeb.formatCurrency(chechNumberCh.amountTotal, currencyId));
+                paymentsAmountTotal.attr("disabled", true);
+                paymentsAmountTotal.css('background', '#eee');
+            }
+
+            if (paymentsDateMaturity.length) {
+                paymentsDateMaturity.val(chechNumberCh.dateMaturity);
+                paymentsDateMaturity.attr("disabled", true);
+                paymentsDateMaturity.css('background', '#eee');
+            }
+
+            var paymentsAmount = instanceWeb.unFormatCurrency(amountPayments.val());
+            var totalBank = 0;
+            var amountBank = 0;
+            var amountRefund = 0;
+            totalBank = chechNumberCh.amountTotal;
+
+            /* factura ventas */
+            if ((self.accountInvoice[0].type === 'out_invoice') || (self.accountInvoice[0].type === 'in_refund')) {
+                amountBank = chechNumberCh.amountReceipt;
+                if (self.accountInvoice[0].type === 'in_refund')
+                    amountRefund = chechNumberCh.amountReceipt;
+            }
+
+            /*factura compras/gastos */
+            if ((self.accountInvoice[0].type === 'in_invoice') || (self.accountInvoice[0].type === 'out_refund')) {
+                amountBank = chechNumberCh.amountPayment;
+                if (self.accountInvoice[0].type === 'out_refund')
+                    amountRefund = chechNumberCh.amountPayment;
+            }
+
+            /* verificar saldo disponible */
+            if (totalBank <= amountBank) {
+                openerp.web.notification.do_warn("Atencion", typePayments.name + " sin saldo disponible.");
+                return false;
+            }
+
+            /* verificar si el monto a pagar no es mayor al monto disponible */
+            amountBalanceBank = (totalBank - amountBank);
+            var amountBalanceBankFoirmat = instanceWeb.formatCurrency(amountBalanceBank, currencyId);
+            if (paymentsAmount > amountBalanceBank) {
+                openerp.web.notification.do_warn("Atencion", "El monto a pagar supera al saldo disponible del.\n Saldo disponible = "+amountBalanceBankFoirmat);
+                amountPayments.css('border-color','red');
+                amountPayments.focus();
+                return false;
+            }
+            /* Focus button 'Guaradar' */
+             $('.expired-account-modal').find('.save-payments-button').focus();
+             return true
+        },
+        /* Verify Bank Field */
+        verifyFields: function(){
+            var self = this;
+            return _.filter(self.fieldsBank, function(item) {
+                var field = $('.expired-account-modal').find('.'+item.field);
+                field.css('border-color','#ccc');
+                return item.required && !(field.val().trim());
+            });
+        },
+        /*  Guaradar Pagos */
+        savePaymentsInvoice: function(savePayments) {
+            var self = this;
+            var invoiceUpdate = new openerp.web.Model('account.invoice');
+            return invoiceUpdate.call('save_payments_invoice',[savePayments], {
+                context: new openerp.web.CompoundContext()
+            });
+        },
+    });
+
+    if (openerp.web && openerp.web.FormView) {
+        openerp.web.FormView.include({
+            load_record: function(record) {
+                this._super.apply(this, arguments);
+
+                if (this.model !== 'account.invoice')
+                    return;
+
+                openerp.parentInstancePaymentsInvoices = this;
+
+                if (record.state !== 'open')
+                    return;
+
+                if (openerp.widgetInstancePaymentsInvoices) {
+                    openerp.widgetInstancePaymentsInvoices.updateId(record.id);
+                    if (this.$el.find('.button-payments-invoices').length !== 0 )
+                        return ;
+                }
+
+                if (this.$el.find('.button-payments-invoices').length !== 0 )
+                    return;
+
+                openerp.widgetInstancePaymentsInvoices = new openerp.EiruPaymentsInvoices(this);
+                var element =this.$el.find('.oe_form').find('.eiru-payments-invoices');
+
+                openerp.widgetInstancePaymentsInvoices.appendTo(element[0]);
+                openerp.widgetInstancePaymentsInvoices.updateId(record.id);
+            }
+        });
+    }
+})();

+ 8 - 0
static/src/xml/eiru_payments.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<templates xml:space="preserve">
+    <t t-name="eiruPaymentsInvoices.Invoices">
+        <button class="button-payments-invoices oe_button oe_form_button oe_highlight">
+            <div>Registrar pago</div>
+        </button>
+  </t>
+</templates>

+ 234 - 0
static/src/xml/modal/modal_eiru_payments_invoices.xml

@@ -0,0 +1,234 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="eiruPaymentsInvoices.Modal">
+        <div class="modal in expired-account-modal" tabindex="-1" role="dialog"  data-backdrop="static">
+            <div class="modal-dialog modal-lg" role="document">
+                <div class="modal-content openerp">
+                    <div class="widget-content widget-loading-payments">
+                        <i class='fa fa-cog fa-spin fa-3x fa-fw'></i>
+                    </div>
+                    <!-- title  -->
+                    <div class="modal-header paymnets-invoice-header">
+                        <button type="button" class="close" data-dismiss="modal" aria-label="Close" aria-hidden="true">×</button>
+                        <h3 class="modal-title">Registrar pagos</h3>
+                    </div>
+                    <!-- Body -->
+                    <div class="modal-body">
+                        <!-- Table -->
+                        <div class=" oe_view_manager_body payments-invoice-table">
+                            <div class="modal-head-wrapper-payments-invoice">
+                                <table class="oe_list_content">
+                                    <thead >
+                                        <tr class="oe_list_header_columns"  >
+                                            <th class="oe_list_header_char oe_sortable"></th>
+                                            <th class="oe_list_header_char oe_sortable"></th>
+                                            <th class="oe_list_header_char oe_sortable">Vencimiento</th>
+                                            <th class="oe_list_header_char oe_sortable">Total</th>
+                                            <th class="oe_list_header_char oe_sortable">Saldo</th>
+                                        </tr>
+                                    </thead>
+                                </table>
+                            </div>
+                            <div class="modal-item-paymnets-invoice">
+                                <table class="oe_list_content">
+                                    <tbody class="table-tbody">
+                                        <!-- <tr> -->
+                                        <tr t-foreach="moveLine" t-as="line">
+                                            <td>
+                                                <t t-esc="line_value.id"/>
+                                            </td>
+                                            <td>
+                                                <input type="checkbox" class="select-move-payments"></input>
+                                            </td>
+                                            <td>
+                                                <t t-esc="line_value.dateMaturity"/>
+                                            </td>
+                                            <td></td>
+                                            <td>
+                                                <t t-esc="line_value.debitFormat"/>
+                                            </td>
+                                            <td>
+                                                <t t-esc="line_value.residualFormat"/>
+                                            </td>
+                                        </tr>
+                                    </tbody>
+                                </table>
+                            </div>
+                        </div>
+                        <!-- Payments -->
+                        <div class="row ">
+                            <div class="col-xs-6">
+                                <label class="payments-invoice-label invoice-payment-label-select">Total a pagar</label>
+                                <div class="payments-invoice-group invoice-payment-input-select">
+                                  <input type="text" class="form-control payments-invoice-input amount-total" readonly="readonly" value="0"></input>
+                                  <div class="payments-invoice-symbol">
+                                    <span class="input-group-text amount-total-symbol"></span>
+                                  </div>
+                                </div>
+                            </div>
+                            <div class="col-xs-6">
+                                <label class="payments-invoice-label invoice-payment-label-select">Nº Recibo</label>
+                                <div class="payments-invoice-group invoice-payment-input-select">
+                                    <input type="text" class="form-control voucher-name"></input>
+                                </div>
+                            </div>
+                        </div>
+
+                        <div class="row ">
+                            <div class="col-xs-12">
+                                <label class="payments-invoice-label invoice-payment-label-select">Obs.</label>
+                                <div class="payments-invoice-group invoice-payment-input-select">
+                                    <input type="text" class="form-control voucher-obs"></input>
+                                </div>
+                            </div>
+                        </div>
+
+                        <div class="row ">
+                            <div class="col-xs-6">
+                                <label class="payments-invoice-label invoice-payment-label-select">Método de pago: </label>
+                                <div class="payments-invoice-group invoice-payment-input-select">
+                                    <select class="payments-invoice-input invoice-payment-input journal-select">
+                                        <t t-foreach="journal" t-as="journal">
+                                            <option t-attf-value="{{ journal_value.code }}" >
+                                                <t t-esc="journal_value.name"/>
+                                            </option>
+                                        </t>
+                                    </select>
+                                </div>
+                            </div>
+                            <div class="col-xs-6">
+                                <label class="payments-invoice-label invoice-payment-label-select">Monto a pagar</label>
+                                <div class="payments-invoice-group invoice-payment-input-select">
+                                  <input type="text" class="form-control payments-invoice-input amount-payments" value="0"></input>
+                                  <div class="payments-invoice-symbol">
+                                    <span class="input-group-text amount-payments-symbol"></span>
+                                  </div>
+                                </div>
+                            </div>
+                        </div>
+
+                        <div class="row ">
+                            <div class="col-xs-6">
+                                <label class="payments-invoice-label invoice-payment-label">Fecha de operación</label>
+                                <div class="payments-invoice-group invoice-payment-input-date">
+                                    <input type="date" class="form-control payments-invoice-input input-date date-operation"></input>
+                                    <!-- readonly="readonly" -->
+                                </div>
+                            </div>
+                            <div class="col-xs-6 statement-config">
+                                <label class="payments-invoice-label invoice-payment-label-select">Caja </label>
+                                <div class="payments-invoice-group invoice-payment-input-select">
+                                    <select class="payments-invoice-input invoice-payment-input statement-select">
+                                    </select>
+                                </div>
+                            </div>
+
+                        </div>
+                        <div class="row">
+                            <div class="col-xs-6 type-select-bank">
+                                <label class="payments-invoice-label invoice-payment-label-select">Tipo de Pago</label>
+                                <div class="payments-invoice-group invoice-payment-input-select">
+                                    <select class="payments-invoice-input invoice-payment-input bank-type-select">
+                                    </select>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="eiru-banking-operation"></div>
+
+                        <!-- Operación bancaria -->
+                        <!-- <hr class="payments-invoice-hr type-card"/>
+                        <div class="row type-select-bank">
+                            <h3 class="from-title-h3">Operación bancaria</h3>
+                        </div> -->
+                        <!-- <div class="row ">
+                            <div class="col-xs-6 type-select-bank">
+                                <label class="payments-invoice-label invoice-payment-label-select">Tipo de Pago</label>
+                                <div class="payments-invoice-group invoice-payment-input-select">
+                                    <select class="payments-invoice-input invoice-payment-input bank-type-select">
+                                    </select>
+                                </div>
+                            </div> -->
+
+
+                            <!-- <div class="col-xs-6 select-bank-id">
+                                <label class="payments-invoice-label invoice-payment-label-select">Banco/Entidad</label>
+                                <div class="payments-invoice-group invoice-payment-input-select">
+                                    <input type="text" class="form-control ui-autocomplete-input bank-select" autocomplete="off" placeholder="Banco/Entidad"></input>
+                                </div>
+                            </div> -->
+                        <!-- </div> -->
+
+                        <!-- <div class="row">
+                            <div class="col-xs-6 select-number-cta">
+                                <label class="payments-invoice-label invoice-payment-label-select">Nº Cuenta: </label>
+                                <div class="payments-invoice-group invoice-payment-input-select">
+                                    <input type="text" class="form-control bank-number-cta"></input>
+                                </div>
+                            </div>
+                            <div class="col-xs-6 select-number">
+                                <label class="payments-invoice-label invoice-payment-label-select number-label"></label>
+                                <div class="payments-invoice-group invoice-payment-input-select">
+                                  <input type="text" class="form-control bank-number"></input>
+                                </div>
+                            </div>
+                        </div> -->
+
+                        <!-- <div class="row">
+                            <div class="col-xs-6 select-number-cta-origin">
+                                <label class="payments-invoice-label invoice-payment-label-select">Nº Cuenta Origen: </label>
+                                <div class="payments-invoice-group invoice-payment-input-select">
+                                    <input type="text" class="form-control bank-number-cta-origen"></input>
+                                </div>
+                            </div>
+                            <div class="col-xs-6 select-date-maturity ">
+                                <label class="payments-invoice-label invoice-payment-label-select">Vencimiento</label>
+                                <div class="payments-invoice-group invoice-payment-input-select">
+                                    <input type="date" class="form-control payments-invoice-input input-date bank-date-maturity"></input>
+                                </div>
+                            </div>
+                        </div> -->
+
+                        <!-- <div class="row">
+                            <div class="col-xs-6 select-check-type-id">
+                                <label class="payments-invoice-label invoice-payment-label-select">Tipo de cheque</label>
+                                <div class="payments-invoice-group invoice-payment-input-select">
+                                    <select class="payments-invoice-input invoice-payment-input bank-check-type-select">
+                                        <t t-foreach="bankTypeCheck" t-as="bankTypeCheck">
+                                            <option t-attf-value="{{ bankTypeCheck_value.id }}" >
+                                                <t t-esc="bankTypeCheck_value.name"/>
+                                            </option>
+                                        </t>
+                                    </select>
+                                </div>
+                            </div>
+                            <div class="col-xs-6 select-amount-total">
+                                <label class="payments-invoice-label invoice-payment-label-select">Monto Cheque</label>
+                                <div class="payments-invoice-group invoice-payment-input-select">
+                                  <input type="text" class="form-control payments-invoice-input amount-payments-bank" value="0"></input>
+                                  <div class="payments-invoice-symbol">
+                                    <span class="input-group-text amount-payments-symbol"></span>
+                                  </div>
+                                </div>
+                            </div>
+                        </div> -->
+
+                        <!-- <div class="row">
+                            <div class="col-xs-12 select-name-holder">
+                                <label class="payments-invoice-label invoice-payment-label-select">Titular</label>
+                                <div class="bank-payments-group invoice-payment-input-select">
+                                    <input type="text" class="form-control bank-name-holder"></input>
+                                </div>
+                            </div>
+                        </div> -->
+                    </div>
+                    <!-- Pie de Pagina -->
+                    <div class="modal-footer paymnets-invoice-footer">
+                        <button type="button" class="oe_button oe_form_button oe_highlight button-accept payments-invoice-button save-payments-button">Guardar</button>
+                        <button type="button" class="oe_button oe_form_button oe_link dismmis-modal payments-invoice-button" data-dismiss="modal">Salir</button>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </t>
+
+</template>

+ 34 - 0
views/eiru_payments_invoices.xml

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+	<data>
+		<record id="view_eiru_payments_invoices" model="ir.ui.view">
+			<field name="name">view.eiru.payments.invoices</field>
+			<field name="model">account.invoice</field>
+			<field name="inherit_id" ref="account.invoice_form"/>
+			<field name="arch" type="xml">
+				<xpath expr="//button[@name='invoice_pay_customer']" position="replace">
+					<div class="eiru-payments-invoices" attrs="{'invisible': [('state','!=','open')]}"> </div>
+				</xpath>
+			</field>
+		</record>
+		<record id="view_eiru_payments_invoices_supplier" model="ir.ui.view">
+			<field name="name">view.eiru.payments.invoices.supplier</field>
+			<field name="model">account.invoice</field>
+			<field name="inherit_id" ref="account.invoice_supplier_form"/>
+			<field name="arch" type="xml">
+				<xpath expr="//button[@name='invoice_pay_customer']" position="replace">
+					<div class="eiru-payments-invoices" attrs="{'invisible': [('state','!=','open')]}"> </div>
+				</xpath>
+			</field>
+		</record>
+
+		<record id="view_eiru_payments_invoices_voucher_customer" model="ir.ui.view">
+			<field name="name">view.eiru.payments.invoices.voucher.customer</field>
+			<field name="model">account.invoice</field>
+			<field name="inherit_id" ref="account_voucher.view_invoice_customer"/>
+			<field name="arch" type="xml">
+				<xpath expr="//button[@name='invoice_pay_customer']" position="replace"></xpath>
+			</field>
+		</record>
+	</data>
+</openerp>

+ 10 - 0
views/templates.xml

@@ -0,0 +1,10 @@
+<openerp>
+    <data>
+        <template id="eiru_payments_invoices.eiru_assets" name="eiru_payments_invoices_eiru_assets" inherit_id="eiru_assets.assets">
+            <xpath expr="." position="inside">
+                <link rel="stylesheet" href="/eiru_payments_invoices/static/src/css/style.css"/>
+                <script type="text/javascript" src="/eiru_payments_invoices/static/src/js/eiru_payments_invoices.js"/>
+            </xpath>
+        </template>
+    </data>
+</openerp>