res_partner.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_customers():
  4. query = '''
  5. SELECT
  6. partner.id,
  7. partner.name,
  8. partner.ruc,
  9. partner.customer,
  10. partner.phone,
  11. partner.mobile,
  12. partner.email,
  13. partner.street,
  14. partner.street2,
  15. country.name,
  16. CASE
  17. WHEN state.parent_id IS NOT NULL
  18. THEN ( parent_state.name || ' / ' || state.name)
  19. ELSE state.name
  20. END AS state,
  21. partner.store_id,
  22. partner.company_id
  23. FROM res_partner AS partner
  24. LEFT JOIN res_country AS country
  25. ON country.id = partner.country_id
  26. LEFT JOIN res_country_state AS state
  27. ON state.id = partner.state_id
  28. LEFT JOIN res_country_state AS parent_state
  29. ON parent_state.id = state.parent_id
  30. WHERE partner.customer = true
  31. '''
  32. r.cr.execute(query)
  33. return [
  34. {
  35. 'id': j[0],
  36. 'name': j[1],
  37. 'ruc': j[2],
  38. 'customer': j[3],
  39. 'phone': j[4],
  40. 'mobile': j[5],
  41. 'email': j[6],
  42. 'street': j[7],
  43. 'street2': j[8],
  44. 'country': j[9],
  45. 'state': j[10],
  46. 'store_id': j[11],
  47. 'company_id': j[12],
  48. } for j in r.cr.fetchall()
  49. ]