account_bank_statement_line.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_account_bank_statement_line_widget():
  4. user_store = r.env.user.store_id.id
  5. company_currency_rate = r.env.user.company_id.currency_id.rate
  6. validate = '''
  7. SELECT EXISTS(
  8. SELECT column_name
  9. FROM information_schema.columns
  10. WHERE table_schema='public'
  11. AND table_name='account_bank_statement_line'
  12. AND column_name='pos_statement_id')
  13. '''
  14. query = '''
  15. SELECT
  16. line.id,
  17. line.journal_id,
  18. journal.currency,
  19. line.amount,
  20. CASE
  21. WHEN journal.currency IS NULL
  22. THEN line.amount
  23. ELSE line.amount * (%s / (array_agg(rate.rate ORDER BY rate.name DESC))[1])
  24. END AS amount_currency
  25. FROM account_bank_statement_line AS line
  26. LEFT JOIN account_bank_statement AS statement
  27. ON statement.id = line.statement_id
  28. LEFT JOIN res_store_journal_rel AS journal_rel
  29. ON journal_rel.journal_id = statement.journal_id
  30. LEFT JOIN account_journal AS journal
  31. ON journal.id = statement.journal_id
  32. LEFT JOIN res_currency_rate AS rate
  33. ON rate.currency_id = journal.currency
  34. WHERE TO_CHAR(line.date,'YYYY-MM') = TO_CHAR(current_date,'YYYY-MM')
  35. AND line.pos_statement_id IS NOT NULL
  36. AND journal_rel.store_id = ''' + str(user_store) + '''
  37. GROUP BY
  38. line.id,
  39. line.amount,
  40. line.journal_id,
  41. journal.currency
  42. '''
  43. r.cr.execute(validate)
  44. for j in r.cr.fetchall():
  45. band = j[0]
  46. if band == True:
  47. r.cr.execute(query,(tuple([company_currency_rate])))
  48. return [
  49. {
  50. 'id': j[0],
  51. 'journal_id': j[1],
  52. 'currency_id': j[2],
  53. 'amount': j[3],
  54. 'amount_currency': j[4],
  55. } for j in r.cr.fetchall()
  56. ]
  57. else:
  58. return []