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