콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
10730 화면

How to Unique constraint a field in custom model on Odoo Enterprise 12.0 Online?

아바타
취소
베스트 답변

Hi Tameem,

I think you are trying to make the Unique field.

Usually, this is handled by SQL Constraints. In your case, you are using Odoo Online. So we must think differently to make it possible.

Anyway

Try this way. Maybe you will get the result you wish.

  1. Create an Automated action with the following parameters.

    • Model: your custom model

    • Trigger Condition: On Update

    • Action To Do: Execute Python Code

    • In the python code, try this code

new_value = record.YourFieldName
existing_records = env['Your.Model'].search([('YourFieldName', '=', new_value)])
if len(existing_records) > 1:
    raise Warning('Field value must be unique')


Thanks

아바타
취소
작성자

Dear Avinash,

Your answer worked perfectly!

Thank you for your reply.

My pleasure

Hello, do you know if we can manage to do the same using Studio ?

베스트 답변

Hello, Avinash's answer works for me too but instead of having the warning I setted I have an Odoo error about the automated action itself. Do you know how to solve this ?

아바타
취소
관련 게시물 답글 화면 활동
1
11월 24
1467
2
1월 24
4752
3
7월 25
649
2
7월 25
3957
2
9월 21
4929