account_invoice.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_account_invoice_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.id,
  9. rate.currency_id,
  10. invoice.date_invoice,
  11. invoice.type,
  12. invoice.origin,
  13. invoice.partner_id,
  14. invoice.user_id,
  15. invoice.amount_total * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]) as invoice_rate
  16. FROM account_invoice AS invoice
  17. LEFT JOIN res_store_journal_rel AS journal
  18. ON journal.journal_id = invoice.journal_id
  19. LEFT JOIN res_currency_rate AS rate
  20. ON rate.currency_id = invoice.currency_id
  21. LEFT JOIN res_company AS company
  22. ON company.id = invoice.company_id
  23. WHERE invoice.state NOT IN ('draft', 'cancel')
  24. AND TO_CHAR(invoice.date_invoice,'YYYY-MM') = TO_CHAR(current_date,'YYYY-MM')
  25. AND journal.store_id = ''' + str(user_store) + '''
  26. GROUP BY
  27. invoice.id,
  28. rate.currency_id,
  29. invoice.date_invoice,
  30. invoice.type,
  31. invoice.origin,
  32. invoice.amount_total,
  33. invoice.partner_id,
  34. invoice.user_id,
  35. invoice.amount_total
  36. '''
  37. r.cr.execute(query,(tuple([company_currency_rate])))
  38. return [
  39. {
  40. 'invoice_id': j[0],
  41. 'currency_id': j[1],
  42. 'date': j[2],
  43. 'type': j[3],
  44. 'origin': j[4],
  45. 'customer_id':j[5],
  46. 'user_id':j[6],
  47. 'amount':j[7],
  48. } for j in r.cr.fetchall()
  49. ]