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][FIX] project_stock: Avoid AccessError in the form view of tasks for users without permissions in stock.move #1296

Merged
merged 1 commit into from
Jun 11, 2024
Merged
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
2 changes: 1 addition & 1 deletion project_stock/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def setUpClass(cls):
cls.stage_in_progress = cls.env.ref("project.project_stage_1")
cls.stage_done = cls.env.ref("project.project_stage_2")
group_stock_user = "stock.group_stock_user"
new_test_user(
cls.basic_user = new_test_user(
cls.env,
login="basic-user",
groups="project.group_project_user,%s" % group_stock_user,
Expand Down
17 changes: 16 additions & 1 deletion project_stock/tests/test_project_stock.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Copyright 2022-2023 Tecnativa - Víctor Martínez
# Copyright 2022-2024 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields
from odoo.tests import Form
from odoo.tests.common import users
from odoo.tools import mute_logger

from .common import TestProjectStockBase

Expand Down Expand Up @@ -81,6 +82,15 @@ def test_project_task_without_analytic_account(self):
def test_project_task_without_analytic_account_manager_user(self):
self.test_project_task_without_analytic_account()

def test_project_task_user_access_without_stock_group(self):
self.basic_user.write(
{
"groups_id": [(6, 0, [self.env.ref("project.group_project_user").id])],
}
)
task_form = Form(self.task.with_user(self.basic_user))
self.assertEqual(task_form.project_id, self.project)

def test_project_task_analytic_lines_without_tags(self):
self.task = self.env["project.task"].browse(self.task.id)
self.task.write({"stage_id": self.stage_done.id})
Expand Down Expand Up @@ -173,6 +183,7 @@ def test_project_task_process_done(self):
def test_project_task_process_done_basic_user(self):
self.test_project_task_process_done()

@mute_logger("odoo.models.unlink")
def test_project_task_process_cancel(self):
self.task = self.env["project.task"].browse(self.task.id)
self.assertEqual(self.move_product_a.state, "draft")
Expand Down Expand Up @@ -212,6 +223,7 @@ def test_project_task_process_cancel(self):
def test_project_task_process_cancel_manager_user(self):
self.test_project_task_process_cancel()

@mute_logger("odoo.models.unlink")
def test_project_task_process_unreserve(self):
self.task = self.env["project.task"].browse(self.task.id)
self.assertEqual(self.move_product_a.state, "draft")
Expand All @@ -233,6 +245,7 @@ def test_project_task_process_unreserve(self):
self.assertEqual(self.move_product_b.reserved_availability, 0)
self.assertFalse(self.task.unreserve_visible)

@mute_logger("odoo.models.unlink")
def test_project_task_process_01(self):
"""Product A move cancel + Product B move OK."""
self.task = self.env["project.task"].browse(self.task.id)
Expand Down Expand Up @@ -290,13 +303,15 @@ def test_project_task_action_done(self):
def test_project_task_action_done_basic_user(self):
self.test_project_task_action_done()

@mute_logger("odoo.models.unlink")
def test_project_task_unlink(self):
self.assertTrue(self.env["project.task"].browse(self.task.id).unlink())

@users("basic-user")
def test_project_task_unlink_basic_user(self):
self.test_project_task_unlink()

@mute_logger("odoo.models.unlink")
def test_project_project_onchange(self):
new_type = self.env.ref("stock.picking_type_out")
self.project.write({"picking_type_id": new_type.id})
Expand Down
13 changes: 10 additions & 3 deletions project_stock/views/project_task_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,45 +40,51 @@
/>
<field name="stock_analytic_date" />
</field>
<field name="stage_id" position="before" groups="stock.group_stock_user">
<field name="stage_id" position="before">
<button
name="action_confirm"
string="Confirm materials"
type="object"
class="oe_highlight"
attrs="{'invisible':[('allow_moves_action_confirm','=',False)]}"
groups="stock.group_stock_user"
/>
<button
name="action_assign"
string="Check availability materials"
type="object"
class="oe_highlight"
attrs="{'invisible':[('allow_moves_action_assign','=',False)]}"
groups="stock.group_stock_user"
/>
<button
name="button_scrap"
type="object"
string="Scrap"
attrs="{'invisible': ['|','|',('stock_state', '=', 'done'),('done_stock_moves', '=', False),('stock_moves_is_locked','=',False)]}"
groups="stock.group_stock_user"
/>
<button
name="button_unreserve"
type="object"
string="Unreserve"
attrs="{'invisible': ['|','|','|', ('stock_state', '=', 'cancel'),('unreserve_visible', '=', False),('done_stock_moves', '=', False),('stock_moves_is_locked','=',False)]}"
groups="stock.group_stock_user"
/>
<button
name="action_cancel"
type="object"
string="Cancel Materials"
attrs="{'invisible': ['|','|',('stock_state', 'in', ('draft', 'cancel')),('done_stock_moves', '=', False),('stock_moves_is_locked','=',False)]}"
groups="stock.group_stock_user"
/>
<button
name="action_done"
type="object"
string="Transfer Materials"
attrs="{'invisible': ['|','|',('stock_state', '!=', 'assigned'),('done_stock_moves', '=', False),('stock_moves_is_locked', '=', False)]}"
class="oe_highlight"
groups="stock.group_stock_user"
/>
<button
name="action_toggle_stock_moves_is_locked"
Expand All @@ -97,12 +103,14 @@
/>
</field>
<xpath expr="///page[@name='extra_info']" position="before">
<!-- Field without groups used as domain in stock_analytic_* fields !-->
<field name="use_stock_moves" invisible="1" />
pedrobaeza marked this conversation as resolved.
Show resolved Hide resolved
<page
name="stock_info"
string="Stock Info"
attrs="{'invisible': [('use_stock_moves', '=', False)]}"
groups="stock.group_stock_user"
>
<field name="use_stock_moves" invisible="1" />
<field name="done_stock_moves" invisible="1" />
<field name="stock_moves_is_locked" invisible="1" />
<field name="stock_state" invisible="1" />
Expand All @@ -113,7 +121,6 @@
name="move_ids"
context="{'tree_view_ref': 'project_stock.view_stock_move_raw_tree', 'form_view_ref':'stock.view_move_form', 'default_company_id': company_id, 'default_state': 'draft', 'default_raw_material_task_id': id}"
attrs="{'readonly': [('done_stock_moves', '=', True),('stock_moves_is_locked', '=', True)]}"
groups="stock.group_stock_user"
pedrobaeza marked this conversation as resolved.
Show resolved Hide resolved
/>
</page>
</xpath>
Expand Down
Loading