Debian Codegraph @

addons/website_event_sale/models/product.py

raw
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo import api, fields, models
4
5
6 # defined for access rules
7 class ProductProduct(models.Model):
8 _inherit = 'product.product'
9
10 event_ticket_ids = fields.One2many('event.event.ticket', 'product_id', string='Event Tickets')
11
12 def _can_return_content(self, field_name=None, access_token=None):
13 """ Override of `orm` to give public users access to the unpublished product image.
14
15 Give access to the public users to the unpublished product images if they are linked to an
16 event ticket.
17
18 :param field_name: The name of the field to check.
19 :param access_token: The access token.
20 :return: Whether to allow the access to the image.
21 :rtype: bool
22 """
23 if (
24 field_name in ["image_%s" % size for size in [1920, 1024, 512, 256, 128]]
25 and self.sudo().event_ticket_ids
26 ):
27 return True
28 return super()._can_return_content(field_name, access_token)
29
30 def _get_product_placeholder_filename(self):
31 if self.event_ticket_ids:
32 return 'website_event_sale/static/img/event_ticket_placeholder_thumbnail.png'
33 return super()._get_product_placeholder_filename()
34
35 class ProductTemplate(models.Model):
36 _inherit = 'product.template'
37
38 @api.model
39 def _get_product_types_allow_zero_price(self):
40 return super()._get_product_types_allow_zero_price() + ["event"]