diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website_sale_slides/models/sale_order.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website_sale_slides/models/sale_order.py')
| -rw-r--r-- | addons/website_sale_slides/models/sale_order.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/addons/website_sale_slides/models/sale_order.py b/addons/website_sale_slides/models/sale_order.py new file mode 100644 index 00000000..266e2576 --- /dev/null +++ b/addons/website_sale_slides/models/sale_order.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, api + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def _action_confirm(self): + """ If the product of an order line is a 'course', we add the client of the sale_order + as a member of the channel(s) on which this product is configured (see slide.channel.product_id). """ + result = super(SaleOrder, self)._action_confirm() + + so_lines = self.env['sale.order.line'].search( + [('order_id', 'in', self.ids)] + ) + products = so_lines.mapped('product_id') + related_channels = self.env['slide.channel'].search( + [('product_id', 'in', products.ids)] + ) + channel_products = related_channels.mapped('product_id') + + channels_per_so = {sale_order: self.env['slide.channel'] for sale_order in self} + for so_line in so_lines: + if so_line.product_id in channel_products: + for related_channel in related_channels: + if related_channel.product_id == so_line.product_id: + channels_per_so[so_line.order_id] = channels_per_so[so_line.order_id] | related_channel + + for sale_order, channels in channels_per_so.items(): + channels._action_add_members(sale_order.partner_id) + + return result |
