account_voucher.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request
  3. _MODEL = 'account.voucher'
  4. '''
  5. Create voucher
  6. '''
  7. def create_account_voucher(account_move_id, journal_id, currency_id, paid_amount):
  8. account_move = request.env['account.move'].browse(account_move_id)
  9. account_journal = request.env['account.journal'].browse(journal_id)
  10. values = {
  11. 'reference': account_move.name,
  12. 'type': 'receipt',
  13. 'journal_id': account_journal.id,
  14. 'company_id': account_move.company_id.id,
  15. 'pre_line': True,
  16. 'amount': paid_amount,
  17. 'period_id': account_move.period_id.id,
  18. 'date': account_move.date,
  19. 'partner_id': account_move.partner_id.id,
  20. 'account_id': account_journal.default_credit_account_id.id,
  21. 'currency_id': currency_id,
  22. 'line_cr_ids': [[0, False, {
  23. 'date_due': l.date_maturity,
  24. 'account_id': l.account_id.id,
  25. 'date_original': l.invoice.date_invoice,
  26. 'move_line_id': l.id,
  27. 'amount_original': abs(l.credit or l.debit or 0.0),
  28. 'amount_unreconciled': abs(l.amount_residual),
  29. 'amount': abs(l.debit) if account_move.date == l.date_maturity else 0.0,
  30. 'reconcile': account_move.date == l.date_maturity,
  31. 'currency_id': currency_id
  32. }] for l in account_move.line_id]
  33. }
  34. account_voucher = request.env[_MODEL].create(values)
  35. account_voucher.action_move_line_create()
  36. return account_voucher