[FIX] website_sale: fix amount format
This commit fix wrong grouping when we format price via price_to_str. where '[3,0]' was interpreted as string and not array in intersperse. Thousand separator was duplicated ",,,320.00" e.g. This commit fix also product page where amount for variant was formatted js side before that RPC translation (website.ready() defered) was resolved. '/website/translations' is only called when user have rights to edit page. So a standard user didn't call it and l10n is not initialized. After an update, now we format the amount with the l10n value. To stay retro compatible, if l10n is not initialized (value = []) we use [] for grouping as 'fallback value'. To fix decimal precision you need to update the template product_price. To fix the grouping, you need to update the website.layout To fix the decimal separator, (and previous fix), you just need to pull the JS This commit is related to #1103, #11553, #14772, #14874, ... And fix the previous fix odoo/odoo@1f10ef8055 It should also fix (by side-effect) the translation JS for user without editor right. Already fixed in V9 - don't forward this commit...
This commit is contained in:
parent
a5dc060afb
commit
6b87284f3f
|
@ -56,7 +56,7 @@
|
|||
|
||||
<template id="layout" name="Main layout"><!DOCTYPE html>
|
||||
<html t-att-lang="lang and lang.replace('_', '-')"
|
||||
t-att-data-website-id="website.id if editable and website else None"
|
||||
t-att-data-website-id="website and website.id or None"
|
||||
t-att-data-editable="'1' if editable else None"
|
||||
t-att-data-translatable="'1' if translatable else None"
|
||||
t-att-data-view-xmlid="xmlid if editable else None"
|
||||
|
|
|
@ -166,9 +166,10 @@ $('.oe_website_sale').each(function () {
|
|||
var l10n = openerp._t.database.parameters;
|
||||
var negative = num[0] === '-';
|
||||
num = (negative ? num.slice(1) : num);
|
||||
|
||||
// retro-compatibilit: if no website_id and so l10n.grouping = []
|
||||
var grouping = l10n.grouping instanceof Array ? l10n.grouping : JSON.parse(l10n.grouping);
|
||||
return (negative ? '-' : '') + intersperse(
|
||||
num, l10n.grouping, l10n.thousands_sep);
|
||||
num, grouping, l10n.thousands_sep);
|
||||
}
|
||||
|
||||
function price_to_str(price) {
|
||||
|
@ -176,7 +177,7 @@ $('.oe_website_sale').each(function () {
|
|||
var precision = 2;
|
||||
if ($(".decimal_precision").length) {
|
||||
var dec_precision = $(".decimal_precision").first().data('precision');
|
||||
//MAth.log10 is not implemented in phantomJS
|
||||
//Math.log10 is not implemented in phantomJS
|
||||
dec_precision = Math.round(Math.log(1/parseFloat(dec_precision))/Math.log(10));
|
||||
if (!isNaN(dec_precision)) {
|
||||
precision = dec_precision;
|
||||
|
@ -184,8 +185,7 @@ $('.oe_website_sale').each(function () {
|
|||
}
|
||||
var formatted = _.str.sprintf('%.' + precision + 'f', price).split('.');
|
||||
formatted[0] = insert_thousand_seps(formatted[0]);
|
||||
var ret = formatted.join(l10n.decimal_point);
|
||||
return ret;
|
||||
return formatted.join(l10n.decimal_point);
|
||||
}
|
||||
|
||||
$(oe_website_sale).on('change', 'input.js_product_change', function (ev) {
|
||||
|
@ -213,8 +213,10 @@ $('.oe_website_sale').each(function () {
|
|||
var product_id = false;
|
||||
for (var k in variant_ids) {
|
||||
if (_.isEmpty(_.difference(variant_ids[k][1], values))) {
|
||||
$price.html(price_to_str(variant_ids[k][2]));
|
||||
$default_price.html(price_to_str(variant_ids[k][3]));
|
||||
openerp.website.ready(function() {
|
||||
$price.html(price_to_str(variant_ids[k][2]));
|
||||
$default_price.html(price_to_str(variant_ids[k][3]));
|
||||
});
|
||||
if (variant_ids[k][3]-variant_ids[k][2]>0.2) {
|
||||
$default_price.closest('.oe_website_sale').addClass("discount");
|
||||
$optional_price.closest('.oe_optional').show().css('text-decoration', 'line-through');
|
||||
|
|
|
@ -428,7 +428,8 @@
|
|||
|
||||
<template id="product_price">
|
||||
<div itemprop="offers" itemscope="itemscope" itemtype="http://schema.org/Offer" class="product_price mt16">
|
||||
<h4 class="oe_price_h4 css_editable_mode_hidden">
|
||||
<h4 class="oe_price_h4 css_editable_mode_hidden decimal_precision"
|
||||
t-att-data-precision="user_id.partner_id.property_product_pricelist.currency_id.rounding">
|
||||
<span class="text-danger oe_default_price" style="text-decoration: line-through; white-space: nowrap;"
|
||||
t-field="product.lst_price"
|
||||
t-field-options='{
|
||||
|
|
Loading…
Reference in New Issue