12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- # -*- coding: utf-8 -*-
- from openerp.http import request as r
- def get_products(type=None):
- product_obj = r.env['product.template']
- domain = [('standard_price', '>=', 0), ('active', '=', True)]
- if type == 'purchase':
- domain.append(('purchase_ok', '=', True))
- else:
- if product_obj.fields_get('hr_expense_ok'):
- domain.append(('hr_expense_ok', '=', True))
- else:
- return []
- return [
- {
- 'id': p.id,
- 'name': p.name,
- 'displayName': p.display_name,
- 'ean13': p.ean13,
- 'imageMedium': p.image_medium,
- 'standardPrice': p.standard_price,
- 'variantCount': p.product_variant_count,
- 'quantity': 1,
- 'price': p.standard_price,
- 'minimumPrice': p.minimum_price,
- 'maximumPrice': p.maximum_price,
- 'variants': [{
- 'id': v.id,
- 'name': v.name,
- 'displayName': v.display_name,
- 'ean13': v.ean13,
- 'imageMedium': v.image_medium,
- 'standardPrice': v.standard_price,
- 'quantity': 1,
- 'price': v.standard_price,
- 'minimumPrice': p.minimum_price,
- 'maximumPrice': p.maximum_price
- } for v in p.product_variant_ids if v.active]
- } for p in product_obj.search(domain)
- ]
- def create_product(self, values):
- p = r.env['product.template'].create({
- 'name': values.get('name'),
- 'standard_price': float(values.get('price')),
- 'ean13': values.get('ean13')
- })
- return {
- 'id': p.id,
- 'name': p.name,
- 'displayName': p.display_name,
- 'ean13': p.ean13,
- 'imageMedium': p.image_medium,
- 'standardPrice': p.standard_price,
- 'variantCount': p.product_variant_count,
- 'price': p.list_price,
- 'minimumPrice': p.minimum_price,
- 'maximumPrice': p.maximum_price,
- 'variants': [{
- 'id': v.id,
- 'name': v.name,
- 'displayName': v.display_name,
- 'ean13': v.ean13,
- 'imageMedium': v.image_medium,
- 'standardPrice': p.standard_price,
- 'price': v.standard_price,
- 'minimumPrice': p.minimum_price,
- 'maximumPrice': p.maximum_price
- } for v in p.product_variant_ids if v.active]
- }
|