Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
3561 Lượt xem
I am trying to execute this python code to avoid repeating a task in my odoo and the error is not known

if record.name:
task = env ['project.task'].search([['name', '=', record.name]])

if task:
for e in task:
if e.id != record.id:
raise Warning ('La tarea esta creada')


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
Try this way

if record.name:
task = env ['project.task'].search([('name', '=', record.name),('id','!=',record.id)])    

    if task:
        raise Warning ('La tarea esta creada')


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

It works fine for me. Of course, you need to respect the indentation rules of Python. 

if record.name:
task = env ['project.task'].search([['name', '=', record.name]])

if task:
for e in task:
if e.id != record.id:
raise Warning ('La tarea esta creada')

Hope this helps you. 

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất
it returns this error when I try to run it

ValueError: : "'NoneType' object has no attribute 'name'" while evaluating "if record.name:\n task = env ['project.task'].search([['task.name', '=', record.name]])\n\nif task:\n for e in task:\n if e.id != record.id:\n raise Warning ('La tarea esta creada')"


Ảnh đại diện
Huỷ bỏ

I'm testing it in V13, On Premise. The behavior is:
- Create a task with a name. (e.g. : "x") --> OK
- Create another task with the same name ("x") --> Shows the message "La tarea esta creada" and it doesn't allow saving the record.
Tested from both kamban and list view of tasks.

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 5 21
4450
0
thg 10 24
1158
0
thg 2 24
1813
1
thg 12 22
2253
2
thg 7 22
5538