コンテンツへスキップ
メニュー
この質問にフラグが付けられました

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
2193
1
4月 24
2468
1
2月 24
1877
0
1月 24
1246
0
10月 23
1983