Skip to content

Commit

Permalink
[IMP] delivery: ease to inherit delivery currency computation
Browse files Browse the repository at this point in the history
closes odoo#85946

X-original-commit: f4f833b
Signed-off-by: Arnold Moyaux <arm@odoo.com>
Signed-off-by: Wolfgang Taferner <w.taferner@wtioit.at>
Co-authored-by: Andreas Perhab <andreas.perhab@wt-io-it.at>
  • Loading branch information
wtaferner and ap-wtioit committed Mar 8, 2022
1 parent 9f12405 commit 2060efd
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions addons/delivery/models/delivery_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,28 @@ def base_on_rule_rate_shipment(self, order):
'price': 0.0,
'error_message': e.args[0],
'warning_message': False}
if order.company_id.currency_id.id != order.pricelist_id.currency_id.id:
price_unit = order.company_id.currency_id._convert(
price_unit, order.pricelist_id.currency_id, order.company_id, order.date_order or fields.Date.today())

price_unit = self._compute_currency(order, price_unit, 'company_to_pricelist')

return {'success': True,
'price': price_unit,
'error_message': False,
'warning_message': False}

def _get_conversion_currencies(self, order, conversion):
if conversion == 'company_to_pricelist':
from_currency, to_currency = order.company_id.currency_id, order.pricelist_id.currency_id
elif conversion == 'pricelist_to_company':
from_currency, to_currency = order.currency_id, order.company_id.currency_id

return from_currency, to_currency

def _compute_currency(self, order, price, conversion):
from_currency, to_currency = self._get_conversion_currencies(order, conversion)
if from_currency.id == to_currency.id:
return price
return from_currency._convert(price, to_currency, order.company_id, order.date_order or fields.Date.today())

def _get_price_available(self, order):
self.ensure_one()
self = self.sudo()
Expand All @@ -90,8 +103,7 @@ def _get_price_available(self, order):
quantity += qty
total = (order.amount_total or 0.0) - total_delivery

total = order.currency_id._convert(
total, order.company_id.currency_id, order.company_id, order.date_order or fields.Date.today())
total = self._compute_currency(order, total, 'pricelist_to_company')

return self._get_price_from_picking(total, weight, volume, quantity)

Expand Down

0 comments on commit 2060efd

Please sign in to comment.