İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
6084 Görünümler

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 !!

Avatar
Vazgeç
En İyi Yanıt

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.

Avatar
Vazgeç
Üretici

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.

Üretici

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

İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Kas 23
1423
2
Mar 23
2403
0
Mar 15
5920
2
Tem 22
6911
1
Ara 21
5895