account_invoice.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_account_invoice_sale_type():
  4. company_currency_rate = r.env.user.company_id.currency_id.rate
  5. query = '''
  6. SELECT
  7. invoice.id,
  8. rate.currency_id,
  9. invoice.date_invoice,
  10. invoice.type,
  11. invoice.origin,
  12. invoice.partner_id,
  13. invoice.user_id,
  14. invoice.amount_total * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]),
  15. invoice.number,
  16. partner.name,
  17. customer.name,
  18. invoice.amount_tax * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]),
  19. invoice.state,
  20. journal.store_id,
  21. invoice.journal_id,
  22. invoice.state,
  23. invoice.company_id
  24. FROM account_invoice AS invoice
  25. LEFT JOIN res_store_journal_rel AS journal
  26. ON journal.journal_id = invoice.journal_id
  27. LEFT JOIN res_currency_rate AS rate
  28. ON rate.currency_id = invoice.currency_id
  29. LEFT JOIN res_company AS company
  30. ON company.id = invoice.company_id
  31. LEFT JOIN res_users AS users
  32. ON users.id = invoice.user_id
  33. LEFT JOIN res_partner AS partner
  34. ON partner.id = users.partner_id
  35. LEFT JOIN res_partner AS customer
  36. ON customer.id = invoice.partner_id
  37. WHERE invoice.state NOT IN ('draft', 'cancel')
  38. AND invoice.type in ('out_invoice','out_refund')
  39. GROUP BY
  40. invoice.id,
  41. rate.currency_id,
  42. invoice.date_invoice,
  43. invoice.type,
  44. invoice.origin,
  45. invoice.amount_total,
  46. invoice.partner_id,
  47. invoice.user_id,
  48. invoice.amount_total,
  49. partner.name,
  50. customer.name,
  51. invoice.amount_tax,
  52. invoice.state,
  53. journal.store_id,
  54. invoice.journal_id,
  55. invoice.state,
  56. invoice.company_id
  57. '''
  58. r.cr.execute(query,(tuple([company_currency_rate,company_currency_rate])))
  59. return [
  60. {
  61. 'invoice_id': j[0],
  62. 'currency_id': j[1],
  63. 'date': j[2],
  64. 'type': j[3],
  65. 'origin': j[4],
  66. 'customer_id':j[5],
  67. 'user_id':j[6],
  68. 'amount':j[7],
  69. 'number':j[8],
  70. 'user_name':j[9],
  71. 'customer_name':j[10],
  72. 'amount_tax':j[11],
  73. 'state':j[12],
  74. 'store_id':j[13],
  75. 'journal_id':j[14],
  76. 'state':j[15],
  77. 'company_id':j[16]
  78. } for j in r.cr.fetchall()
  79. ]