This question has been flagged
1 Reply
4197 Views

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
Discard
Best Answer

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
Discard
Author

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.

Author

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