[FIX] website_sale(_*): fix zero price sale

* product_configurator, comparison, stock(_wishlist)

Before this commit, the option "Prevent Sale of Zero Price Product"
would still allow some free products to be added to the cart (accessory,
optional and alternative products).

This commit makes sure no free product can be added to cart if this
option is activated.

Also, this option was conflicting with some other options and not well
handled in bridge modules. This commit improves the UX when this option
is activated.

task-2983615

closes odoo/odoo#143626

X-original-commit: 158f622f00bad7f3b24b81cfa715601f5ff7022a
Part-of: odoo/odoo#143504
Signed-off-by: Vallaeys Valentin (vava) <vava@odoo.com>
This commit is contained in:
Valentin Vallaeys (vava)
2023-11-25 06:43:36 +00:00
committed by vava-odoo
parent b578521324
commit 3735f6c961
8 changed files with 16 additions and 6 deletions
+4
View File
@@ -368,6 +368,10 @@ class SaleOrder(models.Model):
product.id not in product_ids
and product.filtered_domain(self.env['product.product']._check_company_domain(line.company_id))
and product._is_variant_possible(parent_combination=combination)
and (
not self.website_id.prevent_zero_price_sale
or product._get_contextual_price()
)
)
return random.sample(all_accessory_products, len(all_accessory_products))
@@ -170,6 +170,8 @@ class WebsiteSnippetFilter(models.Model):
excluded_products |= current_template.product_variant_ids
included_products = current_template.alternative_product_ids.product_variant_ids
products = included_products - excluded_products
if website.prevent_zero_price_sale:
products = products.filtered(lambda p: p._get_contextual_price())
if products:
domain = expression.AND([
domain,
+1 -1
View File
@@ -215,7 +215,7 @@
<t t-set="template_price_vals" t-value="get_product_prices(product)"/>
<div class="o_wsale_product_btn"/>
<div class="product_price" itemprop="offers" itemscope="itemscope" itemtype="http://schema.org/Offer">
<t t-if="'base_price' in template_price_vals and template_price_vals['base_price'] &gt; template_price_vals['price_reduce']">
<t t-if="'base_price' in template_price_vals and (template_price_vals['base_price'] &gt; template_price_vals['price_reduce']) and (template_price_vals['price_reduce'] or not website.prevent_zero_price_sale)">
<del t-attf-class="text-muted me-1 h6 mb-0" style="white-space: nowrap;">
<em class="small" t-esc="template_price_vals['base_price']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}" />
</del>
@@ -163,7 +163,7 @@
class="btn btn-primary btn_cta">
Contact Us
</a>
<a t-else="" role="button" class="btn btn-primary d-block a-submit" href="#">
<a t-else="" role="button" class="btn btn-primary a-submit" href="#">
<i class="fa fa-shopping-cart me-2"/>Add to Cart
</a>
</form>
@@ -16,7 +16,9 @@ class WebsiteSaleProductConfiguratorController(Controller):
product_template = product.product_tmpl_id
combination = request.env['product.template.attribute.value'].browse(variant_values)
has_optional_products = product.optional_product_ids.filtered(
lambda p: p._is_add_to_cart_possible(combination))
lambda p: p._is_add_to_cart_possible(combination)
and (not request.website.prevent_zero_price_sale or p._get_contextual_price())
)
already_configured = bool(combination)
if not force_dialog and not has_optional_products and (
@@ -133,7 +133,7 @@
<t t-set="combination_info" t-value="product._get_combination_info(combination, add_qty=add_qty)"/>
<t t-set="product_variant" t-value="product.env['product.product'].browse(combination_info['product_id'])"/>
<tr class="js_product">
<tr class="js_product" t-if="not combination_info.get('prevent_zero_price_sale', False)">
<td class="td-img">
<input type="hidden" class="product_template_id" t-att-value="product.id"/>
<input type="hidden" class="product_id" t-attf-name="optional-product-#{product.id}" t-att-value="product_variant.id"/>
@@ -2,7 +2,7 @@
<templates>
<t t-name="website_sale_stock.product_availability">
<t t-if="product_type == 'product'">
<t t-if="product_type == 'product' and !prevent_zero_price_sale">
<div t-if="free_qty lte 0 and !cart_qty" t-attf-class="availability_message_#{product_template} mb-1">
<div id="out_of_stock_message">
<t t-if='has_out_of_stock_message' t-out='out_of_stock_message'/>
@@ -2,7 +2,9 @@
<templates>
<t t-name="website_sale_stock_wishlist.product_availability" inherit_id="website_sale_stock.product_availability">
<div id="stock_wishlist_message" t-if="product_type == 'product' and !free_qty and !allow_out_of_stock_order" t-attf-class="availability_message_#{product_template} my-2 d-flex align-items-center flex-column flex-md-row">
<div id="stock_wishlist_message"
t-if="product_type == 'product' and !free_qty and !allow_out_of_stock_order and !prevent_zero_price_sale"
t-attf-class="availability_message_#{product_template} my-2 d-flex align-items-center flex-column flex-md-row">
<button
id="wsale_save_for_later_button"
t-if="!is_in_wishlist"