Skip to Content
Menu
This question has been flagged
2 Replies
6391 Views

Hello there,

We are on Odoo 8.

I knew that I had a problem with the currency format in some case on my webshop. This morning, I noticed something...

For all products without variant, the price is well formatted (with a comma) :




But as soon as a product has some variants, the price is NOT well formatted (with a dot instead of the comma...) :



Would you have some ideas to format all my prices correctly in all cases?

Thanks for your comments


EDIT #1

I suspect a problem in the file openerp/addons/website_sale/static/src/js/website_sale.js. I think the javascript is used when a product has some variants.

May be something in this code :

// change price when they are variants    
    $('form.js_add_cart_json label', oe_website_sale).on('mouseup touchend', function (ev) {       
        var $label = $(this);
        var $price = $label.parents("form:first").find(".oe_price .oe_currency_value");
        if (!$price.data("price")) {           
            $price.data("price", parseFloat($price.text()));
        }       
        var value = $price.data("price") + parseFloat($label.find(".badge span").text() || 0);
        var dec = value % 1;
        $price.html(value + (dec < 0.01 ? ".00" : (dec < 1 ? "0" : "") ));
    });


EDIT #2

Ţhe same thing arrives in the cart. When the customer change the quantity of an ordered item with the - or + buttons, the item price loses his comma for a dot :





Avatar
Discard
Author

Little up here. An idea?

Author Best Answer

With the help of Axel Mendoza, I managed it.

See this post : https://www.odoo.com/fr_FR/forum/aide-1/question/how-to-override-the-price-to-str-function-of-website-sale-js-111804

This way, I have overriden the price_to_str() function and $(oe_website_sale).find(".oe_cart input.js_quantity").on("change", function () in the original website_sale.js file.

Thanks a lot Axel!

In the function $(oe_website_sale).find(".oe_cart input.js_quantity").on("change", function () :

I replaced this line

$dom.find('span.oe_currency_value').last().text(res[product_id].toFixed(2));

By this line

$dom.find('span.oe_currency_value').last().text(res[product_id].toFixed(2).toString().replace(/\./g, ','));


My new price_to_str() function is :

function price_to_str(price) {
                price = Math.round(price * 100) / 100;
                var price = price.toString().replace(/\./g, ',');
                return price
 
            }

Avatar
Discard
Related Posts Replies Views Activity
0
Nov 24
111
3
Sep 24
4917
2
Jul 21
1288
0
Apr 18
2897
3
May 17
5379