# -*- coding: utf-8 -*- from openerp.http import request _MODEL = 'account.voucher' ''' Create voucher ''' def create_account_voucher(account_move_id, journal_id, currency_id, paid_amount): account_move = request.env['account.move'].browse(account_move_id) account_journal = request.env['account.journal'].browse(journal_id) values = { 'reference': account_move.name, 'type': 'receipt', 'journal_id': account_journal.id, 'company_id': account_move.company_id.id, 'pre_line': True, 'amount': paid_amount, 'period_id': account_move.period_id.id, 'date': account_move.date, 'partner_id': account_move.partner_id.id, 'account_id': account_journal.default_credit_account_id.id, 'currency_id': currency_id, 'line_cr_ids': [[0, False, { 'date_due': l.date_maturity, 'account_id': l.account_id.id, 'date_original': l.invoice.date_invoice, 'move_line_id': l.id, 'amount_original': abs(l.credit or l.debit or 0.0), 'amount_unreconciled': abs(l.amount_residual), 'amount': abs(l.debit) if account_move.date == l.date_maturity else 0.0, 'reconcile': account_move.date == l.date_maturity, 'currency_id': currency_id }] for l in account_move.line_id] } account_voucher = request.env[_MODEL].create(values) account_voucher.action_move_line_create() return account_voucher