-
-
Notifications
You must be signed in to change notification settings - Fork 797
/
Copy pathproject_task.py
44 lines (36 loc) · 1.2 KB
/
project_task.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Copyright 2016 Tecnativa <vicent.cubells@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
class ProjectTask(models.Model):
_inherit = "project.task"
code = fields.Char(
string="Task Number",
required=True,
default="/",
readonly=True,
copy=False,
)
_sql_constraints = [
("project_task_unique_code", "UNIQUE (code)", _("The code must be unique!")),
]
@api.model_create_multi
def create(self, vals_list):
new_list = []
for vals in vals_list:
if vals.get("code", "/") == "/":
new_vals = dict(
vals,
code=self.env["ir.sequence"].next_by_code("project.task") or "/",
)
else:
new_vals = vals
new_list.append(new_vals)
return super().create(new_list)
def name_get(self):
result = super().name_get()
new_result = []
for task in result:
rec = self.browse(task[0])
name = "[{}] {}".format(rec.code, task[1])
new_result.append((rec.id, name))
return new_result