account_voucher.py 1.4 KB

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