Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] stock_inventory_discrepancy: better inheritance #2232

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

41 changes: 41 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,44 @@
)
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 not (
self.env.context.get("from_apply_inventory")
and groups == "stock.group_stock_manager"
):
return ret
if (
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(

Check warning on line 112 in stock_inventory_discrepancy/models/stock_quant.py

View check run for this annotation

Codecov / codecov/patch

stock_inventory_discrepancy/models/stock_quant.py#L112

Added line #L112 was not covered by tests
_("Only a stock manager can validate an inventory adjustment.")
)
else:
return True

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(

Check warning on line 128 in stock_inventory_discrepancy/models/stock_quant.py

View check run for this annotation

Codecov / codecov/patch

stock_inventory_discrepancy/models/stock_quant.py#L128

Added line #L128 was not covered by tests
_("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()
rvalyi marked this conversation as resolved.
Show resolved Hide resolved
Loading