account_invoice_multi_store.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_account_invoice_multi_store_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]),
  16. journal.store_id
  17. FROM account_invoice AS invoice
  18. LEFT JOIN res_store_journal_rel AS journal
  19. ON journal.journal_id = invoice.journal_id
  20. LEFT JOIN res_currency_rate AS rate
  21. ON rate.currency_id = invoice.currency_id
  22. LEFT JOIN res_company AS company
  23. ON company.id = invoice.company_id
  24. WHERE invoice.state NOT IN ('draft', 'cancel')
  25. AND TO_CHAR(invoice.date_invoice,'YYYY-MM') = TO_CHAR(current_date,'YYYY-MM')
  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. journal.store_id
  37. '''
  38. r.cr.execute(query,(tuple([company_currency_rate])))
  39. return [
  40. {
  41. 'invoice_id': j[0],
  42. 'currency_id': j[1],
  43. 'date': j[2],
  44. 'type': j[3],
  45. 'origin': j[4],
  46. 'customer_id':j[5],
  47. 'user_id':j[6],
  48. 'amount':j[7],
  49. 'store_id':j[8]
  50. } for j in r.cr.fetchall()
  51. ]