account_journal.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request
  3. from res_users import get_current_user
  4. from res_config import get_pos_config
  5. _MODEL = 'account.journal'
  6. '''
  7. '''
  8. def get_journals():
  9. domain = [
  10. ('type', 'in', ['bank', 'cash']),
  11. ('active', '=', True)
  12. ]
  13. if not get_pos_config().get('allowCurrencyExchange'):
  14. currency_id = get_current_user().get('company').get('currencyId')
  15. domain.append('|')
  16. domain.append(('currency', '=', currency_id))
  17. domain.append(('company_id.currency_id', '=', currency_id))
  18. return [
  19. {
  20. 'id': journal.id,
  21. 'name': journal.display_name,
  22. 'code': journal.code,
  23. 'type': journal.type,
  24. 'subtype': journal.subtype or None,
  25. 'currencyId': journal.currency.id or journal.company_id.currency_id.id
  26. } for journal in request.env[_MODEL].search(domain, order='id')
  27. ]
  28. '''
  29. '''
  30. def get_currencies_from_journals():
  31. domain = [
  32. ('type', 'in', ['bank', 'cash']),
  33. ('active', '=', True)
  34. ]
  35. currencies = []
  36. for journal in request.env[_MODEL].search(domain):
  37. currency = journal.currency or journal.company_id.currency_id
  38. currencies.append({
  39. 'id': currency.id,
  40. 'name': currency.display_name,
  41. 'base': currency.base,
  42. 'symbol': currency.symbol,
  43. 'position': currency.position,
  44. 'rateSilent': currency.rate_silent,
  45. 'decimalSeparator': currency.decimal_separator,
  46. 'decimalPlaces': currency.decimal_places,
  47. 'thousandsSeparator': currency.thousands_separator
  48. })
  49. return {c['id']:c for c in currencies}.values()
  50. '''
  51. '''
  52. def get_currency(journal_id):
  53. journal = request.env['account.journal'].browse(journal_id)
  54. return journal.default_credit_account_id.currency_id.id or journal.default_credit_account_id.company_currency_id.id