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
This commit is contained in:
Cédric Krier committed 2018-04-13 18:49:19 +02:00
1 parent 2a1497d40f
commit 6d40daa082
2 files changed
+11 -1

No files matched your search

+9 -1
View File
@@ -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
@@ -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