account_bank_statement.py 2.0 KB

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