diff --git a/stock_inventory_discrepancy/models/stock_inventory.py b/stock_inventory_discrepancy/models/stock_inventory.py
index fe44f56f7..6ae5bec86 100644
--- a/stock_inventory_discrepancy/models/stock_inventory.py
+++ b/stock_inventory_discrepancy/models/stock_inventory.py
@@ -1,5 +1,4 @@
-# Copyright 2017-2020 ForgeFlow S.L.
-# (http://www.forgeflow.com)
+# Copyright 2017-21 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
@@ -33,7 +32,7 @@ class StockInventory(models.Model):
def _compute_over_discrepancy_line_count(self):
for inventory in self:
lines = inventory.line_ids.filtered(
- lambda line: line.discrepancy_percent > line.discrepancy_threshold
+ lambda line: line._has_over_discrepancy()
)
inventory.over_discrepancy_line_count = len(lines)
@@ -57,9 +56,7 @@ class StockInventory(models.Model):
def _action_done(self):
for inventory in self:
- if inventory.over_discrepancy_line_count and inventory.line_ids.filtered(
- lambda t: t.discrepancy_threshold > 0.0
- ):
+ if inventory.over_discrepancy_line_count > 0.0:
if self.user_has_groups(
"stock_inventory_discrepancy.group_stock_inventory_validation"
) and not self.user_has_groups(
diff --git a/stock_inventory_discrepancy/models/stock_inventory_line.py b/stock_inventory_discrepancy/models/stock_inventory_line.py
index a1a0fceda..546931bef 100644
--- a/stock_inventory_discrepancy/models/stock_inventory_line.py
+++ b/stock_inventory_discrepancy/models/stock_inventory_line.py
@@ -1,5 +1,4 @@
-# Copyright 2017-2020 ForgeFlow S.L.
-# (http://www.forgeflow.com)
+# Copyright 2017-21 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
@@ -29,6 +28,7 @@ class StockInventoryLine(models.Model):
help="Maximum Discrepancy Rate Threshold",
compute="_compute_discrepancy_threshold",
)
+ has_over_discrepancy = fields.Boolean(compute="_compute_has_over_discrepancy",)
@api.depends("theoretical_qty", "product_qty")
def _compute_discrepancy(self):
@@ -52,3 +52,10 @@ class StockInventoryLine(models.Model):
line.discrepancy_threshold = whs.discrepancy_threshold
else:
line.discrepancy_threshold = False
+
+ def _compute_has_over_discrepancy(self):
+ for rec in self:
+ rec.has_over_discrepancy = rec._has_over_discrepancy()
+
+ def _has_over_discrepancy(self):
+ return self.discrepancy_percent > self.discrepancy_threshold > 0
diff --git a/stock_inventory_discrepancy/tests/test_inventory_discrepancy.py b/stock_inventory_discrepancy/tests/test_inventory_discrepancy.py
index 07b894086..3c97c309c 100644
--- a/stock_inventory_discrepancy/tests/test_inventory_discrepancy.py
+++ b/stock_inventory_discrepancy/tests/test_inventory_discrepancy.py
@@ -173,6 +173,7 @@ class TestInventoryDiscrepancy(TransactionCase):
)
inventory.with_user(self.user).action_start()
inventory.with_user(self.user).action_validate()
+ self.assertTrue(inventory.line_ids.has_over_discrepancy)
self.assertEqual(
inventory.over_discrepancy_line_count,
1,
diff --git a/stock_inventory_discrepancy/views/stock_inventory_view.xml b/stock_inventory_discrepancy/views/stock_inventory_view.xml
index 26927dd88..69fb87db4 100644
--- a/stock_inventory_discrepancy/views/stock_inventory_view.xml
+++ b/stock_inventory_discrepancy/views/stock_inventory_view.xml
@@ -59,11 +59,12 @@
+
theoretical_qty < 0 or discrepancy_percent > discrepancy_threshold or "product_qty != theoretical_qty"
+ >theoretical_qty < 0 or has_over_discrepancy