Permalink
Browse files

fix convert date

  • Loading branch information...
seb-odoo committed Nov 8, 2018
1 parent 0de58f3 commit caeba9025e798e2fe36058ea2df25444d6f855dd
@@ -665,8 +665,7 @@ def _get_combination_info(self, combination, product_id=False, add_qty=1, pricel
if pricelist and pricelist.currency_id != product_template.currency_id:
list_price = product_template.currency_id._convert(
list_price, pricelist.currency_id,
product_template.company_id, fields.Date.today()
list_price, pricelist.currency_id, product_template.company_id
)
return {
@@ -75,8 +75,6 @@ def _show_optional_products(self, product_id, variant_values, pricelist, handle_
to_currency = pricelist.currency_id if pricelist else product.currency_id
company = request.env['res.company'].browse(request.env.context.get('company_id')) or request.env['res.users']._get_company()
date = request.env.context.get('date') or fields.Date.today()
# TODO SEB fix and/or don't use compute_currency at different places.
# should probably be from product currency instead of current user company currency
def compute_currency(price):
return product.currency_id._convert(price, to_currency, company, date)
@@ -147,7 +147,7 @@ def _get_pricelist_context(self):
def _get_compute_currency(self, pricelist, product=None):
from_currency = (product or request.env.user.company_id).currency_id
to_currency = pricelist.currency_id
return lambda price: from_currency._convert(price, to_currency, (product or request.env.user).company_id, fields.Date.today())
return lambda price: from_currency._convert(price, to_currency, (product or request.env.user).company_id)
def _get_compute_currency_and_context(self, product=None):
pricelist_context, pricelist = self._get_pricelist_context()
@@ -308,7 +308,7 @@ def product(self, product, category='', search='', **kwargs):
pricelist = request.website.get_current_pricelist()
def compute_currency(price):
return product.currency_id._convert(price, pricelist.currency_id, product.company_id, fields.Date.today())
return product.currency_id._convert(price, pricelist.currency_id, product.company_id)
if not product_context.get('pricelist'):
product_context['pricelist'] = pricelist.id
@@ -201,7 +201,7 @@ def _get_combination_info_website(self, combination, product=False, add_qty=1):
if pricelist.discount_policy == 'without_discount':
combination_info = self._get_combination_info(combination, product.id, qty, None)
lst_price = self_with_context.currency_id._convert(combination_info.get('list_price'), pricelist.currency_id, self.env.user.company_id, fields.Date.today())
lst_price = self_with_context.currency_id._convert(combination_info.get('list_price'), pricelist.currency_id, self.env.user.company_id)
website_public_price = taxes.compute_all(lst_price, pricelist.currency_id, qty, self, partner)[tax_display]
else:
website_public_price = website_price
@@ -833,7 +833,7 @@
</t>
</td>
<td class="text-center td-price" name="price">
<t t-set="website_public_price_converted" t-value="website.currency_id._convert(line.product_id.website_public_price, website_sale_order.currency_id, website_sale_order.company_id, fields.Date.today())"/>
<t t-set="website_public_price_converted" t-value="website.currency_id._convert(line.product_id.website_public_price, website_sale_order.currency_id, website_sale_order.company_id)"/>
<t t-if="(website_sale_order.pricelist_id.discount_policy == 'without_discount' and website_sale_order.currency_id.compare_amounts(website_public_price_converted, line.price_reduce) == 1) or website_sale_order.currency_id.compare_amounts(line.price_unit, line.price_reduce) == 1">
<del t-attf-class="#{'text-danger mr8'}" style="white-space: nowrap;" t-esc="website_public_price_converted" t-options="{'widget': 'monetary', 'display_currency': website_sale_order.currency_id}" />
</t>
@@ -185,7 +185,7 @@ def _get_conversion_rate(self, from_currency, to_currency, company, date):
res = currency_rates.get(to_currency.id) / currency_rates.get(from_currency.id)
return res
def _convert(self, from_amount, to_currency, company, date, round=True):
def _convert(self, from_amount, to_currency, company, date=fields.Date.today(), round=True):
"""Returns the converted amount of ``from_amount``` from the currency
``self`` to the currency ``to_currency`` for the given ``date`` and
company.

0 comments on commit caeba90

Please sign in to comment.