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
|
from odoo import models
class ProductProduct(models.Model):
_inherit = 'product.product'
def api_single_response(self, product_product):
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': self.env['ir.attachment'].api_image('product.template', 'image_256', product_template.id),
},
'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):
if product_template.x_manufacture:
manufacture = product_template.x_manufacture
return {
'id': manufacture.id,
'name': manufacture.x_name,
'image_promotion_1': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_1', manufacture.id),
'image_promotion_2': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_2', manufacture.id),
}
return {}
|