[FIX] stock_account: inventory with company

- Set a company on the inventory location
- Create a stockable product, FIFO, real-time, with a cost
- Receive a unit

The product stock value remains zero.

The fact that the inventory location has a company set should not impact
the product cost. This is useful when a scrap location as a company set.

The domain of move selection is incomplete. It should be, for the 'in'
moves:
- coming from a location without company, or an inventory location
  within the same company
- going to a location within the same company

For the 'out' moves:
- coming from to a location within the same company
- going to a location without company, or an inventory location within
  the same company

opw-1943384

closes odoo/odoo#31485

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Nicolas Martinelli
2019-04-01 11:00:29 +00:00
parent f7301a8eef
commit 67ea26460f
2 changed files with 75 additions and 4 deletions
+30 -4
View File
@@ -155,24 +155,50 @@ class StockMove(models.Model):
@api.model
def _get_in_base_domain(self, company_id=False):
# Domain:
# - state is done
# - coming from a location without company, or an inventory location within the same company
# - going to a location within the same company
domain = [
('state', '=', 'done'),
('location_id.company_id', '=', False),
('location_dest_id.company_id', '=', company_id or self.env.user.company_id.id)
'&',
'|',
('location_id.company_id', '=', False),
'&',
('location_id.usage', 'in', ['inventory', 'production']),
('location_id.company_id', '=', company_id or self.env.user.company_id.id),
('location_dest_id.company_id', '=', company_id or self.env.user.company_id.id),
]
return domain
@api.model
def _get_all_base_domain(self, company_id=False):
# Domain:
# - state is done
# Then, either 'in' or 'out' moves.
# 'in' moves:
# - coming from a location without company, or an inventory location within the same company
# - going to a location within the same company
# 'out' moves:
# - coming from to a location within the same company
# - going to a location without company, or an inventory location within the same company
domain = [
('state', '=', 'done'),
'|',
'&',
('location_id.company_id', '=', False),
'|',
('location_id.company_id', '=', False),
'&',
('location_id.usage', 'in', ['inventory', 'production']),
('location_id.company_id', '=', company_id or self.env.user.company_id.id),
('location_dest_id.company_id', '=', company_id or self.env.user.company_id.id),
'&',
('location_id.company_id', '=', company_id or self.env.user.company_id.id),
('location_dest_id.company_id', '=', False)
'|',
('location_dest_id.company_id', '=', False),
'&',
('location_dest_id.usage', '=', 'inventory'),
('location_dest_id.company_id', '=', company_id or self.env.user.company_id.id),
]
return domain
@@ -14,6 +14,7 @@ class TestStockValuation(TransactionCase):
self.stock_location = self.env.ref('stock.stock_location_stock')
self.customer_location = self.env.ref('stock.stock_location_customers')
self.supplier_location = self.env.ref('stock.stock_location_suppliers')
self.inventory_location = self.env.ref('stock.location_inventory')
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')
@@ -3872,3 +3873,47 @@ class TestStockValuation(TransactionCase):
self.assertEqual(self.product1.with_context(to_date=Date.to_string(date6)).stock_value, 100)
self.assertEqual(self.product1.qty_at_date, 10)
self.assertEqual(self.product1.stock_value, 100)
def test_inventory_fifo_1(self):
""" Make an inventory from a location with a company set, and ensure the product has a stock
value. When the product is sold, ensure there is no remaining quantity on the original move
and no stock value.
"""
self.product1.standard_price = 15
self.product1.product_tmpl_id.cost_method = 'fifo'
self.inventory_location.company_id = self.env.user.company_id.id
# Start Inventory: 12 units
move1 = self.env['stock.move'].create({
'name': 'Adjustment of 12 units',
'location_id': self.inventory_location.id,
'location_dest_id': self.stock_location.id,
'product_id': self.product1.id,
'product_uom': self.uom_unit.id,
'product_uom_qty': 12.0,
})
move1._action_confirm()
move1._action_assign()
move1.move_line_ids.qty_done = 12.0
move1._action_done()
self.assertAlmostEqual(move1.value, 180.0)
self.assertAlmostEqual(move1.remaining_qty, 12.0)
self.assertAlmostEqual(self.product1.stock_value, 180.0)
# Sell the 12 units
move2 = self.env['stock.move'].create({
'name': 'Sell 12 units',
'location_id': self.stock_location.id,
'location_dest_id': self.customer_location.id,
'product_id': self.product1.id,
'product_uom': self.uom_unit.id,
'product_uom_qty': 12.0,
})
move2._action_confirm()
move2._action_assign()
move2.move_line_ids.qty_done = 12.0
move2._action_done()
self.assertAlmostEqual(move1.remaining_qty, 0.0)
self.assertAlmostEqual(self.product1.stock_value, 0.0)