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

Hello, dears i want to make records to be unique and I did it  by SQL constraints and it's worked well, and prevented me to make any duplication, 


now I need to make a more advanced method, that will check the name while creating the record and search overall records so if I found it, should return an action with form view of the original record id 


and here is what I had done.


    testt = fields.Text(string="", compute='open_duplicates', required=False, )
    @api.depends('name','id_num')
    def open_duplicates(self):
        duplicated = self.env['muk_dms.directory'].search([('name','=', self.name)])
        if duplicated:
            print('inn')
            return {
                'view_type': 'form',
                'view_mode': 'form',
                'res_model': 'muk_dms. directory',
                'target': 'current',
                'res_id': duplicated.id,
                'type': 'ir.actions.act_window',
            }
        else:
            pass

now if I ityped a name which already exit the method runs and print the 'inn' but it is'nt return the action 


so how can I do that ??


any help will be appreciated !!

아바타
취소
베스트 답변

From the compute method you cannot return action because it's not supported by Odoo framework. You need to change your logic to meet your requirement.

You can make name field unique (sql constraint / custom constraint) so that user cannot enter duplicate value.

아바타
취소
작성자

i'am already doesn't have any duplicated value and SQL constraints prevent that from happening, actually, I need to go to the form of duplicated record instead of raise error that the value is already exist

Another alternate of this is to open such records from button click. But it will create the record after button click.

작성자

yes this an error , if i make method that return True then another button appears, if i press on this button it saves the record before going to the new form

관련 게시물 답글 화면 활동
0
11월 23
1419
2
3월 23
2397
0
3월 15
5913
2
7월 22
6903
1
12월 21
5889