Use original cost price for returned move

and factorize the cost price of move for cost computation

issue9440
review327491003
This commit is contained in:
Cédric Krier committed 2020-08-10 23:38:04 +02:00
1 parent e0631bf9fe
commit 2691cb7ecf
2 files changed
+6 -32

No files matched your search

+4 -16
View File
@@ -68,7 +68,6 @@ class Move(metaclass=PoolMeta):
'''
pool = Pool()
Uom = pool.get('product.uom')
Currency = pool.get('currency.currency')
total_qty = Uom.compute_qty(self.uom, self.quantity,
self.product.default_uom, round=False)
@@ -81,16 +80,7 @@ class Move(metaclass=PoolMeta):
to_save = []
for move, move_qty in fifo_moves:
consumed_qty += move_qty
if move.from_location.type in {'supplier', 'production'}:
with Transaction().set_context(date=move.effective_date):
move_unit_price = Currency.compute(
move.currency, move.unit_price,
self.company.currency, round=False)
move_unit_price = Uom.compute_price(
move.uom, move_unit_price, move.product.default_uom)
else:
move_unit_price = move.cost_price or 0
cost_price += move_unit_price * Decimal(str(move_qty))
cost_price += move.get_cost_price() * Decimal(str(move_qty))
move_qty = Uom.compute_qty(self.product.default_uom, move_qty,
move.uom, round=False)
@@ -107,10 +97,8 @@ class Move(metaclass=PoolMeta):
'cost_price', **self._cost_price_pattern)
# Compute average cost price
self.unit_price_company, unit_price_company = (
cost_price, self.unit_price_company)
average_cost_price = self._compute_product_cost_price('out')
self.unit_price_company = unit_price_company
average_cost_price = self._compute_product_cost_price(
'out', product_cost_price=cost_price)
if cost_price:
cost_price = round_price(cost_price)
@@ -120,7 +108,7 @@ class Move(metaclass=PoolMeta):
def _do(self):
cost_price = super(Move, self)._do()
if (self.from_location.type in ('supplier', 'production')
if (self.from_location.type != 'storage'
and self.to_location.type == 'storage'
and self.product.cost_price_method == 'fifo'):
cost_price = self._compute_product_cost_price('in')
+2 -16
View File
@@ -4,7 +4,6 @@ import datetime as dt
from decimal import Decimal
from trytond.config import config
from trytond.transaction import Transaction
from trytond.pool import Pool, PoolMeta
from trytond.modules.product import round_price
@@ -93,7 +92,6 @@ class Product(metaclass=PoolMeta):
def recompute_cost_price_fifo(self, start=None):
pool = Pool()
Move = pool.get('stock.move')
Currency = pool.get('currency.currency')
Uom = pool.get('product.uom')
Revision = pool.get('product.cost_price.revision')
@@ -149,11 +147,7 @@ class Product(metaclass=PoolMeta):
consumed_qty = 0
for move, move_qty in fifo_moves:
consumed_qty += move_qty
if move.from_location.type in {'supplier', 'production'}:
unit_price = move.unit_price_company
else:
unit_price = move.cost_price or 0
cost_price += unit_price * Decimal(str(move_qty))
cost_price += move.get_cost_price() * Decimal(str(move_qty))
if consumed_qty:
return round_price(cost_price / Decimal(str(consumed_qty)))
@@ -204,15 +198,7 @@ class Product(metaclass=PoolMeta):
if move.from_location.type == 'storage':
qty *= -1
if in_move(move):
if move.from_location.type in {'supplier', 'production'}:
with Transaction().set_context(date=move.effective_date):
unit_price = Currency.compute(
move.currency, move.unit_price,
move.company.currency, round=False)
unit_price = Uom.compute_price(
move.uom, unit_price, self.default_uom)
else:
unit_price = cost_price
unit_price = move.get_cost_price(product_cost_price=cost_price)
if quantity + qty > 0 and quantity >= 0:
cost_price = (
(cost_price * quantity) + (unit_price * qty)