From 6d40daa082feb0cd68c760cbea34238557c64058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 13 Apr 2018 18:49:19 +0200 Subject: [PATCH] Correctly convert unit price to set as cost price The unit price of the supplier move is in the currency of the purchase when the cost price must be in the company currency. issue7243 review44901002 --- purchase.py | 10 +++++++++- tests/scenario_sale_supply_drop_shipment.rst | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/purchase.py b/purchase.py index 14cd897e57..c54eb5e33c 100644 --- a/purchase.py +++ b/purchase.py @@ -1,5 +1,7 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +from decimal import Decimal + from trytond import backend from trytond.model import ModelSQL, ValueMixin, fields from trytond.pyson import Eval @@ -187,9 +189,15 @@ class PurchaseLine: return result def get_move(self, move_type): + pool = Pool() + Currency = pool.get('currency.currency') move = super(PurchaseLine, self).get_move(move_type) if move and self.purchase.customer: - move.cost_price = move.unit_price + digits = move.__class__.cost_price.digits + cost_price = Currency.compute( + move.currency, move.unit_price, move.company.currency) + move.cost_price = cost_price.quantize( + Decimal(str(10.0 ** -digits[1]))) return move diff --git a/tests/scenario_sale_supply_drop_shipment.rst b/tests/scenario_sale_supply_drop_shipment.rst index f44483fca9..50dd5b6beb 100644 --- a/tests/scenario_sale_supply_drop_shipment.rst +++ b/tests/scenario_sale_supply_drop_shipment.rst @@ -180,6 +180,8 @@ Receiving only 100 products:: >>> move.quantity = 100 >>> move.unit_price Decimal('3.0000') + >>> move.cost_price + Decimal('3.0000') >>> shipment.click('ship') >>> move, = shipment.customer_moves >>> move.unit_price