account_bank_statement.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 '')
  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. ('date', '=', date_today)
  28. ]
  29. account_bank_statement = request.env[_MODEL].search(domain)
  30. account_bank_statement_lines = create_bank_statement_lines(account_voucher_id)
  31. account_bank_statement_values = {
  32. 'date': date_today,
  33. 'user_id': request.env.user.id,
  34. 'journal_id': account_voucher.journal_id.id,
  35. 'period_id': account_voucher.period_id.id,
  36. 'line_ids': account_bank_statement_lines,
  37. 'state': 'open' if account_voucher.journal_id.type == 'cash' else 'draft'
  38. }
  39. if account_bank_statement:
  40. size = len(account_bank_statement)
  41. if size == 1:
  42. account_bank_statement.write(account_bank_statement_values)
  43. else:
  44. account_bank_statement[size - 1].write(account_bank_statement_values)
  45. else:
  46. account_bank_statement.create(account_bank_statement_values)
  47. return account_bank_statement