[FIX] website_sale: display in currency of the user

This commit is contained in:
Christophe Matthieu 2014-06-18 17:43:14 +02:00 committed by Christophe Simonis
parent 7295a07c4a
commit a6185caa18
3 changed files with 62 additions and 45 deletions

View File

@ -170,7 +170,7 @@ class website(orm.Model):
_columns = {
'pricelist_id': fields.related('user_id','partner_id','property_product_pricelist',
type='many2one', relation='product.pricelist', string='Default pricelist')
type='many2one', relation='product.pricelist', string='Default pricelist'),
}
def sale_product_domain(self, cr, uid, ids, context=None):
@ -264,4 +264,9 @@ class website(orm.Model):
'sale_order_code_pricelist_id': False,
})
def compute_curency(self, cr, uid, ids, from_amount, from_currency_id=None, context=None):
from_currency_id = from_currency_id or self.browse(cr, uid, ids[0]).pricelist_id.currency_id.id
to_currency_id = self.pool.get("res.users").browse(cr, uid, uid).partner_id.property_product_pricelist.currency_id.id
return self.pool['res.currency'].compute(cr, uid, from_currency_id, to_currency_id, from_amount, context=context)
# vim:et:

View File

@ -73,13 +73,14 @@
<h5><strong><a itemprop="name" t-att-href="keep('/shop/product/%s' % slug(product), page=(pager['page']['num'] if pager['page']['num']>1 else None))" t-field="product.name"/></strong></h5>
<div itemprop="offers" itemscope="itemscope" itemtype="http://schema.org/Offer" class="product_price" t-if="product.product_variant_ids">
<b>
<t t-if="(product.lst_price - product.price) &gt; 0.1">
<del class="text-danger" t-field="product.lst_price" t-field-options='{
<t t-if="(website.compute_curency(product.lst_price) - product.price) &gt; 0.1">
<del class="text-danger" style="white-space: nowrap;" t-field="product.lst_price" t-field-options='{
"widget": "monetary",
"display_currency": "pricelist.currency_id"
"from_currency": "res_company.partner_id.property_product_pricelist.currency_id",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/>&amp;nbsp;
</t>
<span t-field="product.price" t-field-options='{
<span t-field="product.price" style="white-space: nowrap;" t-field-options='{
"widget": "monetary",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'>
@ -430,14 +431,15 @@
</td>
<td>
<t t-if="(product.lst_price != product.price) &gt; 0.1">
<span class="text-danger" style="text-decoration: line-through;"
<span class="text-danger" style="text-decoration: line-through; white-space: nowrap;"
t-field="product.lst_price"
t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
"widget": "monetary",
"from_currency": "res_company.partner_id.property_product_pricelist.currency_id",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/><br/>
</t>
<span class="oe_price"
<span class="oe_price" style="white-space: nowrap;"
t-field="product.price"
t-field-options='{
"widget": "monetary",
@ -479,15 +481,16 @@
</div>
</td>
<td>
<t t-if="(product.lst_price - product.price) &gt; 0.1">
<span class="text-danger" style="text-decoration: line-through;"
<t t-if="(website.compute_curency(product.lst_price) - product.price) &gt; 0.1">
<span class="text-danger" style="text-decoration: line-through; white-space: nowrap;"
t-field="product.lst_price"
t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
"widget": "monetary",
"from_currency": "res_company.partner_id.property_product_pricelist.currency_id",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/><br/>
</t>
<span class="oe_price"
<span class="oe_price" style="white-space: nowrap;"
t-field="product.price"
t-field-options='{
"widget": "monetary",
@ -566,15 +569,16 @@
<template id="product_price">
<div itemprop="offers" itemscope="itemscope" itemtype="http://schema.org/Offer" class="product_price mt16">
<h4 class="oe_price_h4">
<t t-if="(product.lst_price - product.price) &gt; 0.1">
<span class="text-danger" style="text-decoration: line-through;"
<t t-if="(website.compute_curency(product.lst_price) - product.price) &gt; 0.1">
<span class="text-danger" style="text-decoration: line-through; white-space: nowrap;"
t-field="product.lst_price"
t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
"widget": "monetary",
"from_currency": "res_company.partner_id.property_product_pricelist.currency_id",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/><br/>
</t>
<b class="oe_price"
<b class="oe_price" style="white-space: nowrap;"
t-field="product.price"
t-field-options='{
"widget": "monetary",
@ -594,7 +598,7 @@
<input type="radio" name="product_id" t-att-value="variant_id.id"/>
<span t-esc="variant_id.name_get()[0][1]"/>
<span class="badge" t-if="variant_id.price_extra">
<t t-esc="variant_id.price_extra > 0 and '+' or ''"/><span t-field="variant_id.price_extra" t-field-options='{ "widget": "monetary", "display_currency": "pricelist.currency_id" }'/>
<t t-esc="variant_id.price_extra > 0 and '+' or ''"/><span t-field="variant_id.price_extra" style="white-space: nowrap;" t-field-options='{ "widget": "monetary", "display_currency": "pricelist.currency_id" }'/>
</span>
</label>
</t>
@ -614,7 +618,7 @@
<option t-att-value="value_id.id">
<span t-field="value_id.name"/>
<span t-if="value_id.price_extra">
<t t-esc="value_id.price_extra > 0 and '+' or ''"/><span t-field="value_id.price_extra" t-field-options='{
<t t-esc="value_id.price_extra > 0 and '+' or ''"/><span t-field="value_id.price_extra" style="white-space: nowrap;" t-field-options='{
"widget": "monetary",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/>
@ -633,7 +637,7 @@
<input type="radio" class="js_variant_change" t-att-checked="'checked' if not inc else ''" t-att-name="'attribute-%s-%s' % (product.id, variant_id.attribute_id.id)" t-att-value="value_id.id" style="vertical-align: top; margin-right: 10px;"/>
<span t-field="value_id.name"/>
<span class="badge" t-if="value_id.price_extra">
<t t-esc="value_id.price_extra > 0 and '+' or ''"/><span t-field="value_id.price_extra" t-field-options='{
<t t-esc="value_id.price_extra > 0 and '+' or ''"/><span t-field="value_id.price_extra" style="white-space: nowrap;" t-field-options='{
"widget": "monetary",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/>
@ -814,14 +818,15 @@
<div class="text-muted" t-field="line.name"/>
</td>
<td class="text-center" name="price">
<t t-if="(line.product_id.lst_price - line.price_unit) &gt; 0.1">
<del class="text-danger"
<t t-if="(website.compute_curency(line.product_id.lst_price) - line.price_unit) &gt; 0.1">
<del class="text-danger" style="white-space: nowrap;"
t-field="line.product_id.lst_price" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
"widget": "monetary",
"from_currency": "res_company.partner_id.property_product_pricelist.currency_id",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/>&amp;nbsp;
</t>
<span t-field="line.price_unit" t-field-options='{
<span t-field="line.price_unit" style="white-space: nowrap;" t-field-options='{
"widget": "monetary",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/>
@ -910,14 +915,15 @@
<div class="text-muted" t-field="product.description_sale"/>
</td>
<td>
<t t-if="(product.lst_price - product.price) &gt; 0.1">
<del class="text-danger"
<t t-if="(website.compute_curency(product.lst_price) - product.price) &gt; 0.1">
<del class="text-danger" style="white-space: nowrap;"
t-field="product.lst_price" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
"widget": "monetary",
"from_currency": "res_company.partner_id.property_product_pricelist.currency_id",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/>&amp;nbsp;
</t>
<span t-field="product.price" t-field-options='{
<span t-field="product.price" style="white-space: nowrap;" t-field-options='{
"widget": "monetary",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/>
@ -1101,17 +1107,17 @@
<t t-set="website_sale_order" t-value="website.sale_get_order()"/>
<div class="row">
<div class="col-sm-6 text-right">Subtotal: </div>
<div class="col-sm-6"><span t-field="website_sale_order.amount_untaxed" t-field-options='{
<div class="col-sm-6"><span style="white-space: nowrap;" t-field="website_sale_order.amount_untaxed" t-field-options='{
"widget": "monetary",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/></div>
<div class="col-sm-6 text-right">Taxes: </div>
<div class="col-sm-6"><span t-field="website_sale_order.amount_tax" t-field-options='{
<div class="col-sm-6"><span style="white-space: nowrap;" t-field="website_sale_order.amount_tax" t-field-options='{
"widget": "monetary",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/></div>
<div class="col-sm-6 text-right"><h4>Total To Pay: </h4></div>
<div class="col-sm-6"><h4><span t-field="website_sale_order.amount_total" t-field-options='{
<div class="col-sm-6"><h4><span style="white-space: nowrap;" t-field="website_sale_order.amount_total" t-field-options='{
"widget": "monetary",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/></h4></div>
@ -1169,7 +1175,7 @@
<strong t-field="line.product_id.name"/>
</td>
<td class="text-center">
<span t-field="line.price_unit" t-field-options='{
<span t-field="line.price_unit" style="white-space: nowrap;" t-field-options='{
"widget": "monetary",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/>
@ -1310,7 +1316,7 @@
<tr width="100" style="border-top: 1px solid #000" id="order_total">
<th><h3>Total: </h3></th>
<th class="text-right">
<h3><span t-field="website_sale_order.amount_total" t-field-options='{
<h3><span t-field="website_sale_order.amount_total" style="white-space: nowrap;" t-field-options='{
"widget": "monetary",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/></h3>
@ -1319,7 +1325,7 @@
<tr width="120" class="text-muted" id="order_total_taxes">
<td><abbr title="Taxes may be updated after providing shipping address">Taxes:</abbr></td>
<td class="text-right">
<span t-field="website_sale_order.amount_tax" t-field-options='{
<span t-field="website_sale_order.amount_tax" style="white-space: nowrap;" t-field-options='{
"widget": "monetary",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/>

