An interesting use of Server Actions to copy (and delete) multiple records. This is another one from Jake Robinson
Start by enabling Developer mode and navigating to Settings / Technical / Server Actions:
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
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!