1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
from odoo import models
class ProductProduct(models.Model):
_inherit = 'product.product'
def api_single_response(self, product_product):
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
product_pricelist_default_discount_id = self.env['ir.config_parameter'].get_param('product.pricelist.default_discount_id')
product_pricelist_default_discount_id = int(product_pricelist_default_discount_id)
product_template = product_product.product_tmpl_id
data = {
'id': product_product.id,
'parent': {
'id': product_template.id,
'name': product_template.name,
'image': base_url + 'api/image/product.template/image_256/' + str(product_template.id) if product_template.image_256 else '',
},
'code': product_product.default_code or '',
'name': product_product.display_name,
'price': self.env['product.pricelist'].compute_price(product_pricelist_default_discount_id, product_product.id),
'stock': product_product.qty_stock_vendor,
'weight': product_product.weight,
'attributes': [x.name for x in product_product.product_template_attribute_value_ids],
'manufacture' : self.api_manufacture(product_product)
}
return data
def api_manufacture(self, product_template):
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
if product_template.x_manufacture:
manufacture = product_template.x_manufacture
return {
'id': manufacture.id,
'name': manufacture.x_name,
'image_promotion_1': base_url + 'api/image/x_manufactures/image_promotion_1/' + str(manufacture.id) if manufacture.image_promotion_1 else '',
'image_promotion_2': base_url + 'api/image/x_manufactures/image_promotion_2/' + str(manufacture.id) if manufacture.image_promotion_2 else '',
}
return {}
|