forked from lukebranch/website_multi_image
-
Notifications
You must be signed in to change notification settings - Fork 34
/
product_images.py
48 lines (37 loc) · 1.43 KB
/
product_images.py
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
40
41
42
43
44
45
46
47
48
from openerp import models, fields, api
class product_image(models.Model):
_name = 'product.image'
_order = 'sequence, id DESC'
name = fields.Char('Name')
description = fields.Text('Description')
sequence = fields.Integer('Sequence')
image_alt = fields.Text('Image Label')
image = fields.Binary('Image')
image_small = fields.Binary('Small Image')
product_tmpl_id = fields.Many2one('product.template', 'Product', select=True)
from_main_image = fields.Boolean('From Main Image', default=False)
class product_product(models.Model):
_inherit = 'product.product'
images = fields.One2many('product.image', related='product_tmpl_id.images',
string='Images', store=False)
class product_template(models.Model):
_inherit = 'product.template'
images = fields.One2many('product.image', 'product_tmpl_id',
string='Images')
@api.one
def action_copy_image_to_images(self):
if not self.image:
return
image = None
for r in self.images:
if r.from_main_image:
image = r
break
if image:
image.image = self.image
else:
vals = {'image': self.image,
'name': self.name,
'product_tmpl_id': self.id,
'from_main_image': True, }
self.env['product.image'].create(vals)