Files
odoo_source/addons/stock/tests/common.py
T
Tiffany Chang (tic) c7f53f770c [IMP] mrp, (purchase_)stock: improve move reservation
Currently stock moves are auto-assigned (i.e. reserve free stock) both
when the scheduler is run and when a corresponding stock move that can
assign a move is completed. This strictness was causing issues for
prioritization of moves to assign, for example a picking with a
scheduled_date far in the future could automatically reserve all stock
if it was created before another picking that an immediate
scheduled_date. To ease this, an extra setting has been added to
stock.picking.type to let users choose how reservations should occur for
moves assigned to that picking_type (or picking with that picking_type):

1. 'at_confirm' = automatically when:
   - stock is available when the move's associated picking/MO is
   confirmed,
   - when new stock becomes available,
   - when the scheduler is triggered (+ stock available).
2. 'manual' = user must always manually click "Check Availability"
   button (scheduler will no longer reserve).
3. 'by_date' = automatically when within the move's reservation_date
   and:
   - stock is available when the move's associated picking/MO is
   confirmed,
   - new stock becomes available when move is already confirmed, or
   - the scheduler is run (+ stock is available).

'by_date' has an extra option of # days before the move's scheduled
date that affects the move.reservation_date.

Task: 2359317
Upgrade PR: odoo/upgrade#1868
ENT PR: odoo/enterprise#15050
2020-11-30 16:28:47 +00:00

100 lines
4.8 KiB
Python

# -*- coding: utf-8 -*-
from odoo.tests import common
class TestStockCommon(common.TransactionCase):
@classmethod
def setUpClass(cls):
super(TestStockCommon, cls).setUpClass()
cls.ProductObj = cls.env['product.product']
cls.UomObj = cls.env['uom.uom']
cls.PartnerObj = cls.env['res.partner']
cls.ModelDataObj = cls.env['ir.model.data']
cls.StockPackObj = cls.env['stock.move.line']
cls.StockQuantObj = cls.env['stock.quant']
cls.PickingObj = cls.env['stock.picking']
cls.MoveObj = cls.env['stock.move']
cls.InvObj = cls.env['stock.inventory']
cls.InvLineObj = cls.env['stock.inventory.line']
cls.LotObj = cls.env['stock.production.lot']
# Model Data
cls.picking_type_in = cls.ModelDataObj.xmlid_to_res_id('stock.picking_type_in')
cls.picking_type_out = cls.ModelDataObj.xmlid_to_res_id('stock.picking_type_out')
cls.env['stock.picking.type'].browse(cls.picking_type_out).reservation_method = 'manual'
cls.supplier_location = cls.ModelDataObj.xmlid_to_res_id('stock.stock_location_suppliers')
cls.stock_location = cls.ModelDataObj.xmlid_to_res_id('stock.stock_location_stock')
pack_location = cls.env.ref('stock.location_pack_zone')
pack_location.active = True
cls.pack_location = pack_location.id
output_location = cls.env.ref('stock.stock_location_output')
output_location.active = True
cls.output_location = output_location.id
cls.customer_location = cls.ModelDataObj.xmlid_to_res_id('stock.stock_location_customers')
cls.categ_unit = cls.ModelDataObj.xmlid_to_res_id('uom.product_uom_categ_unit')
cls.categ_kgm = cls.ModelDataObj.xmlid_to_res_id('uom.product_uom_categ_kgm')
# Product Created A, B, C, D
cls.productA = cls.ProductObj.create({'name': 'Product A', 'type': 'product'})
cls.productB = cls.ProductObj.create({'name': 'Product B', 'type': 'product'})
cls.productC = cls.ProductObj.create({'name': 'Product C', 'type': 'product'})
cls.productD = cls.ProductObj.create({'name': 'Product D', 'type': 'product'})
cls.productE = cls.ProductObj.create({'name': 'Product E', 'type': 'product'})
# Configure unit of measure.
cls.uom_kg = cls.env['uom.uom'].search([('category_id', '=', cls.categ_kgm), ('uom_type', '=', 'reference')], limit=1)
cls.uom_kg.write({
'name': 'Test-KG',
'rounding': 0.000001})
cls.uom_tone = cls.UomObj.create({
'name': 'Test-Tone',
'category_id': cls.categ_kgm,
'uom_type': 'bigger',
'factor_inv': 1000.0,
'rounding': 0.001})
cls.uom_gm = cls.UomObj.create({
'name': 'Test-G',
'category_id': cls.categ_kgm,
'uom_type': 'smaller',
'factor': 1000.0,
'rounding': 0.001})
cls.uom_mg = cls.UomObj.create({
'name': 'Test-MG',
'category_id': cls.categ_kgm,
'uom_type': 'smaller',
'factor': 100000.0,
'rounding': 0.001})
# Check Unit
cls.uom_unit = cls.env['uom.uom'].search([('category_id', '=', cls.categ_unit), ('uom_type', '=', 'reference')], limit=1)
cls.uom_unit.write({
'name': 'Test-Unit',
'rounding': 1.0})
cls.uom_dozen = cls.UomObj.create({
'name': 'Test-DozenA',
'category_id': cls.categ_unit,
'factor_inv': 12,
'uom_type': 'bigger',
'rounding': 0.001})
cls.uom_sdozen = cls.UomObj.create({
'name': 'Test-SDozenA',
'category_id': cls.categ_unit,
'factor_inv': 144,
'uom_type': 'bigger',
'rounding': 0.001})
cls.uom_sdozen_round = cls.UomObj.create({
'name': 'Test-SDozenA Round',
'category_id': cls.categ_unit,
'factor_inv': 144,
'uom_type': 'bigger',
'rounding': 1.0})
# Product for different unit of measure.
cls.DozA = cls.ProductObj.create({'name': 'Dozon-A', 'type': 'product', 'uom_id': cls.uom_dozen.id, 'uom_po_id': cls.uom_dozen.id})
cls.SDozA = cls.ProductObj.create({'name': 'SuperDozon-A', 'type': 'product', 'uom_id': cls.uom_sdozen.id, 'uom_po_id': cls.uom_sdozen.id})
cls.SDozARound = cls.ProductObj.create({'name': 'SuperDozenRound-A', 'type': 'product', 'uom_id': cls.uom_sdozen_round.id, 'uom_po_id': cls.uom_sdozen_round.id})
cls.UnitA = cls.ProductObj.create({'name': 'Unit-A', 'type': 'product'})
cls.kgB = cls.ProductObj.create({'name': 'kg-B', 'type': 'product', 'uom_id': cls.uom_kg.id, 'uom_po_id': cls.uom_kg.id})
cls.gB = cls.ProductObj.create({'name': 'g-B', 'type': 'product', 'uom_id': cls.uom_gm.id, 'uom_po_id': cls.uom_gm.id})