mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_inventory_discrepancy: centralize logic for over discrepancy assessment and ease extension.
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
# Copyright 2017-2020 ForgeFlow S.L.
|
# Copyright 2017-21 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||||
# (http://www.forgeflow.com)
|
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from odoo import _, api, fields, models
|
from odoo import _, api, fields, models
|
||||||
@@ -33,7 +32,7 @@ class StockInventory(models.Model):
|
|||||||
def _compute_over_discrepancy_line_count(self):
|
def _compute_over_discrepancy_line_count(self):
|
||||||
for inventory in self:
|
for inventory in self:
|
||||||
lines = inventory.line_ids.filtered(
|
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)
|
inventory.over_discrepancy_line_count = len(lines)
|
||||||
|
|
||||||
@@ -57,9 +56,7 @@ class StockInventory(models.Model):
|
|||||||
|
|
||||||
def _action_done(self):
|
def _action_done(self):
|
||||||
for inventory in self:
|
for inventory in self:
|
||||||
if inventory.over_discrepancy_line_count and inventory.line_ids.filtered(
|
if inventory.over_discrepancy_line_count > 0.0:
|
||||||
lambda t: t.discrepancy_threshold > 0.0
|
|
||||||
):
|
|
||||||
if self.user_has_groups(
|
if self.user_has_groups(
|
||||||
"stock_inventory_discrepancy.group_stock_inventory_validation"
|
"stock_inventory_discrepancy.group_stock_inventory_validation"
|
||||||
) and not self.user_has_groups(
|
) and not self.user_has_groups(
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
# Copyright 2017-2020 ForgeFlow S.L.
|
# Copyright 2017-21 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||||
# (http://www.forgeflow.com)
|
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from odoo import api, fields, models
|
from odoo import api, fields, models
|
||||||
@@ -29,6 +28,7 @@ class StockInventoryLine(models.Model):
|
|||||||
help="Maximum Discrepancy Rate Threshold",
|
help="Maximum Discrepancy Rate Threshold",
|
||||||
compute="_compute_discrepancy_threshold",
|
compute="_compute_discrepancy_threshold",
|
||||||
)
|
)
|
||||||
|
has_over_discrepancy = fields.Boolean(compute="_compute_has_over_discrepancy",)
|
||||||
|
|
||||||
@api.depends("theoretical_qty", "product_qty")
|
@api.depends("theoretical_qty", "product_qty")
|
||||||
def _compute_discrepancy(self):
|
def _compute_discrepancy(self):
|
||||||
@@ -52,3 +52,10 @@ class StockInventoryLine(models.Model):
|
|||||||
line.discrepancy_threshold = whs.discrepancy_threshold
|
line.discrepancy_threshold = whs.discrepancy_threshold
|
||||||
else:
|
else:
|
||||||
line.discrepancy_threshold = False
|
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
|
||||||
|
|||||||
@@ -173,6 +173,7 @@ class TestInventoryDiscrepancy(TransactionCase):
|
|||||||
)
|
)
|
||||||
inventory.with_user(self.user).action_start()
|
inventory.with_user(self.user).action_start()
|
||||||
inventory.with_user(self.user).action_validate()
|
inventory.with_user(self.user).action_validate()
|
||||||
|
self.assertTrue(inventory.line_ids.has_over_discrepancy)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
inventory.over_discrepancy_line_count,
|
inventory.over_discrepancy_line_count,
|
||||||
1,
|
1,
|
||||||
|
|||||||
@@ -59,11 +59,12 @@
|
|||||||
<field name="discrepancy_qty" />
|
<field name="discrepancy_qty" />
|
||||||
<field name="discrepancy_percent" />
|
<field name="discrepancy_percent" />
|
||||||
<field name="discrepancy_threshold" />
|
<field name="discrepancy_threshold" />
|
||||||
|
<field name="has_over_discrepancy" invisible="1" />
|
||||||
</field>
|
</field>
|
||||||
<xpath expr="//tree" position="attributes">
|
<xpath expr="//tree" position="attributes">
|
||||||
<attribute
|
<attribute
|
||||||
name="decoration-danger"
|
name="decoration-danger"
|
||||||
>theoretical_qty < 0 or discrepancy_percent > discrepancy_threshold or "product_qty != theoretical_qty"</attribute>
|
>theoretical_qty < 0 or has_over_discrepancy</attribute>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|||||||
Reference in New Issue
Block a user