Skip to content

Commit

Permalink
[IMP] stock_inventory_discrepancy: better inheritance
Browse files Browse the repository at this point in the history
During the migration to 13.0 of this module it was decided to introduce a hook.

Refactoring to a regular override plays better with inheritance.
  • Loading branch information
thomaspaulb committed Jan 10, 2025
1 parent be1d923 commit 3a0c20a
Show file tree
Hide file tree
Showing 4 changed files with 37 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 @@ -21,7 +21,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.

37 changes: 37 additions & 0 deletions stock_inventory_discrepancy/models/stock_quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,40 @@ def action_apply_inventory(self):
)
return action
return super().action_apply_inventory()

def user_has_groups(self, groups):
# - Allow specific group to validate inventory
# - Allow validate on pending status
ret = super().user_has_groups(groups)
if (
self.env.context.get("from_apply_inventory")
and groups == "stock.group_stock_manager"
and not ret
and not super().user_has_groups(
"stock_inventory_discrepancy.group_stock_inventory_validation"
)
and not super().user_has_groups(
"stock_inventory_discrepancy.group_stock_inventory_validation_always"
)
):
raise UserError(
_("Only a stock manager can validate an inventory adjustment.")
)
return ret

def _apply_inventory(self):
if (
not self.user_has_groups("stock.group_stock_manager")
and not self.user_has_groups(
"stock_inventory_discrepancy.group_stock_inventory_validation"
)
and not self.user_has_groups(
"stock_inventory_discrepancy.group_stock_inventory_validation_always"
)
):
raise UserError(
_("Only a stock manager can validate an inventory adjustment.")
)
# Allow to write last_inventory_date on stock.location
self = self.sudo().with_context(from_apply_inventory=True)
return super(StockQuant, self)._apply_inventory()

0 comments on commit 3a0c20a

Please sign in to comment.