[FIX] (website_)sale: handle archived variants - product configurator

Targets commit d3530eb07e

Purpose
=======
- When a product variant is archived by the user, it should not be selectable in
  the product configurator for both webshop and sale order
- Fixed a typo in the name_get method of ProductTemplateAttributeValue

closes odoo/odoo#27385
This commit is contained in:
Aurélien Warnon
2018-10-10 13:36:54 +00:00
parent a3a49141c9
commit c76734655e
3 changed files with 34 additions and 2 deletions
+1 -1
View File
@@ -187,7 +187,7 @@ class ProductTemplateAttributeValue(models.Model):
@api.multi
def name_get(self):
if not self._context.get('show_attribute', True): # TDE FIXME: not used
return super(ProductAttributeValue, self).name_get()
return super(ProductTemplateAttributeValue, self).name_get()
return [(value.id, "%s: %s" % (value.attribute_id.name, value.name)) for value in self]
@@ -125,9 +125,26 @@ class ProductConfiguratorController(http.Controller):
lambda filter_line: filter_line.product_tmpl_id == product
) for value_id in filter_line.value_ids.ids]
# Query all archived products for this template
archived_combinations = request.env['product.product'].search(
[('product_tmpl_id', '=', product.id), ('active', '=', False)])
if archived_combinations:
# Old archived variants could have a different set of attributes and are not relevant here
# -> filter them out
attribute_ids = product_attribute_values.mapped('attribute_id')
archived_combinations = archived_combinations.filtered(
lambda product: all(
attribute_id in product.mapped('product_template_attribute_value_ids.attribute_id')
for attribute_id in attribute_ids
)
)
return {
'exclusions': mapped_exclusions,
'parent_exclusions': parent_exclusions
'parent_exclusions': parent_exclusions,
'archived_combinations': [archived_combination.product_template_attribute_value_ids.ids
for archived_combination in archived_combinations]
}
def _get_product_context(self, pricelist=None, **kw):
@@ -327,6 +327,9 @@ var ProductConfiguratorMixin = {
* the exclusions coming from the parent product (meaning that this product
* is an option of the parent product)
*
* It will also check that the selected combination does not exactly
* match a manually archived product
*
* @private
* @param {$.Element} $parent the parent container to apply exclusions
* @param {Array} combination the selected combination of product attribute values
@@ -365,6 +368,18 @@ var ProductConfiguratorMixin = {
});
}
if (combinationData.archived_combinations){
_.each(combinationData.archived_combinations, function (archived_combination){
if (disable) {
return;
}
disable = _.every(archived_combination, function (attribute_value){
return combination.indexOf(attribute_value) > -1;
});
});
}
$parent.toggleClass('css_not_available', disable);
$parent.find("#add_to_cart").toggleClass('disabled', disable);
$parent