Skip to content

Commit

Permalink
[FIX] stock_inventory_discrepancy: avoid full overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
ivantodorovich committed Nov 12, 2024
1 parent 257254b commit 093072f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 78 deletions.
1 change: 0 additions & 1 deletion stock_inventory_discrepancy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

from . import models
from . import wizards
from .hooks import post_load_hook
1 change: 0 additions & 1 deletion stock_inventory_discrepancy/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"wizards/confirm_discrepancy_wiz.xml",
],
"license": "AGPL-3",
"post_load": "post_load_hook",
"installable": True,
"application": False,
}
76 changes: 0 additions & 76 deletions stock_inventory_discrepancy/hooks.py

This file was deleted.

11 changes: 11 additions & 0 deletions stock_inventory_discrepancy/models/stock_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ class StockLocation(models.Model):
)

def write(self, values):
# OVERRIDE: Allow the inventory user to set the last inventory date.
# https://github.com/odoo/odoo/blob/534220ee/addons/stock/models/stock_quant.py#L775
if (
self.env.context.get("_stock_inventory_discrepancy")
and len(values) == 1
and "last_inventory_date" in values
and self.user_has_groups(
"stock_inventory_discrepancy.group_stock_inventory_validation"
)
):
self = self.sudo()
res = super().write(values)
# Set the discrepancy threshold for all child locations
if values.get("discrepancy_threshold", False):
Expand Down
17 changes: 17 additions & 0 deletions stock_inventory_discrepancy/models/stock_quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ def _compute_has_over_discrepancy(self):
rec.discrepancy_percent > rec.discrepancy_threshold
)

def user_has_groups(self, groups):
# Most inventory adjustment operations are limited to users having
# the Inventory Manager group.
# OVERRIDE: Hijack the check to replace it with our own group.
if groups == "stock.group_stock_manager" and self.env.context.get(
"_stock_inventory_discrepancy"
):
groups = "stock_inventory_discrepancy.group_stock_inventory_validation"
return super().user_has_groups(groups)

def _apply_inventory(self):
if self.user_has_groups(
"stock_inventory_discrepancy.group_stock_inventory_validation"
):
self = self.with_context(_stock_inventory_discrepancy=True)
return super()._apply_inventory()

def action_apply_inventory(self):
if self.env.context.get("skip_exceeded_discrepancy", False):
return super().action_apply_inventory()
Expand Down

0 comments on commit 093072f

Please sign in to comment.