account_journal.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. from res_bank_payment_type import get_bank_payment_types
  6. _MODEL = 'account.journal'
  7. def get_journals():
  8. domain = [
  9. ('type', 'in', ['bank', 'cash']),
  10. ('active', '=', True)
  11. ]
  12. if not get_pos_config().get('allowCurrencyExchange'):
  13. currency_id = get_current_user().get('company').get('currencyId')
  14. domain.append('|')
  15. domain.append(('currency', '=', currency_id))
  16. domain.append(('company_id.currency_id', '=', currency_id))
  17. return [
  18. {
  19. 'id': journal.id,
  20. 'name': journal.display_name,
  21. 'code': journal.code,
  22. 'type': journal.type,
  23. 'currencyId': journal.currency.id or journal.company_id.currency_id.id,
  24. 'fieldsAllowed': get_bank_payment_types(journal.id)
  25. } for journal in request.env[_MODEL].search(domain, order='id')
  26. ]
  27. def get_currencies_from_journals():
  28. domain = [
  29. ('type', 'in', ['bank', 'cash']),
  30. ('active', '=', True)
  31. ]
  32. currencies = []
  33. for journal in request.env[_MODEL].search(domain):
  34. currency = journal.currency or journal.company_id.currency_id
  35. currencies.append({
  36. 'id': currency.id,
  37. 'name': currency.display_name,
  38. 'base': currency.base,
  39. 'symbol': currency.symbol,
  40. 'position': currency.position,
  41. 'rateSilent': currency.rate_silent,
  42. 'decimalSeparator': currency.decimal_separator,
  43. 'decimalPlaces': currency.decimal_places,
  44. 'thousandsSeparator': currency.thousands_separator
  45. })
  46. return {c['id']:c for c in currencies}.values()
  47. def get_currency(journal_id):
  48. journal = request.env['account.journal'].browse(journal_id)
  49. return journal.default_credit_account_id.currency_id.id or journal.default_credit_account_id.company_currency_id.id