[FIX] website_sale: fix amount format display
Before this commit, amount updated from ajax request don't respect currency format. Eg: 1.200,000 => 1200.00 Now we use the grouping/thousand separator/decimal separator from l10n, and if class decimal_precision is defined in dom, we use it. (format=0.001) This commits closes: #11553 This commits is related to #1103
This commit is contained in:
parent
8d724924f7
commit
1f10ef8055
|
@ -174,7 +174,7 @@
|
|||
Capacity: 16GB
|
||||
Connectivity: Wifi
|
||||
Beautiful 7.9-inch display
|
||||
Over 375,000 apps3
|
||||
Over 375,000 apps
|
||||
Ultrafast wireless
|
||||
iOS7
|
||||
</field>
|
||||
|
|
|
@ -73,13 +73,13 @@ $('.oe_website_sale').each(function () {
|
|||
'line_id': line_id})
|
||||
.then(function (res) {
|
||||
//basic case
|
||||
$dom.find('span.oe_currency_value').last().text(res[product_id].toFixed(2));
|
||||
$dom.find('span.oe_currency_value').last().text(price_to_str(res[product_id]));
|
||||
$dom.find('.text-danger').toggle(res[product_id]<default_price && (default_price-res[product_id] > default_price/100));
|
||||
//optional case
|
||||
$dom_optional.each(function(){
|
||||
var id = $(this).find('span[data-product-id]').data('product-id');
|
||||
var price = parseFloat($(this).find(".text-danger > span.oe_currency_value").text());
|
||||
$(this).find("span.oe_currency_value").last().text(res[id].toFixed(2));
|
||||
$(this).find("span.oe_currency_value").last().text(price_to_str(res[id]));
|
||||
$(this).find('.text-danger').toggle(res[id]<price && (price-res[id]>price/100));
|
||||
});
|
||||
openerp.jsonRpc("/shop/cart/update_json", 'call', {
|
||||
|
@ -145,10 +145,47 @@ $('.oe_website_sale').each(function () {
|
|||
$('.css_attribute_color:has(input:checked)').addClass("active");
|
||||
});
|
||||
|
||||
// Copy from core.js that is not available in front end.
|
||||
function intersperse(str, indices, separator) {
|
||||
separator = separator || '';
|
||||
var result = [], last = str.length;
|
||||
|
||||
for(var i=0; i<indices.length; ++i) {
|
||||
var section = indices[i];
|
||||
if (section === -1 || last <= 0) { break; }
|
||||
else if(section === 0 && i === 0) { break; }
|
||||
else if (section === 0) { section = indices[--i]; }
|
||||
result.push(str.substring(last-section, last));
|
||||
last -= section;
|
||||
}
|
||||
var s = str.substring(0, last);
|
||||
if (s) { result.push(s); }
|
||||
return result.reverse().join(separator);
|
||||
}
|
||||
function insert_thousand_seps(num) {
|
||||
var l10n = openerp._t.database.parameters;
|
||||
var negative = num[0] === '-';
|
||||
num = (negative ? num.slice(1) : num);
|
||||
|
||||
return (negative ? '-' : '') + intersperse(
|
||||
num, l10n.grouping, l10n.thousands_sep);
|
||||
}
|
||||
|
||||
function price_to_str(price) {
|
||||
price = Math.round(price * 100) / 100;
|
||||
var dec = Math.round((price % 1) * 100);
|
||||
return price + (dec ? '' : '.0') + (dec%10 ? '' : '0');
|
||||
var l10n = openerp._t.database.parameters;
|
||||
var precision = 2;
|
||||
if ($(".decimal_precision").length) {
|
||||
var dec_precision = $(".decimal_precision").first().data('precision');
|
||||
//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;
|
||||
}
|
||||
}
|
||||
var formatted = _.str.sprintf('%.' + precision + 'f', price).split('.');
|
||||
formatted[0] = insert_thousand_seps(formatted[0]);
|
||||
var ret = formatted.join(l10n.decimal_point);
|
||||
return ret;
|
||||
}
|
||||
|
||||
$(oe_website_sale).on('change', 'input.js_product_change', function (ev) {
|
||||
|
|
|
@ -97,7 +97,7 @@
|
|||
}'>
|
||||
</span>
|
||||
<span itemprop="price" style="display:none;" t-esc="product.price"/>
|
||||
<span itemprop="priceCurrency" style="display:none;" t-esc="user_id.partner_id.property_product_pricelist.currency_id.name"/>
|
||||
<span itemprop="priceCurrency" style="display:none;" t-esc="user_id.partner_id.property_product_pricelist.currency_id.name" class='decimal_precision' t-att-data-precision="website.pricelist_id.currency_id.rounding"/>
|
||||
</b>
|
||||
</div>
|
||||
</section>
|
||||
|
@ -443,7 +443,7 @@
|
|||
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
|
||||
}'/>
|
||||
<span itemprop="price" style="display:none;" t-esc="product.price"/>
|
||||
<span itemprop="priceCurrency" style="display:none;" t-esc="user_id.partner_id.property_product_pricelist.currency_id.name"/>
|
||||
<span itemprop="priceCurrency" style="display:none;" t-esc="user_id.partner_id.property_product_pricelist.currency_id.name" class='decimal_precision' t-att-data-precision="website.pricelist_id.currency_id.rounding"/>
|
||||
</h4>
|
||||
<h4 class="css_editable_mode_display" style="display: none;">
|
||||
<span t-field="product.lst_price"
|
||||
|
@ -663,7 +663,7 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" width="100">Product</th>
|
||||
<th width="100">Price</th>
|
||||
<th width="100" class='decimal_precision' t-att-data-precision="website_sale_order.pricelist_id.currency_id.rounding">Price</th>
|
||||
<th width="120">Quantity</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
Loading…
Reference in New Issue