Debian Codegraph @

addons/website_sale_slides/models/product_product.py

raw
1 # -*- coding: utf-8 -*-
2 # Part of Odoo. See LICENSE file for full copyright and licensing details.
3
4 from odoo import _, fields, models
5
6
7 class ProductProduct(models.Model):
8 _inherit = "product.product"
9
10 channel_ids = fields.One2many('slide.channel', 'product_id', string='Courses')
11
12 def _is_add_to_cart_allowed(self):
13 """Override to allow published course related products to the cart regardless of product's rules."""
14 self.ensure_one()
15 res = super()._is_add_to_cart_allowed()
16 return res or bool(self.env['slide.channel'].sudo().search_count([
17 ('product_id', '=', self.id),
18 ('website_published', '=', True),
19 ], limit=1))
20
21 def get_product_multiline_description_sale(self):
22 payment_channels = self.channel_ids.filtered(lambda course: course.enroll == 'payment')
23
24 if not payment_channels:
25 return super().get_product_multiline_description_sale()
26
27 new_line = '' if len(payment_channels) == 1 else '\n'
28 return _('Access to: %(new_line)s%(channel_list)s', new_line=new_line, channel_list='\n'.join(payment_channels.mapped('name')))