# -*- coding: utf-8 -*- from openerp.http import request from res_bank_payment_type import get_bank_payment_types from server_datetime import get_date _MODEL = 'res.bank.payments' ''' ''' def create_bank_payment_statement(data, invoice_id, account_voucher_id): invoice = request.env['account.invoice'].browse(invoice_id) account_voucher = request.env['account.voucher'].browse(account_voucher_id) bank_statement_line = request.env['account.bank.statement.line'].search([('voucher_id', '=', account_voucher_id)]) bank_payments_type_id = request.env['res.bank.payments.type'].get_bank_payments_type_id(account_voucher.journal_id.id) values = { 'bank_payments_type_id': bank_payments_type_id, 'bank_id': data.get('bank_id', None), 'currency_id': invoice.currency_id.id, 'date': invoice.date_invoice, 'customer_id': invoice.partner_id.id, 'number_cta': data.get('number_cta', None), 'number_cta_origin': data.get('number_cta_origin', None), 'name_holder': data.get('name_holder', None), 'number': data.get('number'), 'date_maturity': data.get('date_maturity', '') or get_date(), 'amount_total': data.get('amount', None), 'payments_line': [[0, False, { 'amount': abs(account_voucher.amount), 'amount_currency': 0.0, 'date': invoice.date_invoice, 'statement_line_id': bank_statement_line.id, 'statement_id': bank_statement_line.statement_id.id, 'type_operation': ('payment', 'receipt')[invoice.type == 'out_invoice'], 'currency_id': invoice.currency_id.id }]] } request.env['res.bank.payments'].create(values)