account_journal.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # -*- codign: utf-8 -*-
  2. from openerp.http import request
  3. from eiru_logging import make_info_log
  4. _MODEL='account.journal'
  5. def get_currencies_from_journal():
  6. make_info_log('GET currency the journal active in store')
  7. domain = [('type', 'in', ['bank', 'cash']),('active', '=', True)]
  8. currencies = []
  9. for j in request.env[_MODEL].search(domain):
  10. c = j.currency or j.company_id.currency_id
  11. currencies.append({
  12. 'id': c.id,
  13. 'name': c.display_name,
  14. 'base': c.base,
  15. 'symbol': c.symbol,
  16. 'position': c.position,
  17. 'rateSilent': c.rate_silent,
  18. 'decimalSeparator': c.decimal_separator,
  19. 'decimalPlaces': c.decimal_places,
  20. 'thousandsSeparator': c.thousands_separator
  21. })
  22. return {c['id']:c for c in currencies}.values()
  23. ''' all active journals '''
  24. def get_journals(type=None):
  25. make_info_log('GET Journal active in store')
  26. if ((not type[0]) or (not type)):
  27. type= ['bank', 'cash']
  28. user = request.env.user
  29. journal = []
  30. for store in user.store_ids:
  31. for journalID in store.journal_ids:
  32. if (journalID.type in ['bank', 'cash']):
  33. journal.append(journalID.id)
  34. # domain = [('type', 'in', type), ('default_debit_account_id.currency_id', '=', False), ('active', '=', True)]
  35. domain = [('type', 'in', type),('active', '=', True)]
  36. if (journal):
  37. domain.append(('id', 'in', journal ))
  38. return [{
  39. 'id': journal.id,
  40. 'name': journal.name,
  41. 'displayName': journal.display_name,
  42. 'code': journal.code,
  43. 'cashControl': journal.cash_control,
  44. 'type': journal.type,
  45. 'storeIds': map(lambda x: x.id, journal.store_ids),
  46. 'currency': {
  47. 'id': journal.currency.id,
  48. 'name': journal.currency.name,
  49. 'displayName': journal.currency.display_name
  50. },
  51. 'defaultDebitAccount': {
  52. 'id': journal.default_debit_account_id.id,
  53. 'name': journal.default_debit_account_id.name,
  54. 'displayName': journal.default_debit_account_id.display_name,
  55. 'code': journal.default_debit_account_id.code,
  56. 'exchange_rate': journal.default_credit_account_id.exchange_rate,
  57. 'foreignBalance': journal.default_credit_account_id.foreign_balance,
  58. 'reconcile': journal.default_credit_account_id.reconcile,
  59. 'debit': journal.default_credit_account_id.debit,
  60. 'credit': journal.default_credit_account_id.credit,
  61. 'currencyMode': journal.default_credit_account_id.currency_mode,
  62. 'companyCurrency': {
  63. 'id': journal.default_credit_account_id.company_currency_id.id,
  64. 'name': journal.default_credit_account_id.company_currency_id.name,
  65. 'displayName': journal.default_credit_account_id.company_currency_id.display_name,
  66. },
  67. 'currency': {
  68. 'id': journal.default_credit_account_id.currency_id.id,
  69. 'name': journal.default_credit_account_id.currency_id.name,
  70. 'displayName': journal.default_credit_account_id.currency_id.display_name
  71. }
  72. }
  73. } for journal in request.env[_MODEL].search(domain, order='id')]