View File

@ -755,7 +755,7 @@ class MonetaryConverter(osv.AbstractModel):
if context is None:
context = {}
Currency = self.pool['res.currency']
display = self.display_currency(cr, uid, options)
display_currency = self.display_currency(cr, uid, options['display_currency'], options)
# lang.format mandates a sprintf-style format. These formats are non-
# minimal (they have a default fixed precision instead), and
@ -766,17 +766,23 @@ class MonetaryConverter(osv.AbstractModel):
# The log10 of the rounding should be the number of digits involved if
# negative, if positive clamp to 0 digits and call it a day.
# nb: int() ~ floor(), we want nearest rounding instead
precision = int(round(math.log10(display.rounding)))
precision = int(round(math.log10(display_currency.rounding)))
fmt = "%.{0}f".format(-precision if precision < 0 else 0)
from_amount = record[field_name]
if options.get('from_currency'):
from_currency = self.display_currency(cr, uid, options['from_currency'], options)
from_amount = Currency.compute(cr, uid, from_currency.id, display_currency.id, from_amount)
lang_code = context.get('lang') or 'en_US'
lang = self.pool['res.lang']
formatted_amount = lang.format(cr, uid, [lang_code],
fmt, Currency.round(cr, uid, display, record[field_name]),
fmt, Currency.round(cr, uid, display_currency, from_amount),
grouping=True, monetary=True)
pre = post = u''
if display.position == 'before':
if display_currency.position == 'before':
pre = u'{symbol} '
else:
post = u' {symbol}'
@ -785,12 +791,12 @@ class MonetaryConverter(osv.AbstractModel):
formatted_amount,
pre=pre, post=post,
).format(
symbol=display.symbol,
symbol=display_currency.symbol,
))
def display_currency(self, cr, uid, options):
def display_currency(self, cr, uid, currency, options):
return self.qweb_object().eval_object(
options['display_currency'], options['_qweb_context'])
currency, options['_qweb_context'])
TIMEDELTA_UNITS = (
('year', 3600 * 24 * 365),