Use Server Actions to copy (and delete)

Table of Contents

An interesting use of Server Actions to copy (and delete) multiple records.

Start by enabling Developer mode and navigating to Settings / Technical / Server Actions:

server action to copy and delete production orders

for rec in records:
rec.copy()
record['state'] = "cancel"
rec.unlink()

Note: This uses the standard copy() ORM method, and so (by design) it will not copy all fields.

You need to enter:

1. The model (table) – and this should work with any model

2. Action To Do = “Execute Python Code”

3. Enter the Python code as shown above. The second line sets the state to “cancel” because you can only delete a Production Order that has been cancelled. Different rules apply to different models (tables).

Click on “Create Contextual Action” and now the option is available.

action to copy and delete
Beware: this is very powerful!!
Of course you can simply copy and not delete, in which case your Python code will be:

for rec in records:
   rec.copy()


Tip: you may have noticed that Server Actions and Automated Actions are very similar.
All Automated Actions are shown in the list of Server Actions and from there you can create a contextual action for them!

server action to copy and delete production orders

ABOUT US

We continuously update information pertaining to Digital Solutions, ERP (Enterprise Resource Planning), Data management, Cloud services, Company Culture, Odoo, and more.

Table of Contents

Leave a Reply

Your email address will not be published. Required fields are marked *