Skip to Content
Menu
This question has been flagged
10 Replies
39606 Views

How to show the cancel/save buttons on a popup form?

Avatar
Discard
Best Answer

A bit of warning here. A button in a form WILL call python write() on the model, unless there are no writable fields in the view. So having the button specifically call write will have it call the write() method twice. Any button that is not special="cancel" will call the write() method, and this is by design.

Since the button will already call write, the button should define another method it will call afterwards but ONLY if the write() method returns True (on success). So add something like this on the view XML:

<footer>
<button name="write_success" type="object" string="Save"/> or <button string="Cancel" special="cancel"/>
</footer>

and define your method like this in the model:

@api.multi
def write_success(self):
    #do stuff, like return an action
#executed only if write() returned True (successful save)


Avatar
Discard
Best Answer

Add this te the xml form :

<footer> <button name="write" type="object" string="Save"/> or <button name="cancel" string="Cancel" special="cancel" class="oe_link"/> </footer>
Avatar
Discard

is the "write" function available in all py files???

Yes and you can redefine it by ( def write ....)

Best Answer

Hello All,

When I add the 'flags': {'form': {'action_buttons': True}} to the return values I do get the Save and Cancel buttons but the Cancel button does nothing and the Save button saves but does not close the popup window.Is there anyway to add some more values / attributes to the return list so that the popup would act just like the "Create and Edit..." of a M2M field?

Thanks,

Fernando

Avatar
Discard
Best Answer

after target:'new'

add these

'flags': {'form': {'action_buttons': True}}

Avatar
Discard

and tree view?

Best Answer

I am new to Openerp and also faced the same problem you are facing.

I did some Research on this and came up with the solution in view.js file under web module:

at line  384, after "

 action.flags = _.defaults(action.flags || {}, {

            views_switcher : !popup && !inline,
            search_view : !popup && !inline,
            action_buttons : !popup && !inline,
            sidebar : !popup && !inline,
            pager : (!popup || !form) && !inline,
            display_title : !popup,
            search_disable_custom_filters: action.context && action.context.search_disable_custom_filters
        });"

ADD this line: 

"if (popup){
            action.flags.action_buttons = true;
        }"

This will show "save" and "Discard" buttons on 'target:new'.

Hope this will help you.

Avatar
Discard
Best Answer

Hi everyone

I git similar problem but a little much complicated:

I have three buttons in my popup:

    <button name="subscribe" type="object"
    string="Subscribe" class="oe_highlight"/>
    or
    <button name="subscribe_and_get_labels" type="object"
    string="Subscribe and get labels" class="oe_highlight"/>
    or
    <button special="cancel" string="Cancel"/>


"Subscribe"  - just save the data according to form, and close the window

"Subscribe and get labels" - save the data (as subscribe), return pdf report, and do not close window ! (That is the problem.)

"Close" - close the window.


"Subscribe and get labels" button return pdf by returning:

    {'type': 'ir.actions.act_url',
    'url': '/web/binary/saveas?model=ir.attachment&field=datas&filename_field=name&id=' + str(file.id),
    'target': 'new',
    }

but I would like it additionally to close the popup window.



Avatar
Discard
Best Answer

When you open a record in modify state, all the popup has got cancel/save button

Avatar
Discard
Author

i am passing form from py file. i want to see save button in pop up buts its not showing my code is return { 'type': 'ir.actions.act_window', 'name': 'Form heading', 'view_mode': 'form', 'view_type': 'form', # 'view_id': view_id, 'res_model': 'calldata1', 'nodestroy': True, #'res_id': this.id, # assuming the many2one

'target':'new',

          'context': context,
}