Files
odoo_source/addons/stock/tests/test_product.py
T
Simon Lejeune b3180c8411 [REF] stock: new quant implementation
The main idea of this new implementation is that stock.quant is now a
cache of the quantity per location/lot/pack/owner key. We removed every
identity per record, such as `history_ids` or `inventory_value` so that
we can now avoid the linear creation of stock.quant records and are able
to work with only one record per key.

The algorithms to retrieve the quantity per key are made to work with
multiple records, this way we can implement strategies to workaround
postgres locks if concurrent transactions try to work on the same quant
row.

Quants will not be linked to moves anymore, this is in order to be able
to edit stock moves more easily/freely. We removed the links with this
commit and wipe out the `action_assign` on stock move. This will be
implemented in a followup commit, once the relations between stock.move,
stock.pack.operation and stock.quant are clarified.

This commit seems to have unecessary diff, but it was done in order to
run tests on the new implementation.

We adapt the views by removing the fields not present anymore in the
model. This include the complete removal of the inventory valuation
view, as the implementation of stock valuation will be refactored and
moved on stock.move in a following revision.

We wipe out `action_cancel`, `recalculate_move_state`,
`move_quants_by_lot_v10` and `quants_unreserve`.

* `get_removal_strategy` moved from `stock.move` to `stock.quant`

Stock quant model:
  * qty renamed to quantity
  * history_ids: because the quants are not moved
  * inventory_value: implementation moved to stock.move
  * packaging_type_id: doesn't seem to be used (in filters?)
  * propagated_from_id: because we do not split forced quants
  * reservation_id: because the reservation are not linked to
    the stock.move.line

We remove the `lot_ids` computed field, as it depended on the link
between stock moves and quants and could be replaced by a related
to the move lines once the new relation between stock.move,
stock.pack.operation and stock.quant is clarified in a further commit.
Furthermore, the field was not displayed to the user.
2017-07-14 17:08:21 +02:00

69 lines
3.0 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
# Author: Leonardo Pistone
# Copyright 2015 Camptocamp SA
from odoo.addons.stock.tests.common2 import TestStockCommon
class TestVirtualAvailable(TestStockCommon):
def setUp(self):
super(TestVirtualAvailable, self).setUp()
# Make `product3` a stockable product for this test. Indeed, creating quants
# and playing with owners is not possible for consumables.
self.product_3.type = 'product'
self.env['stock.quant'].create({
'product_id': self.product_3.id,
'location_id': self.env.ref('stock.stock_location_stock').id,
'quantity': 30.0})
self.env['stock.quant'].create({
'product_id': self.product_3.id,
'location_id': self.env.ref('stock.stock_location_stock').id,
'quantity': 10.0,
'owner_id': self.user_stock_user.partner_id.id})
self.picking_out = self.env['stock.picking'].create({
'picking_type_id': self.ref('stock.picking_type_out'),
'location_id': self.env.ref('stock.stock_location_stock').id,
'location_dest_id': self.env.ref('stock.stock_location_customers').id})
self.env['stock.move'].create({
'name': 'a move',
'product_id': self.product_3.id,
'product_uom_qty': 3.0,
'product_uom': self.product_3.uom_id.id,
'picking_id': self.picking_out.id,
'location_id': self.env.ref('stock.stock_location_stock').id,
'location_dest_id': self.env.ref('stock.stock_location_customers').id})
self.picking_out_2 = self.env['stock.picking'].create({
'picking_type_id': self.ref('stock.picking_type_out'),
'location_id': self.env.ref('stock.stock_location_stock').id,
'location_dest_id': self.env.ref('stock.stock_location_customers').id})
self.env['stock.move'].create({
'restrict_partner_id': self.user_stock_user.partner_id.id,
'name': 'another move',
'product_id': self.product_3.id,
'product_uom_qty': 5.0,
'product_uom': self.product_3.uom_id.id,
'picking_id': self.picking_out_2.id,
'location_id': self.env.ref('stock.stock_location_stock').id,
'location_dest_id': self.env.ref('stock.stock_location_customers').id})
def test_without_owner(self):
self.assertAlmostEqual(40.0, self.product_3.virtual_available)
self.picking_out.action_assign()
self.picking_out_2.action_assign()
self.assertAlmostEqual(32.0, self.product_3.virtual_available)
def test_with_owner(self):
prod_context = self.product_3.with_context(owner_id=self.user_stock_user.partner_id.id)
self.assertAlmostEqual(10.0, prod_context.virtual_available)
self.picking_out.action_assign()
self.picking_out_2.action_assign()
self.assertAlmostEqual(5.0, prod_context.virtual_available)