1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- # -*- coding: utf-8 -*-
- from openerp.http import request
- _MODEL = 'product.template'
- '''
- '''
- def get_products(image_type='small'):
- domain = [
- ('sale_ok', '=', True),
- ('list_price', '>', 0),
- ('active', '=', True)
- ]
- return [
- {
- 'id': product.id,
- 'name': product.display_name,
- 'ean13': product.ean13,
- 'defaultCode': product.default_code,
- 'image': product.image_small if image_type == 'small' else product.image_medium,
- 'listPrice': product.list_price,
- 'variantCount': product.product_variant_count,
- 'quantity': 1,
- 'price': product.list_price,
- 'minimumPrice': product.minimum_price,
- 'maximumPrice': product.maximum_price,
- 'discount': 0,
- 'variants': [{
- 'id': variant.id,
- 'name': variant.display_name,
- 'ean13': variant.ean13,
- 'defaultCode': product.default_code,
- 'image': variant.image_small if image_type == 'small' else variant.image_medium,
- 'listPrice': variant.list_price,
- 'quantity': 1,
- 'price': variant.list_price,
- 'minimumPrice': product.minimum_price,
- 'maximumPrice': product.maximum_price,
- 'discount': 0,
- } for variant in product.product_variant_ids if variant.active]
- } for product in request.env[_MODEL].search(domain)
- ]
- '''
- Create product and return
- '''
- def create_product(**kw):
- product = request.env[_MODEL].create({
- 'name': kw.get('name'),
- 'listPrice': float(kw.get('price')),
- 'ean13': kw.get('ean13')
- })
- return {
- 'id': product.id,
- 'name': product.display_name,
- 'ean13': product.ean13,
- 'image': product.image_small,
- 'listPrice': product.list_price,
- 'variantCount': product.product_variant_count,
- 'quantity': 1,
- 'price': product.list_price,
- 'discount': 0,
- 'variants': [{
- 'id': variant.id,
- 'name': variant.display_name,
- 'ean13': variant.ean13,
- 'image': variant.image_small,
- 'listPrice': variant.list_price,
- 'quantity': 1,
- 'price': variant.list_price,
- 'discount': 0,
- } for variant in product.product_variant_ids if variant.active]
- }
|