account_journal.py 2.0 KB

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