account_move_line.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_account_move_line():
  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. --AND invoice.id = 20940
  45. GROUP BY invoice.number,
  46. line.date_maturity,
  47. partner.name,
  48. partner.ruc,
  49. line.credit,
  50. line.debit,
  51. invoice.id,
  52. line.reconcile_ref,
  53. line.reconcile_id,
  54. line.reconcile_partial_id,
  55. invoice.amount_total,
  56. journal.currency,
  57. journal.name
  58. '''
  59. r.cr.execute(query,(tuple([company_currency_rate])))
  60. return [
  61. {
  62. 'number': j[0],
  63. 'date_maturity': j[1],
  64. 'partner': j[2],
  65. 'ruc': j[3],
  66. 'credit': j[4],
  67. 'debit': j[5],
  68. 'invoice_id': j[6],
  69. 'reconcile_ref': j[7],
  70. 'reconcile_id': j[8],
  71. 'reconcile_partial_id': j[9],
  72. 'amount_total': j[10],
  73. 'amount_total_currency': j[11],
  74. } for j in r.cr.fetchall()
  75. ]