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
|
from odoo import fields, models
class PromotionProduct(models.Model):
_name = "promotion.product"
_rec_name = "product_id"
product_id = fields.Many2one(comodel_name="product.product", string="Product variant")
qty = fields.Integer(string="Quantity")
program_line_id = fields.Many2one(comodel_name="promotion.program.line", string="Program line")
def formats(self, purchase_qty=1):
ir_attachment = self.env['ir.attachment']
result = []
for rec in self:
weight = rec.product_id.weight or 0
result.append({
'id': rec.product_id.id,
'parent': {
'id': rec.product_id.product_tmpl_id.id,
'name': rec.product_id.product_tmpl_id.name,
},
'image': ir_attachment.api_image('product.template', 'image_256', rec.product_id.product_tmpl_id.id),
'display_name': rec.product_id.display_name,
'name': rec.product_id.name,
'code': rec.product_id.code,
'price': rec.product_id.calculate_website_price(),
'qty': rec.qty * purchase_qty,
'weight': weight,
'package_weight': weight * rec.qty
})
return result
|