[FIX] stock_account: consignment
If a move line has an owner_id, it should be ignored in the valuation process.
This commit is contained in:
@@ -184,7 +184,7 @@ class StockMove(models.Model):
|
||||
|
||||
:return: True if the move is entering the company else False
|
||||
"""
|
||||
for move_line in self.move_line_ids:
|
||||
for move_line in self.move_line_ids.filtered(lambda ml: not ml.owner_id):
|
||||
if not move_line.location_id._should_be_valued() and move_line.location_dest_id._should_be_valued():
|
||||
return True
|
||||
return False
|
||||
@@ -195,7 +195,7 @@ class StockMove(models.Model):
|
||||
|
||||
:return: True if the move is leaving the company else False
|
||||
"""
|
||||
for move_line in self.move_line_ids:
|
||||
for move_line in self.move_line_ids.filtered(lambda ml: not ml.owner_id):
|
||||
if move_line.location_id._should_be_valued() and not move_line.location_dest_id._should_be_valued():
|
||||
return True
|
||||
return False
|
||||
@@ -204,7 +204,7 @@ class StockMove(models.Model):
|
||||
def _run_fifo(self, move, quantity=None):
|
||||
move.ensure_one()
|
||||
# Find back incoming stock moves (called candidates here) to value this move.
|
||||
valued_move_lines = move.move_line_ids.filtered(lambda ml: ml.location_id._should_be_valued() and not ml.location_dest_id._should_be_valued())
|
||||
valued_move_lines = move.move_line_ids.filtered(lambda ml: ml.location_id._should_be_valued() and not ml.location_dest_id._should_be_valued() and not ml.owner_id)
|
||||
valued_quantity = 0
|
||||
for valued_move_line in valued_move_lines:
|
||||
valued_quantity += valued_move_line.product_uom_id._compute_quantity(valued_move_line.qty_done, move.product_id.uom_id)
|
||||
@@ -263,7 +263,7 @@ class StockMove(models.Model):
|
||||
def _run_valuation(self, quantity=None):
|
||||
self.ensure_one()
|
||||
if self._is_in():
|
||||
valued_move_lines = self.move_line_ids.filtered(lambda ml: not ml.location_id._should_be_valued() and ml.location_dest_id._should_be_valued())
|
||||
valued_move_lines = self.move_line_ids.filtered(lambda ml: not ml.location_id._should_be_valued() and ml.location_dest_id._should_be_valued() and not ml.owner_id)
|
||||
valued_quantity = 0
|
||||
for valued_move_line in valued_move_lines:
|
||||
valued_quantity += valued_move_line.product_uom_id._compute_quantity(valued_move_line.qty_done, self.product_id.uom_id)
|
||||
@@ -288,7 +288,7 @@ class StockMove(models.Model):
|
||||
})
|
||||
self.write(vals)
|
||||
elif self._is_out():
|
||||
valued_move_lines = self.move_line_ids.filtered(lambda ml: ml.location_id._should_be_valued() and not ml.location_dest_id._should_be_valued())
|
||||
valued_move_lines = self.move_line_ids.filtered(lambda ml: ml.location_id._should_be_valued() and not ml.location_dest_id._should_be_valued() and not ml.owner_id)
|
||||
valued_quantity = sum(valued_move_lines.mapped('qty_done'))
|
||||
self.env['stock.move']._run_fifo(self, quantity=quantity)
|
||||
if self.product_id.cost_method in ['standard', 'average']:
|
||||
|
||||
@@ -12,6 +12,7 @@ class TestStockValuation(TransactionCase):
|
||||
self.customer_location = self.env.ref('stock.stock_location_customers')
|
||||
self.supplier_location = self.env.ref('stock.stock_location_suppliers')
|
||||
self.partner = self.env['res.partner'].create({'name': 'xxx'})
|
||||
self.owner1 = self.env['res.partner'].create({'name': 'owner1'})
|
||||
self.uom_unit = self.env.ref('product.product_uom_unit')
|
||||
self.product1 = self.env['product.product'].create({
|
||||
'name': 'Product A',
|
||||
@@ -2208,6 +2209,24 @@ class TestStockValuation(TransactionCase):
|
||||
|
||||
self.assertEqual(move5.value, -477.6)
|
||||
|
||||
# Receives 10 units but assign them to an owner, the valuation should not be impacted.
|
||||
move6 = self.env['stock.move'].create({
|
||||
'name': '10 units to an owner',
|
||||
'location_id': self.supplier_location.id,
|
||||
'location_dest_id': self.stock_location.id,
|
||||
'product_id': self.product1.id,
|
||||
'product_uom': self.uom_unit.id,
|
||||
'product_uom_qty': 10.0,
|
||||
'price_unit': 99,
|
||||
})
|
||||
move6._action_confirm()
|
||||
move6._action_assign()
|
||||
move6.move_line_ids.owner_id = self.owner1.id
|
||||
move6.move_line_ids.qty_done = 10.0
|
||||
move6._action_done()
|
||||
|
||||
self.assertEqual(move6.value, 0)
|
||||
|
||||
def test_average_perpetual_2(self):
|
||||
self.product1.product_tmpl_id.cost_method = 'average'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user