mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[MIG/REF] stock_generate_putaway_from_inventory: Migration to 14.0
This commit is contained in:
@@ -4,8 +4,9 @@
|
|||||||
{
|
{
|
||||||
"name": "Stock Generate Putaway from Inventory",
|
"name": "Stock Generate Putaway from Inventory",
|
||||||
"summary": "Generate Putaway locations per Product deduced from Inventory",
|
"summary": "Generate Putaway locations per Product deduced from Inventory",
|
||||||
"version": "12.0.1.0.0",
|
"version": "14.0.1.0.0",
|
||||||
"author": "Akretion, Odoo Community Association (OCA)",
|
"author": "Akretion, Odoo Community Association (OCA)",
|
||||||
|
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||||
"category": "Warehouse",
|
"category": "Warehouse",
|
||||||
"depends": ["stock"],
|
"depends": ["stock"],
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
from . import stock_inventory
|
from . import stock_inventory
|
||||||
|
from . import stock_location
|
||||||
|
|||||||
@@ -8,52 +8,51 @@ from odoo.exceptions import ValidationError
|
|||||||
class StockInventory(models.Model):
|
class StockInventory(models.Model):
|
||||||
_inherit = "stock.inventory"
|
_inherit = "stock.inventory"
|
||||||
|
|
||||||
def action_generate_putaway_strategy(self):
|
def action_generate_putaway_rules(self):
|
||||||
for inventory in self:
|
self._generate_putaway_rules()
|
||||||
inventory._generate_putaway_strategy()
|
|
||||||
|
|
||||||
def _get_putaway_strategy(self, loc):
|
def _generate_putaway_rules(self):
|
||||||
if loc.putaway_strategy_id:
|
for record in self:
|
||||||
return loc.putaway_strategy_id
|
if record.state != "done":
|
||||||
elif loc.location_id:
|
raise ValidationError(
|
||||||
return self._get_putaway_strategy(loc.location_id)
|
_(
|
||||||
|
"Please validate the inventory before generating "
|
||||||
|
"the putaway strategy."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
for location in record.location_ids:
|
||||||
|
record.line_ids._generate_putaway_rules(location)
|
||||||
|
|
||||||
def _update_product_putaway_strategy(self, inventory_line, strategy):
|
|
||||||
putaway_line_obj = self.env["stock.fixed.putaway.strat"]
|
class StockInventoryLine(models.Model):
|
||||||
putaway_line = putaway_line_obj.search(
|
_inherit = "stock.inventory.line"
|
||||||
|
|
||||||
|
def _generate_putaway_rules(self, inventory_location):
|
||||||
|
# Eliminate lines for other IN locations
|
||||||
|
# and eliminate lines where quantity is null
|
||||||
|
self.filtered(
|
||||||
|
lambda x: x.location_id._is_child(inventory_location) and x.product_qty > 0
|
||||||
|
)._update_product_putaway_rule(inventory_location)
|
||||||
|
|
||||||
|
def _update_product_putaway_rule(self, location_in):
|
||||||
|
putaway_rule_obj = self.env["stock.putaway.rule"]
|
||||||
|
putaway_rules = putaway_rule_obj.search(
|
||||||
[
|
[
|
||||||
("product_id", "=", inventory_line.product_id.id),
|
("product_id", "in", self.mapped("product_id").ids),
|
||||||
("putaway_id", "=", strategy.id),
|
("location_in_id", "=", location_in.id),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
if putaway_line:
|
for record in self:
|
||||||
putaway_line.write({"fixed_location_id": inventory_line.location_id.id})
|
putaway_rule = putaway_rules.filtered(
|
||||||
else:
|
lambda x: x.product_id == record.product_id
|
||||||
putaway_line_obj.create(
|
|
||||||
{
|
|
||||||
"product_id": inventory_line.product_id.id,
|
|
||||||
"fixed_location_id": inventory_line.location_id.id,
|
|
||||||
"putaway_id": strategy.id,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
if putaway_rule:
|
||||||
def _generate_putaway_strategy(self):
|
putaway_rule.location_out_id = record.location_id
|
||||||
if self.state != "done":
|
else:
|
||||||
raise ValidationError(
|
putaway_rule_obj.create(
|
||||||
_(
|
{
|
||||||
"Please validate the inventory before generating "
|
"product_id": record.product_id.id,
|
||||||
"the putaway strategy."
|
"location_in_id": location_in.id,
|
||||||
|
"location_out_id": record.location_id.id,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
)
|
|
||||||
putaway = self._get_putaway_strategy(self.location_id)
|
|
||||||
if not putaway:
|
|
||||||
raise ValidationError(
|
|
||||||
_(
|
|
||||||
"Inventory location doesn't have a putaway strategy. "
|
|
||||||
"Please set a putaway strategy on the inventory's "
|
|
||||||
"location."
|
|
||||||
)
|
|
||||||
)
|
|
||||||
for line in self.line_ids:
|
|
||||||
if line.product_qty > 0:
|
|
||||||
self._update_product_putaway_strategy(line, putaway)
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Copyright 2021 Akretion (https://www.akretion.com).
|
||||||
|
# @author Pierrick Brun <pierrick.brun@akretion.com>
|
||||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo import models
|
||||||
|
|
||||||
|
|
||||||
|
class StockLocation(models.Model):
|
||||||
|
_inherit = "stock.location"
|
||||||
|
|
||||||
|
def _is_child(self, location):
|
||||||
|
self.ensure_one()
|
||||||
|
if self == location:
|
||||||
|
return True
|
||||||
|
elif self.location_id:
|
||||||
|
return self.location_id._is_child(location)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
@@ -14,57 +14,47 @@ class TestGeneratePutaway(TransactionCase):
|
|||||||
self.inventory = self.env["stock.inventory"].create(
|
self.inventory = self.env["stock.inventory"].create(
|
||||||
{
|
{
|
||||||
"name": "example inventory",
|
"name": "example inventory",
|
||||||
"location_id": self.inventory_location.id,
|
"location_ids": [(6, 0, [self.inventory_location.id])],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.inventory_line_1_product = ref("product.product_product_24")
|
self.inventory_line_1_product = ref("product.product_product_24")
|
||||||
self.inventory_line_1_location = ref("stock.stock_location_14")
|
self.inventory_line_1_location = ref("stock.stock_location_components")
|
||||||
self.inventory_line_1 = self.env["stock.inventory.line"].create(
|
self.inventory_line_1 = self.env["stock.inventory.line"].create(
|
||||||
{
|
{
|
||||||
"product_id": self.inventory_line_1_product.id,
|
"product_id": self.inventory_line_1_product.id,
|
||||||
"location_id": self.inventory_line_1_location.id,
|
"location_id": self.inventory_line_1_location.id,
|
||||||
|
"inventory_id": self.inventory.id,
|
||||||
|
"product_qty": 1,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.irrelevant_location = ref("stock.stock_location_customers")
|
self.irrelevant_location = ref("stock.stock_location_customers")
|
||||||
|
|
||||||
def test_error_not_validated(self):
|
def test_error_not_validated(self):
|
||||||
putaway = self.env["product.putaway"].create({"name": "Putaway example"})
|
|
||||||
self.inventory.putaway_strategy_id = putaway
|
|
||||||
self.inventory.action_cancel_draft()
|
self.inventory.action_cancel_draft()
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
self.inventory.action_generate_putaway_strategy()
|
self.inventory.action_generate_putaway_rules()
|
||||||
|
|
||||||
def test_error_location_has_no_putaway_strategy(self):
|
|
||||||
self.inventory_location.putaway_strategy_id = self.env["product.putaway"]
|
|
||||||
self.inventory.action_start()
|
|
||||||
self.inventory.action_validate()
|
|
||||||
with self.assertRaises(ValidationError):
|
|
||||||
self.inventory.action_generate_putaway_strategy()
|
|
||||||
|
|
||||||
def test_putaway_line_location_update(self):
|
def test_putaway_line_location_update(self):
|
||||||
putaway = self.env["product.putaway"].create({"name": "Putaway example"})
|
putaway = self.env["stock.putaway.rule"].create(
|
||||||
putaway_line_1 = self.env["stock.fixed.putaway.strat"].create(
|
|
||||||
{
|
{
|
||||||
"putaway_id": putaway.id,
|
"location_out_id": self.irrelevant_location.id,
|
||||||
"fixed_location_id": self.irrelevant_location.id,
|
"location_in_id": self.inventory_location.id,
|
||||||
"product_id": self.inventory_line_1_product.id,
|
"product_id": self.inventory_line_1_product.id,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.inventory_location.putaway_strategy_id = putaway
|
|
||||||
self.inventory.action_start()
|
self.inventory.action_start()
|
||||||
self.inventory.action_validate()
|
self.inventory.action_validate()
|
||||||
self.inventory.action_generate_putaway_strategy()
|
self.inventory.action_generate_putaway_rules()
|
||||||
self.assertEqual(
|
self.assertEqual(putaway.location_out_id, self.inventory_line_1_location)
|
||||||
putaway_line_1.fixed_location_id, self.inventory_line_1_location
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_putaway_line_location_create(self):
|
def test_putaway_line_location_create(self):
|
||||||
putaway = self.env["product.putaway"].create({"name": "Putaway example"})
|
|
||||||
self.inventory_location.putaway_strategy_id = putaway
|
|
||||||
self.inventory.action_start()
|
self.inventory.action_start()
|
||||||
self.inventory.action_validate()
|
self.inventory.action_validate()
|
||||||
self.inventory.action_generate_putaway_strategy()
|
self.inventory.action_generate_putaway_rules()
|
||||||
putaway_line = putaway.product_location_ids.filtered(
|
putaway = self.env["stock.putaway.rule"].search(
|
||||||
lambda r: r.product_id == self.inventory_line_1_product
|
[
|
||||||
|
("product_id", "=", self.inventory_line_1_product.id),
|
||||||
|
("location_in_id", "=", self.inventory_location.id),
|
||||||
|
]
|
||||||
)
|
)
|
||||||
self.assertEqual(putaway_line.fixed_location_id, self.inventory_line_1_location)
|
self.assertEqual(putaway.location_out_id, self.inventory_line_1_location)
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
<?xml version="1.0" ?>
|
<?xml version="1.0" ?>
|
||||||
<openerp>
|
<odoo>
|
||||||
<data>
|
|
||||||
<record id="action_generate_putaway_strategy" model="ir.actions.server">
|
<record id="action_generate_putaway_strategy" model="ir.actions.server">
|
||||||
<field name="name">Generate putaway strategies</field>
|
<field name="name">Generate putaway strategies</field>
|
||||||
<field name="model_id" ref="model_stock_inventory" />
|
<field name="model_id" ref="model_stock_inventory" />
|
||||||
<field name="binding_model_id" ref="stock.model_stock_inventory" />
|
<field name="binding_model_id" ref="stock.model_stock_inventory" />
|
||||||
<field name="state">code</field>
|
<field name="state">code</field>
|
||||||
<field name="code">
|
<field name="code">
|
||||||
records.action_generate_putaway_strategy()
|
records.action_generate_putaway_rules()
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
</data>
|
</odoo>
|
||||||
</openerp>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user