res_partner.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request
  3. _MODEL = 'res.partner'
  4. '''
  5. '''
  6. def get_customers(image_type='small'):
  7. domain = [
  8. ('customer', '=', True),
  9. ('active', '=', True)
  10. ]
  11. return [
  12. {
  13. 'id': customer.id,
  14. 'name': customer.display_name,
  15. 'image': customer.image_small if image_type == 'small' else customer.image_medium,
  16. 'ruc': customer.ruc or None,
  17. 'phone': customer.phone or None,
  18. 'mobile': customer.mobile or None,
  19. 'email': customer.email or None
  20. } for customer in request.env['res.partner'].search(domain)
  21. ]
  22. '''
  23. Create and get customer
  24. '''
  25. def create_customer(**kw):
  26. customer = request.env[_MODEL].create({
  27. 'name': kw.get('name'),
  28. 'ruc': kw.get('ruc'),
  29. 'mobile': kw.get('mobile'),
  30. 'customer': True
  31. })
  32. return {
  33. 'id': customer.id,
  34. 'name': customer.display_name,
  35. 'image': customer.image_small,
  36. 'ruc': customer.ruc or None,
  37. 'phone': customer.phone or None,
  38. 'mobile': customer.mobile or None,
  39. 'email': customer.email or None
  40. }