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_sequence: Force generate sequence_code when creating project from list view #1303

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
2 changes: 1 addition & 1 deletion project_sequence/models/project_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def create(self, vals_list):
# It is important to set sequence_code before calling super() because
# other modules such as hr_timesheet expect the name to always have a value
for vals in vals_list:
if "sequence_code" not in vals:
if not vals.get("sequence_code", False):
vals["sequence_code"] = self.env["ir.sequence"].next_by_code(
"project.sequence"
)
Expand Down
25 changes: 22 additions & 3 deletions project_sequence/tests/test_project_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,35 @@ def test_sequence_unique(self):
@users("manager")
def test_project_without_sequence(self):
"""Preexisting projects had no sequence, and they should display fine."""
proj1 = self.env["project.project"].create(
{"name": "one", "sequence_code": False}
proj1 = self.env["project.project"].search(
joscanog marked this conversation as resolved.
Show resolved Hide resolved
[
("sequence_code", "=", False),
],
limit=1,
)
self.assertEqual(proj1.display_name, "one")
proj1.name = "one"
self.assertFalse(proj1.sequence_code)
self.assertEqual(proj1.display_name, "one")
# Make sure that the sequence is not increased
proj2 = self.env["project.project"].create({"name": "two"})
self.assertEqual(proj2.sequence_code, "23-00011")
self.assertEqual(proj2.display_name, "23-00011 - two")

@users("manager")
def test_project_with_empty_sequence(self):
"""Sequence is applied when creating project with an empty sequence"""
proj1 = self.env["project.project"].create(
{"name": "whatever", "sequence_code": ""}
)
self.assertEqual(proj1.sequence_code, "23-00011")
self.assertEqual(proj1.display_name, "23-00011 - whatever")
# Sequence is applied when creating project with sequence in False
proj2 = self.env["project.project"].create(
{"name": "whatever", "sequence_code": False}
)
self.assertEqual(proj2.sequence_code, "23-00012")
self.assertEqual(proj2.display_name, "23-00012 - whatever")

def test_custom_pattern(self):
"""Display name pattern can be customized."""
self.env["ir.config_parameter"].set_param(
Expand Down
Loading