Debian Codegraph @

addons/website_sale_loyalty/models/product_product.py

raw symbols SCIP
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo import models
4
5
6 class ProductProduct(models.Model):
7 _inherit = 'product.product'
8
9 def _can_return_content(self, field_name=None, access_token=None):
10 """ Override of `orm` to give public users access to the unpublished product image.
11
12 Give access to the public users to the unpublished product images if they are linked to a
13 reward.
14
15 :param field_name: The name of the field to check.
16 :param access_token: The access token.
17 :return: Whether to allow the access to the image.
18 :rtype: bool
19 """
20 if (
21 field_name in ["image_%s" % size for size in [1920, 1024, 512, 256, 128]]
22 and self.env['loyalty.reward'].sudo().search_count([
23 ('discount_line_product_id', '=', self.id),
24 ], limit=1)
25 ):
26 return True
27 return super()._can_return_content(field_name, access_token)
28
29 def _get_product_placeholder_filename(self):
30 """ Override of `product` to set a default image for reward products. """
31 # In sudo mode to allow eCommerce customers to see the placeholder
32 if self.env['loyalty.reward'].sudo().search_count([
33 ('discount_line_product_id', '=', self.id),
34 ], limit=1):
35 if self.env['loyalty.reward'].sudo().search_count([
36 ('program_type', '=', 'gift_card'),
37 ('discount_line_product_id', '=', self.id),
38 ], limit=1):
39 return 'loyalty/static/img/gift_card.png'
40 return 'loyalty/static/img/discount_placeholder_thumbnail.png'
41 return super()._get_product_placeholder_filename()