Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
4052 Zobrazení

Hi, everyone I'm trying to make a search wizard which will find records in res.partner based on our given condition. For example, I'm giving a value in CNIC field to search if the record exists on a button click it works correctly and find the existing record (if any) but it does not return the form of existing record it opens the new form always. Can anyone help me to return an existing form with all the values? 

Here's my function:

def existing_record(self):
search = []
if self.cnic:
search.append(('cnic', '=', self.cnic))
else:
raise ValidationError(_("Please Enter CNIC."))

if search:
partner = self.env['res.partner'].search(search)
if not partner:
raise ValidationError(_("This member is not yet created. So, you can not see his details."))

return {
'name': 'Member Form',
'view_mode': 'form',
'res_model': 'res.partner',
'view_id': self.env.ref('real_estate.view_partner_form').id,
'domain': [('cnic','=',self.cnic)],
'context': {
"default_is_member": True,
},
'type': 'ir.actions.act_window',
Avatar
Zrušit
Nejlepší odpověď

Hello Syed,

I believe the issue is that you haven't given the window action a "res_id". This value specifies what record needs to be loaded into the view. Source

The answer which Aktiv Software has provided suggests that you have forgotten to place an ending curly brace at the end of your window action, while not wrong I don't believe this to be your issue. As this would usually bring up a server error, I would imagine you just didn't copy the end into your example. 

If you change the window action to:

return {
'name': 'Member Form',
'view_mode': 'tree,form',
'res_model': 'res.partner',
'res_id': partner.id,
'view_id': self.env.ref('real_estate.view_partner_form').id,
'domain': [('id','in', partner.ids)],
'context': {
"default_is_member": True,
},
'type': 'ir.actions.act_window'
}
It should work, however, you would need to have a check before, such as:

if partner:
    # place window action
else:
    # do something if you haven't found a partner
To make sure the partner exists. 

I hope this helps,

Thanks, 

Avatar
Zrušit
Autor

thanks man it helped.

Nejlepší odpověď

Hello Syed Hamza,

please try for this domain

return {

'name': 'Member Form',

'view_mode': 'tree,form',

'res_model': 'res.partner',

'view_id': self.env.ref('real_estate.view_partner_form').id,

'domain': [('id','in', partner.ids)],

'context': {

"default_is_member": True,

},

'type': 'ir.actions.act_window'

}

Thank you!

Regards,




Email:      odoo@aktivsoftware.com  

Skype: kalpeshmaheshwari

    

Avatar
Zrušit
Autor

thanks for your response but the issue was coming bcz i was missing 'res_id'

Related Posts Odpovědi Zobrazení Aktivita
1
dub 21
2613
0
dub 17
4349
2
pro 19
15339
0
dub 16
5006
0
bře 15
5563