account_bank_statement.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def create_bank_statement_lines(account_voucher_id, reference=None):
  4. account_voucher = r.env['account.voucher'].browse(account_voucher_id)
  5. amount = account_voucher.amount
  6. if account_voucher.type == 'payment':
  7. amount = amount * -1
  8. return [[0, False, {
  9. 'name': account_voucher.reference,
  10. 'amount': amount,
  11. 'partner_id': account_voucher.partner_id.id,
  12. 'voucher_id': account_voucher.id,
  13. 'journal_id': account_voucher.journal_id.id,
  14. 'account_id': account_voucher.account_id.id,
  15. 'journal_entry_id': account_voucher.move_id.id,
  16. 'currency_id': account_voucher.currency_id.id,
  17. 'ref': 'POS/' + (reference or '')
  18. }]]
  19. def create_bank_statement(account_voucher_id, account_bank_statement_lines, date_today):
  20. account_voucher = r.env['account.voucher'].browse(account_voucher_id)
  21. account_bank_statement = r.env['account.bank.statement'].search([('journal_id', '=', account_voucher.journal_id.id), ('date', '=', date_today)])
  22. values = {
  23. 'date': date_today,
  24. 'user_id': r.env.user.id,
  25. 'journal_id': account_voucher.journal_id.id,
  26. 'period_id': account_voucher.period_id.id,
  27. 'line_ids': account_bank_statement_lines,
  28. 'state': 'open' if account_voucher.journal_id.type == 'cash' else 'draft'
  29. }
  30. if account_bank_statement:
  31. size = len(account_bank_statement)
  32. if size == 1:
  33. account_bank_statement.write(values)
  34. else:
  35. account_bank_statement[size - 1].write(values)
  36. else:
  37. account_bank_statement.create(values)
  38. return account_bank_statement