mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_available_immediately: black, isort, prettier
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
../../../../stock_available_immediately
|
||||||
6
setup/stock_available_immediately/setup.py
Normal file
6
setup/stock_available_immediately/setup.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
setup_requires=['setuptools-odoo'],
|
||||||
|
odoo_addon=True,
|
||||||
|
)
|
||||||
@@ -11,5 +11,5 @@
|
|||||||
"author": "Camptocamp,Sodexis,Odoo Community Association (OCA),Sergio Díaz",
|
"author": "Camptocamp,Sodexis,Odoo Community Association (OCA),Sergio Díaz",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"category": "Hidden",
|
"category": "Hidden",
|
||||||
'installable': True,
|
"installable": True,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,17 +7,19 @@ from odoo import api, models
|
|||||||
|
|
||||||
|
|
||||||
class ProductProduct(models.Model):
|
class ProductProduct(models.Model):
|
||||||
_inherit = 'product.product'
|
_inherit = "product.product"
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _compute_available_quantities_dict(self):
|
def _compute_available_quantities_dict(self):
|
||||||
res, stock_dict = \
|
res, stock_dict = super(
|
||||||
super(ProductProduct, self)._compute_available_quantities_dict()
|
ProductProduct, self
|
||||||
|
)._compute_available_quantities_dict()
|
||||||
for product in self:
|
for product in self:
|
||||||
res[product.id]['immediately_usable_qty'] -= \
|
res[product.id]["immediately_usable_qty"] -= stock_dict[product.id][
|
||||||
stock_dict[product.id]['incoming_qty']
|
"incoming_qty"
|
||||||
|
]
|
||||||
return res, stock_dict
|
return res, stock_dict
|
||||||
|
|
||||||
@api.depends('virtual_available', 'incoming_qty')
|
@api.depends("virtual_available", "incoming_qty")
|
||||||
def _compute_available_quantities(self):
|
def _compute_available_quantities(self):
|
||||||
return super(ProductProduct, self)._compute_available_quantities()
|
return super(ProductProduct, self)._compute_available_quantities()
|
||||||
|
|||||||
@@ -8,58 +8,67 @@ from odoo.tests.common import TransactionCase
|
|||||||
|
|
||||||
|
|
||||||
class TestStockLogisticsWarehouse(TransactionCase):
|
class TestStockLogisticsWarehouse(TransactionCase):
|
||||||
|
|
||||||
def test01_stock_levels(self):
|
def test01_stock_levels(self):
|
||||||
"""
|
"""
|
||||||
Checking that immediately_usable_qty actually reflects the variations
|
Checking that immediately_usable_qty actually reflects the variations
|
||||||
in stock, both on product and template.
|
in stock, both on product and template.
|
||||||
"""
|
"""
|
||||||
moveObj = self.env['stock.move']
|
moveObj = self.env["stock.move"]
|
||||||
productObj = self.env['product.product']
|
productObj = self.env["product.product"]
|
||||||
templateObj = self.env['product.template']
|
templateObj = self.env["product.template"]
|
||||||
supplier_location = self.env.ref('stock.stock_location_suppliers')
|
supplier_location = self.env.ref("stock.stock_location_suppliers")
|
||||||
stock_location = self.env.ref('stock.stock_location_stock')
|
stock_location = self.env.ref("stock.stock_location_stock")
|
||||||
customer_location = self.env.ref('stock.stock_location_customers')
|
customer_location = self.env.ref("stock.stock_location_customers")
|
||||||
uom_unit = self.env.ref('uom.product_uom_unit')
|
uom_unit = self.env.ref("uom.product_uom_unit")
|
||||||
|
|
||||||
# Create product template
|
# Create product template
|
||||||
templateAB = templateObj.create({
|
templateAB = templateObj.create({"name": "templAB", "uom_id": uom_unit.id})
|
||||||
'name': 'templAB',
|
|
||||||
'uom_id': uom_unit.id})
|
|
||||||
|
|
||||||
# Create product A and B
|
# Create product A and B
|
||||||
productA = productObj.create({
|
productA = productObj.create(
|
||||||
'name': 'product A',
|
{
|
||||||
'standard_price': 1,
|
"name": "product A",
|
||||||
'type': 'product',
|
"standard_price": 1,
|
||||||
'uom_id': uom_unit.id,
|
"type": "product",
|
||||||
'default_code': 'A',
|
"uom_id": uom_unit.id,
|
||||||
'product_tmpl_id': templateAB.id})
|
"default_code": "A",
|
||||||
|
"product_tmpl_id": templateAB.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
productB = productObj.create({
|
productB = productObj.create(
|
||||||
'name': 'product B',
|
{
|
||||||
'standard_price': 1,
|
"name": "product B",
|
||||||
'type': 'product',
|
"standard_price": 1,
|
||||||
'uom_id': uom_unit.id,
|
"type": "product",
|
||||||
'default_code': 'B',
|
"uom_id": uom_unit.id,
|
||||||
'product_tmpl_id': templateAB.id})
|
"default_code": "B",
|
||||||
|
"product_tmpl_id": templateAB.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
# Create a stock move from INCOMING to STOCK
|
# Create a stock move from INCOMING to STOCK
|
||||||
stockMoveInA = moveObj.create({
|
stockMoveInA = moveObj.create(
|
||||||
'location_id': supplier_location.id,
|
{
|
||||||
'location_dest_id': stock_location.id,
|
"location_id": supplier_location.id,
|
||||||
'name': 'MOVE INCOMING -> STOCK ',
|
"location_dest_id": stock_location.id,
|
||||||
'product_id': productA.id,
|
"name": "MOVE INCOMING -> STOCK ",
|
||||||
'product_uom': productA.uom_id.id,
|
"product_id": productA.id,
|
||||||
'product_uom_qty': 2})
|
"product_uom": productA.uom_id.id,
|
||||||
|
"product_uom_qty": 2,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
stockMoveInB = moveObj.create({
|
stockMoveInB = moveObj.create(
|
||||||
'location_id': supplier_location.id,
|
{
|
||||||
'location_dest_id': stock_location.id,
|
"location_id": supplier_location.id,
|
||||||
'name': 'MOVE INCOMING -> STOCK ',
|
"location_dest_id": stock_location.id,
|
||||||
'product_id': productB.id,
|
"name": "MOVE INCOMING -> STOCK ",
|
||||||
'product_uom': productB.uom_id.id,
|
"product_id": productB.id,
|
||||||
'product_uom_qty': 3})
|
"product_uom": productB.uom_id.id,
|
||||||
|
"product_uom_qty": 3,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def compare_product_usable_qty(product, value):
|
def compare_product_usable_qty(product, value):
|
||||||
# Refresh, because the function field is not recalculated between
|
# Refresh, because the function field is not recalculated between
|
||||||
@@ -78,7 +87,7 @@ class TestStockLogisticsWarehouse(TransactionCase):
|
|||||||
compare_product_usable_qty(productA, 0)
|
compare_product_usable_qty(productA, 0)
|
||||||
compare_product_usable_qty(templateAB, 0)
|
compare_product_usable_qty(templateAB, 0)
|
||||||
|
|
||||||
stockMoveInA.move_line_ids.write({'qty_done': 2.0})
|
stockMoveInA.move_line_ids.write({"qty_done": 2.0})
|
||||||
stockMoveInA._action_done()
|
stockMoveInA._action_done()
|
||||||
compare_product_usable_qty(productA, 2)
|
compare_product_usable_qty(productA, 2)
|
||||||
compare_product_usable_qty(templateAB, 2)
|
compare_product_usable_qty(templateAB, 2)
|
||||||
@@ -86,25 +95,28 @@ class TestStockLogisticsWarehouse(TransactionCase):
|
|||||||
# will directly trigger action_done on productB
|
# will directly trigger action_done on productB
|
||||||
stockMoveInB._action_confirm()
|
stockMoveInB._action_confirm()
|
||||||
stockMoveInB._action_assign()
|
stockMoveInB._action_assign()
|
||||||
stockMoveInB.move_line_ids.write({'qty_done': 3.0})
|
stockMoveInB.move_line_ids.write({"qty_done": 3.0})
|
||||||
stockMoveInB._action_done()
|
stockMoveInB._action_done()
|
||||||
compare_product_usable_qty(productA, 2)
|
compare_product_usable_qty(productA, 2)
|
||||||
compare_product_usable_qty(productB, 3)
|
compare_product_usable_qty(productB, 3)
|
||||||
compare_product_usable_qty(templateAB, 5)
|
compare_product_usable_qty(templateAB, 5)
|
||||||
|
|
||||||
# Create a stock move from STOCK to CUSTOMER
|
# Create a stock move from STOCK to CUSTOMER
|
||||||
stockMoveOutA = moveObj.create({
|
stockMoveOutA = moveObj.create(
|
||||||
'location_id': stock_location.id,
|
{
|
||||||
'location_dest_id': customer_location.id,
|
"location_id": stock_location.id,
|
||||||
'name': ' STOCK --> CUSTOMER ',
|
"location_dest_id": customer_location.id,
|
||||||
'product_id': productA.id,
|
"name": " STOCK --> CUSTOMER ",
|
||||||
'product_uom': productA.uom_id.id,
|
"product_id": productA.id,
|
||||||
'product_uom_qty': 1,
|
"product_uom": productA.uom_id.id,
|
||||||
'state': 'confirmed'})
|
"product_uom_qty": 1,
|
||||||
|
"state": "confirmed",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
stockMoveOutA._action_confirm()
|
stockMoveOutA._action_confirm()
|
||||||
stockMoveOutA._action_assign()
|
stockMoveOutA._action_assign()
|
||||||
stockMoveOutA.move_line_ids.write({'qty_done': 1.0})
|
stockMoveOutA.move_line_ids.write({"qty_done": 1.0})
|
||||||
stockMoveOutA._action_done()
|
stockMoveOutA._action_done()
|
||||||
compare_product_usable_qty(productA, 1)
|
compare_product_usable_qty(productA, 1)
|
||||||
compare_product_usable_qty(templateAB, 4)
|
compare_product_usable_qty(templateAB, 4)
|
||||||
|
|||||||
Reference in New Issue
Block a user