Skip to Content
Menu
This question has been flagged
3 Replies
1916 Views

Hello,


i added a new duplicate menu item in the sale.order form wich call an action server with this python code :

if records:
    for rec in records:
        rec.with_context(type_copy='standard_copy').copy()


The copy is done but i stay on the source record form instead to go on the copied record form.

Do you know how to do that (like when we click on the standard duplicate menu item) ? 

Avatar
Discard
Best Answer

To redirect to the copied record form after creating the copy, you can return an action from your action server. Here is an example:

if records:
    for rec in records:
        copied_record = rec.with_context(type_copy='standard_copy').copy()
        return {
            'type': 'ir.actions.act_window',
            'res_model': 'sale.order',
            'res_id': copied_record.id,
            'views': [[False, 'form']],
        }

This will open the form view of the copied record after the copy is created. You can adjust the action to suit your needs. For example, if you want to open the copied record in a new window, you can add 'target': 'new' to the action.

Avatar
Discard
Author

Hello Ashish,

thank you for your answer.
It doesn't work with this syntax but if i modify like this, it works :
action = {
'type': 'ir.actions.act_window',
'res_model': 'sale.order',
'res_id': copied_record.id,
'views': [[False, 'form']],
}

A last thing, it is just a detail but maybe you know why.
For example, i want to duplicate with my standard method, the quotation S100.
On the top, we can see : ""Quotation / S100"
After duplication, i'm on the new record, that's ok now, but on the top, instead to see "Quotation / S101", i've got "Quotation / S100 / S101"
Do you know if there is an option to have only "Quotation / S101" like with the original duplicate method ??

Author Best Answer

Hello Ayoub,

I don't explained why i don't use standard duplicate method because it is not the problem here.

But to explain the purpose here:

My client need 2 duplicate method : The standard one and an other wich name differently the copied record.

That's why i add an new item duplicate wich call an overriden copy method with a context and the standard duplicate menu call the same overriden copy method but without context.

Like the context is different i can do different things before call the super copy method.

All of that works well.

My problem is when i choose standard duplicate menu, i'm on the new record after copy but if i choose the new duplicate menu, i stay on the first record (but the copy is done).

I tried after call super copy to return an action like that but it doesn't works!

return {
'type': 'ir.actions.act_window',
'res_model': 'sale.order',
'res_id': new_so.id,
'view_type': 'form',
'target': 'current',
}

Avatar
Discard

try to add view_mode (is required) + view_id

Like this:

return {
'type': 'ir.actions.act_window',
'res_model': 'sale.order',
'res_id': new_so.id,
'view_type': 'form',
'view_mode': 'form',
'view_id': self.env.ref('sale.view_order_form').id,
'target': 'current',
}

Author

I already tried to add view_mode and view_id but it doesn't work anymore!ee.
I works if i do the same thing but if i call the method with a button in the header but not with an option in action menu!!

Best Answer

No need to do " if records:"

I didn't understand why you don't directly use the standard duplicate action?

if you need customization, just override the copy method in sale.order and add your logic.


You must return the copied record in this case, but if you're dealing with mass duplicates try that from the tree vue.​


Avatar
Discard