Debian Codegraph @

addons/website_sale_collect/models/product_template.py

raw symbols SCIP
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo import models
4 from odoo.http import request
5
6 from odoo.addons.website_sale_collect import utils
7
8
9 class ProductTemplate(models.Model):
10 _inherit = 'product.template'
11
12 def _get_additionnal_combination_info(self, product_or_template, quantity, uom, date, website):
13 """ Override of `website_sale` to add information on whether Click & Collect is enabled and
14 on the stock of the product. """
15 res = super()._get_additionnal_combination_info(
16 product_or_template, quantity, uom, date, website
17 )
18 if (
19 bool(website.sudo().in_store_dm_id) # Click & Collect is enabled.
20 and product_or_template.is_product_variant
21 and product_or_template.is_storable
22 ):
23 # Enable the Click & Collect Availability widget.
24 res['show_click_and_collect_availability'] = True
25
26 # Prepare the delivery stock data.
27 available_delivery_methods_sudo = self.env['delivery.carrier'].sudo().search([
28 '|', ('website_id', '=', website.id), ('website_id', '=', False),
29 ('website_published', '=', True),
30 ('delivery_type', '!=', 'in_store'),
31 ])
32 if available_delivery_methods_sudo:
33 res['delivery_stock_data'] = utils.format_product_stock_values(
34 product_or_template.sudo(), wh_id=website.warehouse_id.id
35 )
36 else:
37 res['delivery_stock_data'] = {}
38
39 # Prepare the in-store stock data.
40 order_sudo = request.cart
41 if (
42 order_sudo
43 and order_sudo.carrier_id.delivery_type == 'in_store'
44 and order_sudo.pickup_location_data
45 ): # Get stock values for the product variant in the selected store.
46 res['in_store_stock_data'] = utils.format_product_stock_values(
47 product_or_template.sudo(), wh_id=order_sudo.pickup_location_data['id']
48 )
49 else:
50 res['in_store_stock_data'] = utils.format_product_stock_values(
51 product_or_template.sudo(),
52 free_qty=website.sudo()._get_max_in_store_product_available_qty(
53 product_or_template.sudo()
54 )
55 )
56 return res