Skip to Content
Menu
This question has been flagged
1 Reply
2860 Views

Hello,

In the form view of a quotation/so, there is an option Duplicate in action menu.

Is anybody knows where is the code of this option in Odoo to override it?


Vincent

Avatar
Discard
Best Answer

Hi,

You can override copy method of the sale order model and you need to call the super method. Copy method duplicates the record depend on the copy attribute which mentioned in the field definition, if the copy attribute is missing then the default value is false.

  • copy (bool) – whether the field value should be copied when the record is duplicated (default: True for normal fields, False for one2many and computed fields, including property fields and related fields) 

In Odoo 14, there is an override for copy method on sale order to pass default value for validity_date depend on conditions:

https://github.com/odoo/odoo/blob/14.0/addons/sale_management/models/sale_order.py#L45


Update: 07-10-2021

The portal user will not have access to create sale order and you will do it using sudo(). If you able to get the sale order active record you will define a method and call it from the button and use copy method directly as below:
record.sudo().copy() and you can pass default values to copy method as dictionary

Here you are the copy method in documentation:
https://www.odoo.com/documentation/13.0/developer/reference/addons/orm.html#odoo.models.Model.copy


Avatar
Discard
Author

Hi CorTex,
Thank you for your answer.

I forgot to indicate that i'm on version 13 of Odoo

I already tried to search copy method in sale order model but i only found copy_data() !?!

In fact, i try to duplicate a quotation/so from the user portal
For that i added a "Duplicate" button under the buttons "Download" and "Print"
And i'm looking for how to do the same thing that the duplicate option in the action menu of SO form view

The portal user will not have access to create sale order and you will do it using sudo(). If you able to get the sale order active record you will define a method and call it from the button and use copy method directly as below:
record.sudo().copy() and you can pass default values to copy method as dictionary

Here you are the copy method in documentation:
https://www.odoo.com/documentation/13.0/developer/reference/addons/orm.html#odoo.models.Model.copy

Author

It works Cortex
Thank you for your help
Vincent

Sound good.. I have updated the answer