changeset 1ee58c8f9471 in modules/product_cost_fifo:default
details:
https://hg.tryton.org/modules/product_cost_fifo?cmd=changeset;node=1ee58c8f9471
description:
Use original cost price for returned move
and factorize the cost price of move for cost computation
issue9440
review327491003
diffstat:
move.py | 20 ++++----------------
product.py | 18 ++----------------
2 files changed, 6 insertions(+), 32 deletions(-)
diffs (100 lines):
diff -r d865960839f5 -r 1ee58c8f9471 move.py
--- a/move.py Wed Jul 29 23:50:03 2020 +0200
+++ b/move.py Mon Aug 10 23:38:04 2020 +0200
@@ -68,7 +68,6 @@
'''
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 @@
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 @@
'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 @@
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')
diff -r d865960839f5 -r 1ee58c8f9471 product.py
--- a/product.py Wed Jul 29 23:50:03 2020 +0200
+++ b/product.py Mon Aug 10 23:38:04 2020 +0200
@@ -4,7 +4,6 @@
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 @@
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 @@
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 @@
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)