Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Product not Avaliable in E-Shop

By
Luis Miguel Varón E
on 8/14/14, 2:31 PM 924 views

Hello

I'm developing a module that insert some columns to the product.attribute and product.attribute.value, but when i make a product with 2 variants itś get not available on the e-shop. This doesn happen without my module installed.

My code:

class product_colorisa_attribute(osv.osv):
    _inherit = "product.attribute.value"
    _columns = {
        'code' : fields.char('Codigo', size=3, required=True, help="Campo con capacidad de 3 caracteres, pero segun definicion de la codificacion de los productos ingresar unicamente 2 en caso de catalogar un Color, Sabor."),
        'scode' : fields.char('Sub Codigo', size=2, required=False, help="")
    }

class product_product(osv.osv):
    _inherit = 'product.product'
      
    def get_ref(self, cr, uid, ids,context=None):
        if isinstance(ids, (list, tuple)) and not len(ids):
            return []
        if isinstance(ids, (long, int)):
            ids = [ids]
        reads = self.browse(cr, uid, ids)
        res = []
        for records in reads:
            if records.categ_id.code:
                ref = records.categ_id.code + '' + records.linea_id.code + '' + records.marca_id.code
                for attribute in records.attribute_value_ids:
                    print attribute.code
                    if attribute.code:
                        ref = ref + '' + attribute.code
                if ref:
                    print ref
                    res.append((records['id'], ref))
        return res
        
    
    def _get_ref(self, cr, uid, ids, prop, unknow_none, context=None):
        res = self.get_ref(cr, uid, ids, context=context)
        return dict(res)

 _columns = {
        'ref' : fields.function(_get_ref, type='char', string='Internal Reference', store=True ),

}

Thanks for anything and forgive my english

0
Anton Chepurov
On 2/6/15, 7:01 PM

This happens when your product.template has an attribute with a single value, e.g. Color: blue.

Here's what you could do:

diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js
index d700ef2..a1cc3e0 100644
--- a/addons/website_sale/static/src/js/website_sale.js
+++ b/addons/website_sale/static/src/js/website_sale.js
@@ -103,6 +103,7 @@ $('.oe_website_sale').each(function () {
 
     $(oe_website_sale).on('change', 'input.js_variant_change, select.js_variant_change', function (ev) {
         var $ul = $(this).parents('ul.js_add_cart_variants:first');
+        var $section = $(this).parents('#product_detail');
         var $parent = $ul.closest('.js_product');
         var $product_id = $parent.find('input.product_id').first();
         var $price = $parent.find(".oe_price:first .oe_currency_value");
@@ -112,6 +113,9 @@ $('.oe_website_sale').each(function () {
         $parent.find('input.js_variant_change:checked, select.js_variant_change').each(function () {
             values.push(+$(this).val());
         });
+        $section.find('span.js_variant_static').each(function () {
+            values.push(parseInt($(this).attr('value')));
+        });
 
         $parent.find("label").removeClass("text-muted css_not_available");

And override one template in your XML file:

        <template id="product_attributes" inherit_id="website_sale.product_attributes" name="Product attributes">
            <xpath expr="//span[@t-field='variant_id.value_ids[0].name']" position="attributes">
                <attribute name="t-att-value">variant_id.value_ids[0].id</attribute>
                <attribute name="class">js_variant_static</attribute>
            </xpath>
        </template>

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 8/14/14, 2:31 PM
Seen: 924 times
Last updated: 3/16/15, 8:10 AM