Use domain method to select incoming and outgoing move to recompute cost price

issue10586
review369311002
This commit is contained in:
Cédric Krier committed 2021-07-28 00:33:12 +02:00
1 parent 28d761fbf6
commit c4efb34fdf
1 file changed
+14 -14
+14 -14
View File
@@ -99,21 +99,22 @@ class Product(metaclass=PoolMeta):
('product', '=', self.id),
self._domain_moves_cost(),
['OR',
[
('to_location.type', '=', 'storage'),
('from_location.type', '!=', 'storage'),
],
[
('from_location.type', '=', 'storage'),
('to_location.type', '!=', 'storage'),
],
],
self._domain_in_moves_cost(),
self._domain_out_moves_cost(),
]
]
if start:
domain.append(('effective_date', '>=', start))
moves = Move.search(
domain, order=[('effective_date', 'ASC'), ('id', 'ASC')])
_in_moves = Move.search([
('product', '=', self.id),
self._domain_moves_cost(),
self._domain_in_moves_cost(),
], order=[])
_in_moves = set(m.id for m in _in_moves)
revisions = Revision.get_for_product(self)
cost_price = Decimal(0)
@@ -121,8 +122,7 @@ class Product(metaclass=PoolMeta):
if start:
domain.remove(('effective_date', '>=', start))
domain.append(('effective_date', '<', start))
domain.append(
('from_location.type', 'in', ['supplier', 'production']))
domain.append(self._domain_in_moves_cost())
prev_moves = Move.search(
domain,
order=[('effective_date', 'DESC'), ('id', 'DESC')],
@@ -135,10 +135,10 @@ class Product(metaclass=PoolMeta):
quantity = Decimal(str(quantity))
def in_move(move):
return move.to_location.type == 'storage'
return move.id in _in_moves
def out_move(move):
return move.from_location.type == 'storage'
return not in_move(move)
def compute_fifo_cost_price(quantity, date):
fifo_moves = self.get_fifo_move(float(quantity), date=date)
@@ -195,7 +195,7 @@ class Product(metaclass=PoolMeta):
revisions, cost_price, move.effective_date)
qty = Uom.compute_qty(move.uom, move.quantity, self.default_uom)
qty = Decimal(str(qty))
if move.from_location.type == 'storage':
if out_move(move):
qty *= -1
if in_move(move):
unit_price = move.get_cost_price(product_cost_price=cost_price)