mirror of
https://github.com/bringout/oca-project.git
synced 2026-04-18 15:22:03 +02:00
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
# 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"
|
|
_rec_names_search = ["name", "code"]
|
|
|
|
code = fields.Char(
|
|
string="Task Number",
|
|
required=True,
|
|
default="/",
|
|
readonly=True,
|
|
copy=False,
|
|
)
|
|
|
|
_sql_constraints = [
|
|
(
|
|
"project_task_unique_code",
|
|
"UNIQUE (company_id, code)",
|
|
_("The code must be unique!"),
|
|
),
|
|
]
|
|
|
|
@api.model_create_multi
|
|
def create(self, vals_list):
|
|
for vals in vals_list:
|
|
if vals.get("code", "/") == "/":
|
|
vals["code"] = (
|
|
self.env["ir.sequence"].next_by_code("project.task") or "/"
|
|
)
|
|
return super().create(vals_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
|