diff --git a/website_hide_variants/__manifest__.py b/website_hide_variants/__manifest__.py index ea8a1c266..f8ac78ee6 100644 --- a/website_hide_variants/__manifest__.py +++ b/website_hide_variants/__manifest__.py @@ -35,7 +35,8 @@ 'website_sale', 'sale_management' ], - 'data': ['views/product_views.xml'], + 'data': ['views/product_views.xml', + ], 'assets': { 'web.assets_frontend': [ diff --git a/website_hide_variants/doc/RELEASE_NOTES.md b/website_hide_variants/doc/RELEASE_NOTES.md index 5fc572e3e..f3ac254ce 100644 --- a/website_hide_variants/doc/RELEASE_NOTES.md +++ b/website_hide_variants/doc/RELEASE_NOTES.md @@ -1,6 +1,6 @@ ## Module -#### 11.08.2023 +#### 17.10.2023 #### Version 16.0.1.0.0 #### ADD - Initial commit for Odoo 16 Hide Variants diff --git a/website_hide_variants/models/product.py b/website_hide_variants/models/product.py index b49ea8124..07a0d7a15 100644 --- a/website_hide_variants/models/product.py +++ b/website_hide_variants/models/product.py @@ -30,3 +30,9 @@ class ProductProduct(models.Model): help="Check right if you want to " "hide the variant in your " "website") + + def product_read(self, data): + if data.get('id', False): + prod_id = int(data.get('id')) + product = self.sudo().browse(prod_id).read(["website_hide_variants"]) + return product diff --git a/website_hide_variants/static/src/js/variants.js b/website_hide_variants/static/src/js/variants.js index f9a58a0b7..12e0e6eae 100644 --- a/website_hide_variants/static/src/js/variants.js +++ b/website_hide_variants/static/src/js/variants.js @@ -9,92 +9,96 @@ * @requires web.rpc * @augments sale.VariantMixin */ -odoo.define('website_hide_variants.VariantMixin', function (require) { -'use strict'; +odoo.define('website_hide_variants.VariantMixin', function(require) { + 'use strict'; - var VariantMixin =require('sale.VariantMixin') + var session = require('web.session'); + var VariantMixin = require('sale.VariantMixin') var core = require('web.core') var rpc = require('web.rpc') - VariantMixin._onChangeCombination = async function (ev, $parent, combination) { + var ajax = require('web.ajax'); + VariantMixin._onChangeCombination = async function(ev, $parent, combination) { var count = false - // Check if the selected combination has a valid product ID - if(combination.product_id){ + // Check if the selected combination has a valid product ID + var product = combination.product_id + if (combination.product_id) { + var data = { + 'id': combination.product_id + } await rpc.query({ model: 'product.product', - method: 'search_read', - args: [[['id','=',parseInt(combination.product_id)]]], - - }).then(function (res) { - // Check if the product is marked as "website_hide_variants" - - if(res[0].website_hide_variants){ - // Disable the combination and display an appropriate message to the user - - combination.is_combination_possible = false - - count = true - } + method: 'product_read', + args: [ + [], data + ], + }).then(function(res) { + // Check if the product is marked as "website_hide_variants" + if (res[0].website_hide_variants) { + // Disable the combination and display an appropriate message to the user + combination.is_combination_possible = false + count = true + } }); } - // Update the product variant information - - var $price = $parent.find(".oe_price:first .oe_currency_value"); - var $default_price = $parent.find(".oe_default_price:first .oe_currency_value"); - var $optional_price = $parent.find(".oe_optional:first .oe_currency_value"); - $price.text(this._priceToStr(combination.price)); - $default_price.text(this._priceToStr(combination.list_price)); - - var isCombinationPossible = true; - if (!_.isUndefined(combination.is_combination_possible)) { - isCombinationPossible = combination.is_combination_possible; - } - this._toggleDisable($parent, isCombinationPossible); + // Update the product variant information - if (combination.has_discounted_price) { - $default_price.closest('.oe_website_sale').addClass("discount"); - $optional_price.closest('.oe_optional').removeClass('d-none').css('text-decoration', 'line-through'); - $default_price.parent().removeClass('d-none'); - } else { - $default_price.closest('.oe_website_sale').removeClass("discount"); - $optional_price.closest('.oe_optional').addClass('d-none'); - $default_price.parent().addClass('d-none'); - } - - var rootComponentSelectors = [ - 'tr.js_product', - '.oe_website_sale', - '.o_product_configurator' - ]; + var $price = $parent.find(".oe_price:first .oe_currency_value"); + var $default_price = $parent.find(".oe_default_price:first .oe_currency_value"); + var $optional_price = $parent.find(".oe_optional:first .oe_currency_value"); + $price.text(this._priceToStr(combination.price)); + $default_price.text(this._priceToStr(combination.list_price)); + var isCombinationPossible = true; + if (!_.isUndefined(combination.is_combination_possible)) { + isCombinationPossible = combination.is_combination_possible; + } + this._toggleDisable($parent, isCombinationPossible); + + if (combination.has_discounted_price) { + $default_price.closest('.oe_website_sale').addClass("discount"); + $optional_price.closest('.oe_optional').removeClass('d-none').css('text-decoration', 'line-through'); + $default_price.parent().removeClass('d-none'); + } else { + $default_price.closest('.oe_website_sale').removeClass("discount"); + $optional_price.closest('.oe_optional').addClass('d-none'); + $default_price.parent().addClass('d-none'); + } - if (!combination.product_id || - !this.last_product_id || - combination.product_id !== this.last_product_id) { - this.last_product_id = combination.product_id; - this._updateProductImage( - $parent.closest(rootComponentSelectors.join(', ')), - combination.display_image, - combination.product_id, - combination.product_template_id, - combination.carousel, - isCombinationPossible - ); - } + var rootComponentSelectors = [ + 'tr.js_product', + '.oe_website_sale', + '.o_product_configurator' + ]; + + + if (!combination.product_id || + !this.last_product_id || + combination.product_id !== this.last_product_id) { + this.last_product_id = combination.product_id; + this._updateProductImage( + $parent.closest(rootComponentSelectors.join(', ')), + combination.display_image, + combination.product_id, + combination.product_template_id, + combination.carousel, + isCombinationPossible + ); + } - $parent.find('.product_id').first().val(combination.product_id || 0).trigger('change'); - $parent.find('.product_display_name').first().text(combination.display_name); - $parent.find('.js_raw_price').first().text(combination.price).trigger('change'); + $parent.find('.product_id').first().val(combination.product_id || 0).trigger('change'); + $parent.find('.product_display_name').first().text(combination.display_name); + $parent.find('.js_raw_price').first().text(combination.price).trigger('change'); - this.handleCustomValues($(ev.target)); + this.handleCustomValues($(ev.target)); // Display appropriate message to the user based on the availability of the selected variant - if(count){ - $('.css_not_available_msg')[0].innerText = "This Product is Out-of-stock." - - }else{ - $('.css_not_available_msg')[0].innerText = "This combination does not exist." - } + if (count) { + $('.css_not_available_msg')[0].innerText = "This Product is Out-of-stock." + } else { + $('.css_not_available_msg')[0].innerText = "This combination does not exist." } - }); + + } +}); \ No newline at end of file