account_move_line.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_account_move_line_widget():
  4. user_store = r.env.user.store_id.id
  5. company_currency_rate = r.env.user.company_id.currency_id.rate
  6. query = '''
  7. SELECT
  8. invoice.number,
  9. line.date_maturity,
  10. partner.name,
  11. partner.ruc,
  12. line.credit,
  13. line.debit,
  14. invoice.id,
  15. line.reconcile_ref,
  16. line.reconcile_id,
  17. line.reconcile_partial_id,
  18. invoice.amount_total AS invoice_amount,
  19. CASE
  20. WHEN invoice.currency_id IS NULL
  21. THEN invoice.amount_total
  22. ELSE invoice.amount_total * (%s / (array_agg(rate.rate ORDER BY rate.name DESC))[1])
  23. END AS invoice_amount_currency
  24. -- INVOICE
  25. FROM account_invoice AS invoice
  26. -- JOURNAL/STORE
  27. LEFT JOIN res_store_journal_rel AS journal_rel
  28. ON journal_rel.journal_id = invoice.journal_id
  29. -- JOURNAL
  30. LEFT JOIN account_journal AS journal
  31. ON journal.id = invoice.journal_id
  32. -- MOVE
  33. LEFT JOIN account_move AS move
  34. ON move.name = invoice.number
  35. -- MOVE LINE
  36. LEFT JOIN account_move_line AS line
  37. ON line.move_id = move.id AND line.date_maturity IS NOT NULL
  38. -- PARTNER
  39. LEFT JOIN res_partner AS partner
  40. ON line.partner_id = partner.id
  41. -- RATE
  42. LEFT JOIN res_currency_rate AS rate
  43. ON rate.currency_id = invoice.currency_id
  44. --WHERE
  45. WHERE invoice.state = 'open'
  46. AND journal_rel.store_id = ''' + str(user_store) + '''
  47. --AND invoice.id = 20940
  48. GROUP BY invoice.number,
  49. line.date_maturity,
  50. partner.name,
  51. partner.ruc,
  52. line.credit,
  53. line.debit,
  54. invoice.id,
  55. line.reconcile_ref,
  56. line.reconcile_id,
  57. line.reconcile_partial_id,
  58. invoice.amount_total,
  59. journal.currency,
  60. journal.name
  61. '''
  62. r.cr.execute(query,(tuple([company_currency_rate])))
  63. return [
  64. {
  65. 'number': j[0],
  66. 'date_maturity': j[1],
  67. 'partner': j[2],
  68. 'ruc': j[3],
  69. 'credit': j[4],
  70. 'debit': j[5],
  71. 'invoice_id': j[6],
  72. 'reconcile_ref': j[7],
  73. 'reconcile_id': j[8],
  74. 'reconcile_partial_id': j[9],
  75. 'amount_total': j[10],
  76. 'amount_total_currency': j[11],
  77. } for j in r.cr.fetchall()
  78. ]
  79. def get_account_move_line_partial_reconcile():
  80. query = '''
  81. SELECT
  82. journal.id,
  83. line.reconcile_partial_id,
  84. line.credit,
  85. line.debit
  86. FROM account_journal AS journal
  87. LEFT JOIN account_move_line AS line
  88. ON line.journal_id = journal.id
  89. WHERE journal.type in ('bank','cash')
  90. AND line.reconcile_partial_id IS NOT NULL
  91. '''
  92. r.cr.execute(query)
  93. return [
  94. {
  95. 'journal_id': j[0],
  96. 'reconcile_partial_id': j[1],
  97. 'credit': j[2],
  98. 'debit': j[3],
  99. } for j in r.cr.fetchall()
  100. ]