product_pricelist.py 847 B

123456789101112131415161718192021222324252627282930
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_pricelist_id(currency_id):
  4. if not currency_id:
  5. return None
  6. domain = [
  7. ('active', '=', True),
  8. ('type', '=', 'sale')
  9. ]
  10. pricelist = r.env['product.pricelist'].search(domain)
  11. if not True in pricelist.mapped(lambda p: p.currency_id.id == currency_id):
  12. pricelist = pricelist[0].copy()
  13. pricelist.write({
  14. 'currency_id': currency_id
  15. })
  16. else:
  17. pricelist = pricelist.filtered(lambda p: p.currency_id.id == currency_id)
  18. if len(pricelist) > 1:
  19. pricelist = pricelist[0]
  20. # lambda self, cr, uid, context: context.get('partner_id', False) and self.pool.get('res.partner').browse(cr, uid, context['partner_id']).property_product_pricelist_purchase.id
  21. return pricelist.id