Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2502 มุมมอง

In my case, I need to allow the users to duplicate so, they can prevent typing the City, Province, Country, and Other extra information. But I have to restrict saving the same lead name twice.

I already used Automated Actions to prevent duplication but it's not letting to duplicate leads.


The code I used in Automated Action is:

existing_name = env['crm.lead'].search([('id', '!=', record.id), ('name', '=', record.name)])
if existing_name:
         raise UserError(record.name + ' already exists!')


Is there are any ways to allow the duplication but while saving it has to show a different name or else the warning message has to pop up.


Thanks in advance.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

You can do this way


@api.constrains('name')
def _check_something(self):
existing_name = self.env['crm.lead'].search([('id', '!=', self.id), ('name', '=', self.name)])
if existing_name:
raise UserError("%s already exists!" % self.name)

อวตาร
ละทิ้ง
ผู้เขียน

Thanks for the code, Could you please explain to me where can I use this code?

I am using Odoo cloud not Odoo SH or on-premise.

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ย. 21
2166
2
พ.ย. 24
3174
1
พ.ค. 24
3374
Blank Page After Logged in. แก้ไขแล้ว
1
พ.ย. 23
3405
0
ต.ค. 23
1563