trytond-product_images/product.py

35 lines
917 B
Python

#The COPYRIGHT file at the top level of this repository contains the full
#copyright notices and license terms.
from trytond.model import fields
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval
__all__ = ['Attachment', 'Product']
__metaclass__ = PoolMeta
class Attachment:
__name__ = 'ir.attachment'
product_image = fields.Boolean('Product Image')
class Product:
__name__ = 'product.product'
images = fields.One2Many('ir.attachment', 'resource', 'Images', domain=[
('product_image', '=', True),
],
context={
'resource': Eval('id'),
}, depends=['id'])
@classmethod
def delete(cls, products):
pool = Pool()
Attachment = pool.get('ir.attachment')
attachments = [a for p in products for a in p.images]
Attachment.delete(attachments)
super(Product, cls).delete(products)