Skip to content
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
5 changes: 4 additions & 1 deletion project_stock/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ def action_toggle_stock_moves_is_locked(self):
return True

def action_done(self):
for move in self.mapped("move_ids"):
# Filter valid stock moves (avoiding those done and cancelled).
for move in self.mapped("move_ids").filtered(
lambda x: x.state not in ("done", "cancel")
):
move.quantity_done = move.reserved_availability
self.mapped("move_ids")._action_done()
# Use sudo to avoid error for users with no access to analytic
Expand Down
25 changes: 10 additions & 15 deletions project_stock/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ class TestProjectStockBase(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
cls.product_a = cls.env["product.product"].create(
{"name": "Test product A", "detailed_type": "product", "standard_price": 10}
)
Expand Down Expand Up @@ -47,36 +57,21 @@ 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"
ctx = {
"mail_create_nolog": True,
"mail_create_nosubscribe": True,
"mail_notrack": True,
"no_reset_password": True,
}
new_test_user(
cls.env,
login="basic-user",
groups="project.group_project_user,%s" % group_stock_user,
context=ctx,
)
new_test_user(
cls.env,
login="manager-user",
groups="project.group_project_manager,%s,analytic.group_analytic_accounting"
% group_stock_user,
context=ctx,
)
ctx = {
"mail_create_nolog": True,
"mail_create_nosubscribe": True,
"mail_notrack": True,
"no_reset_password": True,
}
new_test_user(
cls.env,
login="project-task-user",
groups="project.group_project_user,stock.group_stock_user",
context=ctx,
)

def _prepare_context_task(self):
Expand Down
27 changes: 26 additions & 1 deletion project_stock/tests/test_project_stock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Tecnativa - Víctor Martínez
# Copyright 2022-2023 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
Expand Down Expand Up @@ -235,6 +235,31 @@ def test_project_task_process_unreserve(self):
self.assertEqual(self.move_product_b.reserved_availability, 0)
self.assertFalse(self.task.unreserve_visible)

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)
self.move_product_b.unlink()
self.assertEqual(self.move_product_a.state, "draft")
# Confirm + Edit to qty=0
self.task.action_confirm()
self.assertEqual(self.move_product_a.state, "assigned")
self.move_product_a.product_uom_qty = 0
self.task.action_done()
self.assertEqual(self.move_product_a.state, "cancel")
# Add extra line
task_form = Form(self.task)
with task_form.move_ids.new() as move_form:
move_form.product_id = self.product_b
move_form.product_uom_qty = 1
task_form.save()
self.move_product_b = self.task.move_ids.filtered(
lambda x: x.product_id == self.product_b
)
self.task.action_confirm()
self.assertEqual(self.move_product_b.state, "assigned")
self.task.action_done()
self.assertEqual(self.move_product_b.state, "done")

@users("basic-user")
def test_project_task_process_unreserve_basic_user(self):
self.test_project_task_process_unreserve()
Expand Down