res_partner.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. 'pricelistId': customer.property_product_pricelist.id or None
  21. } for customer in request.env['res.partner'].search(domain)
  22. ]
  23. '''
  24. Create and get customer
  25. '''
  26. def create_customer(values):
  27. customer = request.env[_MODEL].sudo().create({
  28. 'name': values.get('name'),
  29. 'ruc': values.get('ruc'),
  30. 'mobile': values.get('mobile'),
  31. 'customer': True
  32. })
  33. return {
  34. 'id': customer.id,
  35. 'name': customer.display_name,
  36. 'image': customer.image_small,
  37. 'ruc': customer.ruc or None,
  38. 'phone': customer.phone or None,
  39. 'mobile': customer.mobile or None,
  40. 'email': customer.email or None
  41. }