Skip to Content
Menu
This question has been flagged

I am using Odoo 16 enterprise edition. I have added a custom module called x_waybill in odoo 16. I have a form there, i need to duplicate the form with same value except barcode field(x_studio_barcode) and the state of the form should go to draft state. 

Please help me to achieve this using server action?


Many thanks in advance.


Avatar
Discard
Best Answer

Hi Abdul Razak,


To achieve this in Odoo 16 Enterprise Edition using a server action, you can follow these steps:


    Create a Server Action:

        Go to Settings > Technical > Automation > Server Actions.

        Create a new server action.

        Set the action's name, model, and conditions if necessary.


    Define Python Code:

        In the server action, add a Python code block to duplicate the record and update the necessary fields.

        You can use the copy method to duplicate the record.

        Update the barcode field to the desired value.

        Update the state of the duplicated record to "draft".


    Set Action To Run On Form:

        Optionally, you can set this server action to run when a form is triggered, like after clicking a button.


Here's a sample Python code you can use in the server action:


# Assume the model name is 'x_waybill'

# Find the record to duplicate

original_record = env['x_waybill'].browse(record_id)


# Duplicate the record

duplicated_record = original_record.copy()


# Update the barcode field to a new value (if needed)

# For example:

# duplicated_record.x_studio_barcode = 'new_barcode_value'


# Update the state to 'draft'

duplicated_record.write({'state': 'draft'})


Make sure to replace x_waybill with the actual model name, and adjust the field names and values accordingly.


    Trigger Server Action:

        If you want to trigger this action manually, you can create a button in the form view and link it to this server action.


By following these steps, you'll be able to create a server action that duplicates a record in your custom module with specific modifications as required.


Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
1
Sep 23
2181
1
Apr 24
2416
1
Feb 24
1864
0
Jan 24
1241
0
Oct 23
1965