19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:32:12 +01:00
parent 79f83631d5
commit 73afc09215
6267 changed files with 1534193 additions and 1130106 deletions

View file

@ -3,5 +3,5 @@
from . import product_product
from . import product_template
from . import sale_order
from . import sale_order_line
from . import slide_channel
from . import website

View file

@ -4,16 +4,25 @@
from odoo import _, fields, models
class Product(models.Model):
class ProductProduct(models.Model):
_inherit = "product.product"
channel_ids = fields.One2many('slide.channel', 'product_id', string='Courses')
def _is_add_to_cart_allowed(self):
"""Override to allow published course related products to the cart regardless of product's rules."""
self.ensure_one()
res = super()._is_add_to_cart_allowed()
return res or bool(self.env['slide.channel'].sudo().search_count([
('product_id', '=', self.id),
('website_published', '=', True),
], limit=1))
def get_product_multiline_description_sale(self):
payment_channels = self.channel_ids.filtered(lambda course: course.enroll == 'payment')
if not payment_channels:
return super(Product, self).get_product_multiline_description_sale()
return super().get_product_multiline_description_sale()
new_line = '' if len(payment_channels) == 1 else '\n'
return _('Access to:%s%s', new_line, '\n'.join(payment_channels.mapped('name')))
return _('Access to: %(new_line)s%(channel_list)s', new_line=new_line, channel_list='\n'.join(payment_channels.mapped('name')))

View file

@ -1,21 +1,24 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
from odoo import _, api, fields, models
class ProductTemplate(models.Model):
_inherit = 'product.template'
detailed_type = fields.Selection(selection_add=[
('course', 'Course'),
], ondelete={'course': 'set service'})
service_tracking = fields.Selection(selection_add=[
('course', 'Course Access'),
], ondelete={'course': 'set default'})
def _detailed_type_mapping(self):
type_mapping = super(ProductTemplate, self)._detailed_type_mapping()
type_mapping['course'] = 'service'
return type_mapping
def _prepare_service_tracking_tooltip(self):
if self.service_tracking == 'course':
return _("Grant access to the eLearning course linked to this product.")
return super()._prepare_service_tracking_tooltip()
@api.model
def _get_product_types_allow_zero_price(self):
return super()._get_product_types_allow_zero_price() + ["course"]
def _service_tracking_blacklist(self):
return super()._service_tracking_blacklist() + ['course']

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, _
from odoo import _, models
class SaleOrder(models.Model):
@ -33,9 +32,9 @@ class SaleOrder(models.Model):
return result
def _verify_updated_quantity(self, order_line, product_id, new_qty, **kwargs):
def _verify_updated_quantity(self, order_line, product_id, new_qty, uom_id, **kwargs):
"""Forbid quantity updates on courses lines."""
product = self.env['product.product'].browse(product_id)
if product.detailed_type == 'course' and new_qty > 1:
if product.service_tracking == 'course' and new_qty > 1:
return 1, _('You can only add a course once in your cart.')
return super()._verify_updated_quantity(order_line, product_id, new_qty, **kwargs)
return super()._verify_updated_quantity(order_line, product_id, new_qty, uom_id, **kwargs)

View file

@ -0,0 +1,11 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
def _is_reorder_allowed(self):
# Don't allow courses in reorder
return self.service_tracking != 'course' and super()._is_reorder_allowed()

View file

@ -4,27 +4,28 @@
from odoo import api, fields, models
class Channel(models.Model):
class SlideChannel(models.Model):
_inherit = 'slide.channel'
def _get_default_product_id(self):
product_courses = self.env['product.product'].search(
[('detailed_type', '=', 'course')], limit=2)
[('service_tracking', '=', 'course')], limit=2)
return product_courses.id if len(product_courses) == 1 else False
enroll = fields.Selection(selection_add=[
('payment', 'On payment')
], ondelete={'payment': lambda recs: recs.write({'enroll': 'invite'})})
product_id = fields.Many2one('product.product', 'Product', domain=[('detailed_type', '=', 'course')],
default=_get_default_product_id)
product_id = fields.Many2one('product.product', 'Product', domain=[('service_tracking', '=', 'course')],
index='btree_not_null', default=_get_default_product_id)
product_sale_revenues = fields.Monetary(
string='Total revenues', compute='_compute_product_sale_revenues',
groups="sales_team.group_sale_salesman")
currency_id = fields.Many2one(related='product_id.currency_id')
_sql_constraints = [
('product_id_check', "CHECK( enroll!='payment' OR product_id IS NOT NULL )", "Product is required for on payment channels.")
]
_product_id_check = models.Constraint(
"CHECK( enroll!='payment' OR product_id IS NOT NULL )",
'Product is required for on payment channels.',
)
@api.depends('product_id')
def _compute_product_sale_revenues(self):
@ -32,21 +33,21 @@ class Channel(models.Model):
('state', 'in', self.env['sale.report']._get_done_states()),
('product_id', 'in', self.product_id.ids),
]
rg_data = dict(
(item['product_id'][0], item['price_total'])
for item in self.env['sale.report']._read_group(domain, ['product_id', 'price_total'], ['product_id'])
)
rg_data = {
product.id: price_total
for product, price_total in self.env['sale.report']._read_group(domain, ['product_id'], ['price_total:sum'])
}
for channel in self:
channel.product_sale_revenues = rg_data.get(channel.product_id.id, 0)
@api.model_create_multi
def create(self, vals_list):
channels = super(Channel, self).create(vals_list)
channels = super().create(vals_list)
channels.filtered(lambda channel: channel.enroll == 'payment')._synchronize_product_publish()
return channels
def write(self, vals):
res = super(Channel, self).write(vals)
res = super().write(vals)
if 'is_published' in vals:
self.filtered(lambda channel: channel.enroll == 'payment')._synchronize_product_publish()
return res
@ -61,12 +62,11 @@ class Channel(models.Model):
self.filtered(lambda channel: channel.is_published and not channel.product_id.is_published).sudo().product_id.write({'is_published': True})
unpublished_channel_products = self.filtered(lambda channel: not channel.is_published).product_id
group_data = self.read_group(
group_data = self._read_group(
[('is_published', '=', True), ('product_id', 'in', unpublished_channel_products.ids)],
['product_id'],
['product_id'],
)
used_product_ids = [product['product_id'][0] for product in group_data if product['product_id_count'] > 0]
used_product_ids = {product.id for [product] in group_data}
product_to_unpublish = unpublished_channel_products.filtered(lambda product: product.id not in used_product_ids)
if product_to_unpublish:
product_to_unpublish.sudo().write({'is_published': False})
@ -75,18 +75,3 @@ class Channel(models.Model):
action = self.env["ir.actions.actions"]._for_xml_id("website_sale_slides.sale_report_action_slides")
action['domain'] = [('product_id', 'in', self.product_id.ids)]
return action
def _filter_add_members(self, target_partners, **member_values):
""" Overridden to add 'payment' channels to the filtered channels. People
that can write on payment-based channels can add members. """
result = super(Channel, self)._filter_add_members(target_partners, **member_values)
on_payment = self.filtered(lambda channel: channel.enroll == 'payment')
if on_payment:
try:
on_payment.check_access_rights('write')
on_payment.check_access_rule('write')
except:
pass
else:
result |= on_payment
return result

View file

@ -1,15 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
from odoo.osv import expression
class Website(models.Model):
_inherit = 'website'
def sale_product_domain(self):
return expression.AND([
super(Website, self).sale_product_domain(),
[('detailed_type', '!=', 'course')],
])