Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
6141 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Autore

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.

Autore

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

Post correlati Risposte Visualizzazioni Attività
0
nov 23
1435
2
mar 23
2458
0
mar 15
5947
2
lug 22
6971
1
dic 21
5932