跳至内容
菜单
此问题已终结

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.


形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
1
9月 23
2196
1
4月 24
2470
1
2月 24
1878
0
1月 24
1246
0
10月 23
1984