mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[FIX] corrected calculation of immediately_usable_qty on product.product and
product.template, now takes in account variants and correctly displays value. [FLAKE8] Removing duplicate modules and moving README.rst into __unported__
This commit is contained in:
committed by
Florian da Costa
parent
bc1a4c5e1c
commit
e2fb3e7c8c
@@ -19,18 +19,15 @@
|
|||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from openerp import models, fields, api
|
from openerp import models
|
||||||
|
|
||||||
|
|
||||||
class ProductTemplate(models.Model):
|
class Product(models.Model):
|
||||||
"""Subtract incoming qty from immediately_usable_qty"""
|
"""Subtract incoming qty from immediately_usable_qty"""
|
||||||
_inherit = 'product.template'
|
_inherit = 'product.product'
|
||||||
|
|
||||||
@api.depends('virtual_available')
|
def _immediately_usable_qty(self):
|
||||||
def _product_available(self):
|
|
||||||
"""Ignore the incoming goods in the quantity available to promise"""
|
"""Ignore the incoming goods in the quantity available to promise"""
|
||||||
super(ProductTemplate, self)._product_available()
|
super(Product, self)._immediately_usable_qty()
|
||||||
for product in self:
|
for product in self:
|
||||||
product.immediately_usable_qty -= product.incoming_qty
|
product.immediately_usable_qty -= product.incoming_qty
|
||||||
|
|
||||||
immediately_usable_qty = fields.Float(compute='_product_available')
|
|
||||||
|
|||||||
1
stock_available_immediately/tests/__init__.py
Normal file
1
stock_available_immediately/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import test_stock_available_immediately
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Copyright (C) 2015 Therp BV <http://therp.nl>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
from openerp.tests.common import TransactionCase
|
||||||
|
|
||||||
|
|
||||||
|
class testStockLogisticsWarehouse(TransactionCase):
|
||||||
|
|
||||||
|
def test01_stock_levels(self):
|
||||||
|
"""checking that immediately_usable_qty actually reflects \
|
||||||
|
the variations in stock, both on product and template"""
|
||||||
|
moveObj = self.env['stock.move']
|
||||||
|
productObj = self.env['product.product']
|
||||||
|
templateObj = self.env['product.template']
|
||||||
|
supplier_location = self.env.ref('stock.stock_location_suppliers')
|
||||||
|
stock_location = self.env.ref('stock.stock_location_stock')
|
||||||
|
customer_location = self.env.ref('stock.stock_location_customers')
|
||||||
|
uom_unit = self.env.ref('product.product_uom_unit')
|
||||||
|
|
||||||
|
# Create product template
|
||||||
|
templateAB = templateObj.create(
|
||||||
|
{'name': 'templAB',
|
||||||
|
'uom_id': uom_unit.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
# Create product A and B
|
||||||
|
productA = productObj.create(
|
||||||
|
{'name': 'product A',
|
||||||
|
'standard_price': 1,
|
||||||
|
'type': 'product',
|
||||||
|
'uom_id': uom_unit.id,
|
||||||
|
'default_code': 'A',
|
||||||
|
'product_tmpl_id': templateAB.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
productB = productObj.create(
|
||||||
|
{'name': 'product B',
|
||||||
|
'standard_price': 1,
|
||||||
|
'type': 'product',
|
||||||
|
'uom_id': uom_unit.id,
|
||||||
|
'default_code': 'B',
|
||||||
|
'product_tmpl_id': templateAB.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
# Create a stock move from INCOMING to STOCK
|
||||||
|
stockMoveInA = moveObj.create(
|
||||||
|
{'location_id': supplier_location.id,
|
||||||
|
'location_dest_id': stock_location.id,
|
||||||
|
'name': 'MOVE INCOMING -> STOCK ',
|
||||||
|
'product_id': productA.id,
|
||||||
|
'product_uom': productA.uom_id.id,
|
||||||
|
'product_uom_qty': 2,
|
||||||
|
})
|
||||||
|
|
||||||
|
stockMoveInB = moveObj.create(
|
||||||
|
{'location_id': supplier_location.id,
|
||||||
|
'location_dest_id': stock_location.id,
|
||||||
|
'name': 'MOVE INCOMING -> STOCK ',
|
||||||
|
'product_id': productB.id,
|
||||||
|
'product_uom': productB.uom_id.id,
|
||||||
|
'product_uom_qty': 3,
|
||||||
|
})
|
||||||
|
|
||||||
|
def compare_product_usable_qty(product, value):
|
||||||
|
# Refresh, because the function field is not recalculated between
|
||||||
|
# transactions
|
||||||
|
product.refresh()
|
||||||
|
self.assertEqual(product.immediately_usable_qty, value)
|
||||||
|
|
||||||
|
compare_product_usable_qty(productA, 0)
|
||||||
|
compare_product_usable_qty(templateAB, 0)
|
||||||
|
|
||||||
|
stockMoveInA.action_confirm()
|
||||||
|
compare_product_usable_qty(productA, 0)
|
||||||
|
compare_product_usable_qty(templateAB, 0)
|
||||||
|
|
||||||
|
stockMoveInA.action_assign()
|
||||||
|
compare_product_usable_qty(productA, 0)
|
||||||
|
compare_product_usable_qty(templateAB, 0)
|
||||||
|
|
||||||
|
stockMoveInA.action_done()
|
||||||
|
compare_product_usable_qty(productA, 2)
|
||||||
|
compare_product_usable_qty(templateAB, 2)
|
||||||
|
|
||||||
|
# will directly trigger action_done on productB
|
||||||
|
stockMoveInB.action_done()
|
||||||
|
compare_product_usable_qty(productA, 2)
|
||||||
|
compare_product_usable_qty(productB, 3)
|
||||||
|
compare_product_usable_qty(templateAB, 5)
|
||||||
|
|
||||||
|
# Create a stock move from STOCK to CUSTOMER
|
||||||
|
stockMoveOutA = moveObj.create(
|
||||||
|
{'location_id': stock_location.id,
|
||||||
|
'location_dest_id': customer_location.id,
|
||||||
|
'name': ' STOCK --> CUSTOMER ',
|
||||||
|
'product_id': productA.id,
|
||||||
|
'product_uom': productA.uom_id.id,
|
||||||
|
'product_uom_qty': 1,
|
||||||
|
'state': 'confirmed',
|
||||||
|
})
|
||||||
|
|
||||||
|
stockMoveOutA.action_done()
|
||||||
|
compare_product_usable_qty(productA, 1)
|
||||||
|
compare_product_usable_qty(templateAB, 4)
|
||||||
Reference in New Issue
Block a user