This question has been flagged
2 Replies
19876 Views

Hi, I have a form view in Openerp and i have a button which redirect to another form. I want wehn clicked to the button, amany2one field to be filled by the id of the current object. Thanks for your help

Avatar
Discard
Best Answer

If you want automatically to fill the many2one field then create a button of type object and in the function ctx.update({ 'default_model':'your.model', 'default_many2one_field': ids[0], }) return { 'type': 'ir.actions.act_window', 'view_type': 'form', 'view_mode': 'form', 'res_model': 'mail.compose.message', 'views': [(compose_form_id, 'form')], 'view_id': compose_form_id, 'target': 'new', 'context': ctx, }

In this mehod you should update the context with the default value for your many2one field and pass it in the return method of your function, this will redirect to the view which you specify and load with the value for many2one which you have passed.

for furthur reference check for "action_quotation_send" in sale.py file

Avatar
Discard
Author

Thanks a lot it works.

Best Answer

do a function like this

    obj_model = self.pool.get('ir.model.data')
    model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','account_automatic_reconcile_view1')])
    resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'])[0]['res_id']
    return {
                    'name': 'Customer Invoices',
                    'view_type': 'form',
                    'view_mode': 'form',
                    'view_id': [res_id],
                    'res_model': 'account.invoice',
                    'context': "{'type': 'out_invoice'}",
                    'type': 'ir.actions.act_window',
                    'nodestroy': True,
                    'target': 'current',
                    'res_id': inv_id or False,
                   }
Avatar
Discard

will you please explain what is the use of 'nodestroy'

I am getting the following error in V13:

werkzeug.exceptions.BadRequest: 400 Bad Request: <function Home.web_client at 0x7f2fd2bfc950>, /web: Function declared as capable of handling request of type 'http' but called with a request of type 'json'

Can you help me with this please?

My function is the following:

def open_child(self):

return {

'type': 'ir.actions.act_window',

'res_model': self._child_model,

'res_id': self._child_id,

'view_mode': 'form',

'views': [(False,'form')],

'target': 'current',

}

I fixed the problem, my _child fields were not set correctly.

In case anyone still wonders, the use of 'nodestroy' is so that a popup like a wizard doesn't close automatically after clicking on save (you have to close it with the 'X'). I'm not sure if it is useful with 'target': 'current'