[FIX] website_sale: currency in line with pricelist selected
Before this fix, inconsistencies arise in the prices displayed in a multi-currency environment. For example, let's consider these 2 pricelists: - Public Pricelist, in USD - Benelux Pricelist, in EUR with 10 % discount When the Benelux Pricelist is selected, the strikethrough price is in USD, the price is in EUR, and the currency displayed is $. The reason is that the pricelist used is stored in request.session, but the templates are still using the pricelist linked to the partner. We link website.pricelist_id to the currency stored in request.session, which is more logical. We also use the currency related to this pricelist in the templates, which avoids the inconsistencies mentioned.
This commit is contained in:
@@ -123,10 +123,16 @@ class sale_order(osv.Model):
|
|||||||
class website(orm.Model):
|
class website(orm.Model):
|
||||||
_inherit = 'website'
|
_inherit = 'website'
|
||||||
|
|
||||||
|
def _get_pricelist_id(self, cr, uid, ids, name, args, context=None):
|
||||||
|
res = {}
|
||||||
|
pricelist = self.get_current_pricelist(cr, uid, context=context)
|
||||||
|
for data in self.browse(cr, uid, ids, context=context):
|
||||||
|
res[data.id] = pricelist.id
|
||||||
|
return res
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'pricelist_id': fields.related(
|
'pricelist_id': fields.function(_get_pricelist_id,\
|
||||||
'user_id', 'partner_id', 'property_product_pricelist',
|
type='many2one', relation="product.pricelist", string='Default Pricelist'),
|
||||||
type='many2one', relation='product.pricelist', string='Default Pricelist'),
|
|
||||||
'currency_id': fields.related(
|
'currency_id': fields.related(
|
||||||
'pricelist_id', 'currency_id',
|
'pricelist_id', 'currency_id',
|
||||||
type='many2one', relation='res.currency', string='Default Currency'),
|
type='many2one', relation='res.currency', string='Default Currency'),
|
||||||
@@ -180,7 +186,7 @@ class website(orm.Model):
|
|||||||
"""
|
"""
|
||||||
isocountry = request.session.geoip and request.session.geoip.get('country_code') or False
|
isocountry = request.session.geoip and request.session.geoip.get('country_code') or False
|
||||||
pl_ids = self._get_pl(cr, uid, isocountry, show_visible,
|
pl_ids = self._get_pl(cr, uid, isocountry, show_visible,
|
||||||
request.website.pricelist_id.id,
|
request.website.user_id.partner_id.property_product_pricelist.id,
|
||||||
request.session.get('website_sale_current_pl'),
|
request.session.get('website_sale_current_pl'),
|
||||||
request.website.website_pricelist_ids)
|
request.website.website_pricelist_ids)
|
||||||
return self.pool['product.pricelist'].browse(cr, uid, pl_ids, context=context)
|
return self.pool['product.pricelist'].browse(cr, uid, pl_ids, context=context)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class TestWebsitePriceList(TransactionCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestWebsitePriceList, self).setUp()
|
super(TestWebsitePriceList, self).setUp()
|
||||||
self.website = self.registry('website').browse(self.cr, self.uid, 1)
|
self.website = self.registry('website').browse(self.cr, self.uid, 1)
|
||||||
|
self.website.pricelist_id = self.registry('ir.model.data').xmlid_to_res_id(self.cr, self.uid, 'product.list0')
|
||||||
self.patcher = patch('openerp.addons.website_sale.models.sale_order.website.get_pricelist_available', wraps=self._get_pricelist_available)
|
self.patcher = patch('openerp.addons.website_sale.models.sale_order.website.get_pricelist_available', wraps=self._get_pricelist_available)
|
||||||
self.mock_get_pricelist_available = self.patcher.start()
|
self.mock_get_pricelist_available = self.patcher.start()
|
||||||
|
|
||||||
|
|||||||
@@ -93,16 +93,16 @@
|
|||||||
<del class="text-danger mr8" style="white-space: nowrap;" t-field="product.lst_price" t-field-options='{
|
<del class="text-danger mr8" style="white-space: nowrap;" t-field="product.lst_price" t-field-options='{
|
||||||
"widget": "monetary",
|
"widget": "monetary",
|
||||||
"from_currency": "product.company_id.currency_id",
|
"from_currency": "product.company_id.currency_id",
|
||||||
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
|
"display_currency": "website.currency_id"
|
||||||
}'/>
|
}'/>
|
||||||
</t>
|
</t>
|
||||||
<span t-field="product.price" style="white-space: nowrap;" t-field-options='{
|
<span t-field="product.price" style="white-space: nowrap;" t-field-options='{
|
||||||
"widget": "monetary",
|
"widget": "monetary",
|
||||||
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
|
"display_currency": "website.currency_id"
|
||||||
}'>
|
}'>
|
||||||
</span>
|
</span>
|
||||||
<span itemprop="price" style="display:none;" t-esc="product.price"/>
|
<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="website.currency_id.name"/>
|
||||||
</b>
|
</b>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@@ -423,16 +423,16 @@
|
|||||||
t-field-options='{
|
t-field-options='{
|
||||||
"widget": "monetary",
|
"widget": "monetary",
|
||||||
"from_currency": "product.company_id.currency_id",
|
"from_currency": "product.company_id.currency_id",
|
||||||
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
|
"display_currency": "website.currency_id"
|
||||||
}'/>
|
}'/>
|
||||||
<b class="oe_price" style="white-space: nowrap;"
|
<b class="oe_price" style="white-space: nowrap;"
|
||||||
t-field="product.price"
|
t-field="product.price"
|
||||||
t-field-options='{
|
t-field-options='{
|
||||||
"widget": "monetary",
|
"widget": "monetary",
|
||||||
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
|
"display_currency": "website.currency_id"
|
||||||
}'/>
|
}'/>
|
||||||
<span itemprop="price" style="display:none;" t-esc="product.price"/>
|
<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="website.currency_id.name"/>
|
||||||
</h4>
|
</h4>
|
||||||
<h4 class="css_non_editable_mode_hidden">
|
<h4 class="css_non_editable_mode_hidden">
|
||||||
<span t-field="product.lst_price"
|
<span t-field="product.lst_price"
|
||||||
@@ -456,7 +456,7 @@
|
|||||||
<t t-esc="variant_id.price_extra > 0 and '+' or ''"/><span t-field="variant_id.price_extra" style="white-space: nowrap;" t-field-options='{
|
<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",
|
"widget": "monetary",
|
||||||
"from_currency": "product.company_id.currency_id",
|
"from_currency": "product.company_id.currency_id",
|
||||||
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
|
"display_currency": "website.currency_id"
|
||||||
}'/>
|
}'/>
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
@@ -481,7 +481,7 @@
|
|||||||
<t t-esc="value_id.price_extra > 0 and '+' or ''"/><span t-field="value_id.price_extra" style="white-space: nowrap;" 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",
|
"widget": "monetary",
|
||||||
"from_currency": "product.company_id.currency_id",
|
"from_currency": "product.company_id.currency_id",
|
||||||
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
|
"display_currency": "website.currency_id"
|
||||||
}'/>
|
}'/>
|
||||||
</span>
|
</span>
|
||||||
</option>
|
</option>
|
||||||
@@ -501,7 +501,7 @@
|
|||||||
<t t-esc="value_id.price_extra > 0 and '+' or ''"/><span t-field="value_id.price_extra" style="white-space: nowrap;" 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",
|
"widget": "monetary",
|
||||||
"from_currency": "product.company_id.currency_id",
|
"from_currency": "product.company_id.currency_id",
|
||||||
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
|
"display_currency": "website.currency_id"
|
||||||
}'/>
|
}'/>
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
@@ -776,12 +776,12 @@
|
|||||||
t-field="line.product_id.lst_price" t-field-options='{
|
t-field="line.product_id.lst_price" t-field-options='{
|
||||||
"widget": "monetary",
|
"widget": "monetary",
|
||||||
"from_currency": "line.company_id.currency_id",
|
"from_currency": "line.company_id.currency_id",
|
||||||
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
|
"display_currency": "website.currency_id"
|
||||||
}'/>
|
}'/>
|
||||||
<span t-field="line.price_reduce" style="white-space: nowrap;" t-field-options='{
|
<span t-field="line.price_reduce" style="white-space: nowrap;" t-field-options='{
|
||||||
"widget": "monetary",
|
"widget": "monetary",
|
||||||
"from_currency": "website_sale_order.pricelist_id.currency_id",
|
"from_currency": "website_sale_order.pricelist_id.currency_id",
|
||||||
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
|
"display_currency": "website.currency_id"
|
||||||
}'/>
|
}'/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -898,12 +898,12 @@
|
|||||||
t-field="product.lst_price" t-field-options='{
|
t-field="product.lst_price" t-field-options='{
|
||||||
"widget": "monetary",
|
"widget": "monetary",
|
||||||
"from_currency": "product.company_id.currency_id",
|
"from_currency": "product.company_id.currency_id",
|
||||||
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
|
"display_currency": "website.currency_id"
|
||||||
}'/>
|
}'/>
|
||||||
</t>
|
</t>
|
||||||
<span t-field="product.price" style="white-space: nowrap;" t-field-options='{
|
<span t-field="product.price" style="white-space: nowrap;" t-field-options='{
|
||||||
"widget": "monetary",
|
"widget": "monetary",
|
||||||
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
|
"display_currency": "website.currency_id"
|
||||||
}'/>
|
}'/>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
@@ -1153,7 +1153,7 @@
|
|||||||
<span t-field="line.price_unit" style="white-space: nowrap;" t-field-options='{
|
<span t-field="line.price_unit" style="white-space: nowrap;" t-field-options='{
|
||||||
"widget": "monetary",
|
"widget": "monetary",
|
||||||
"from_currency": "website_sale_order.pricelist_id.currency_id",
|
"from_currency": "website_sale_order.pricelist_id.currency_id",
|
||||||
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
|
"display_currency": "website.currency_id"
|
||||||
}'/>
|
}'/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -1394,7 +1394,7 @@
|
|||||||
<span t-field="website_sale_order.amount_untaxed" style="white-space: nowrap;" t-field-options='{
|
<span t-field="website_sale_order.amount_untaxed" style="white-space: nowrap;" t-field-options='{
|
||||||
"widget": "monetary",
|
"widget": "monetary",
|
||||||
"from_currency": "website_sale_order.pricelist_id.currency_id",
|
"from_currency": "website_sale_order.pricelist_id.currency_id",
|
||||||
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
|
"display_currency": "website.currency_id"
|
||||||
}'/>
|
}'/>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -1404,7 +1404,7 @@
|
|||||||
<span t-field="website_sale_order.amount_tax" style="white-space: nowrap;" t-field-options='{
|
<span t-field="website_sale_order.amount_tax" style="white-space: nowrap;" t-field-options='{
|
||||||
"widget": "monetary",
|
"widget": "monetary",
|
||||||
"from_currency": "website_sale_order.pricelist_id.currency_id",
|
"from_currency": "website_sale_order.pricelist_id.currency_id",
|
||||||
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
|
"display_currency": "website.currency_id"
|
||||||
}'/>
|
}'/>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -1414,7 +1414,7 @@
|
|||||||
<span t-field="website_sale_order.amount_total" style="white-space: nowrap;" t-field-options='{
|
<span t-field="website_sale_order.amount_total" style="white-space: nowrap;" t-field-options='{
|
||||||
"widget": "monetary",
|
"widget": "monetary",
|
||||||
"from_currency": "website_sale_order.pricelist_id.currency_id",
|
"from_currency": "website_sale_order.pricelist_id.currency_id",
|
||||||
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
|
"display_currency": "website.currency_id"
|
||||||
}'/>
|
}'/>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user