product_pricelist.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. _MODEL = 'product.pricelist'
  4. def get_pricelists(type='sale'):
  5. domain = [
  6. ('type', '=', type),
  7. ('active', '=', True)
  8. ]
  9. return [
  10. {
  11. 'id': p.id,
  12. 'name': p.display_name,
  13. 'type': p.type,
  14. 'versions': [
  15. {
  16. 'id': v.id,
  17. 'name': v.display_name,
  18. 'companyId': v.company_id.id or None,
  19. 'items': [
  20. {
  21. 'id': i.id,
  22. 'name': i.display_name,
  23. 'base': i.base,
  24. 'basePricelistId': i.base_pricelist_id.id or None,
  25. 'minQuantity': i.min_quantity,
  26. 'priceDiscount': i.price_discount,
  27. 'priceMaxMargin': i.price_max_margin,
  28. 'priceMinMargin': i.price_min_margin,
  29. 'priceRound': i.price_round,
  30. 'priceSurcharge': i.price_surcharge,
  31. 'productId': i.product_id.id or None,
  32. 'productTmplId': i.product_tmpl_id.id or None,
  33. 'categoryId': i.categ_id or None,
  34. 'companyId': i.company_id.id or None
  35. } for i in v.items_id
  36. ],
  37. } for v in p.version_id
  38. ]
  39. } for p in r.env[_MODEL].search(domain)
  40. ]