mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[ADD] stock_inventory: Products Under Review
This commit is contained in:
@@ -147,6 +147,34 @@ class InventoryAdjustmentsGroup(models.Model):
|
||||
help="Specific responsible of Inventory Adjustment.",
|
||||
)
|
||||
|
||||
products_under_review_ids = fields.Many2many(
|
||||
comodel_name="product.product",
|
||||
compute="_compute_products_under_review_ids",
|
||||
search="_search_products_under_review_ids",
|
||||
string="Products Under Review",
|
||||
relation="stock_inventory_product_review_rel",
|
||||
)
|
||||
|
||||
def _search_products_under_review_ids(self, operator, value):
|
||||
quants = self.env["stock.quant"].search(
|
||||
[("to_do", "=", True), ("product_id", operator, value)]
|
||||
)
|
||||
inventories = quants.mapped("stock_inventory_ids")
|
||||
return [("id", "in", inventories.ids), ("state", "=", "in_progress")]
|
||||
|
||||
@api.depends("stock_quant_ids", "stock_quant_ids.to_do", "state")
|
||||
def _compute_products_under_review_ids(self):
|
||||
for record in self:
|
||||
if record.state == "in_progress":
|
||||
products = record.stock_quant_ids.filtered(
|
||||
lambda quant: quant.to_do
|
||||
).mapped("product_id")
|
||||
record.products_under_review_ids = (
|
||||
[(6, 0, products.ids)] if products else [(5, 0, 0)]
|
||||
)
|
||||
else:
|
||||
record.products_under_review_ids = [(5, 0, 0)]
|
||||
|
||||
@api.depends("stock_quant_ids")
|
||||
def _compute_count_stock_quants(self):
|
||||
for rec in self:
|
||||
|
||||
@@ -6,6 +6,13 @@ class StockQuant(models.Model):
|
||||
|
||||
to_do = fields.Boolean(default=False)
|
||||
|
||||
stock_inventory_ids = fields.Many2many(
|
||||
"stock.inventory",
|
||||
"stock_inventory_stock_quant_rel",
|
||||
string="Stock Inventories",
|
||||
copy=False,
|
||||
)
|
||||
|
||||
def _apply_inventory(self):
|
||||
res = super()._apply_inventory()
|
||||
record_moves = self.env["stock.move.line"]
|
||||
|
||||
@@ -521,3 +521,37 @@ class TestStockInventory(TransactionCase):
|
||||
self.assertTrue(inventory.stock_quant_ids)
|
||||
inventory.action_state_to_done()
|
||||
self.assertTrue(all(not quant.to_do for quant in quants))
|
||||
|
||||
def test_11_products_under_review(self):
|
||||
inventory1 = self.inventory_model.create(
|
||||
{
|
||||
"name": "Inventory_Test_Under_Review_1",
|
||||
"product_selection": "all",
|
||||
"location_ids": [self.location1.id],
|
||||
}
|
||||
)
|
||||
inventory1.action_state_to_in_progress()
|
||||
self.assertEqual(inventory1.state, "in_progress")
|
||||
self.assertIn(self.product, inventory1.products_under_review_ids)
|
||||
inventory1.action_state_to_done()
|
||||
self.assertEqual(inventory1.state, "done")
|
||||
self.assertEqual(inventory1.products_under_review_ids.ids, [])
|
||||
|
||||
def test_12_search_products_under_review(self):
|
||||
inventory = self.inventory_model.create(
|
||||
{
|
||||
"name": "Inventory for Search Test",
|
||||
"product_selection": "all",
|
||||
"location_ids": [self.location1.id],
|
||||
}
|
||||
)
|
||||
inventory.action_state_to_in_progress()
|
||||
search_result = self.inventory_model._search_products_under_review_ids(
|
||||
"=", self.product.id
|
||||
)
|
||||
expected_result = [("id", "in", [inventory.id]), ("state", "=", "in_progress")]
|
||||
self.assertEqual(
|
||||
search_result,
|
||||
expected_result,
|
||||
"The search function did not return the expected results",
|
||||
)
|
||||
|
||||
@@ -162,6 +162,10 @@
|
||||
<field name="date" />
|
||||
<field name="state" />
|
||||
<field name="product_ids" string="Product" />
|
||||
<field
|
||||
name="products_under_review_ids"
|
||||
string="Products Under Review"
|
||||
/>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user