top of page
Search
Chris Tringham

Server Actions to copy (and delete)

Updated: Nov 25, 2019

There's a newer version of this post here: https://odootricks.tips/server-actions-copy-delete/

 

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

This is another one from Jake Robinson


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

for rec in records:

rec.copy()

record['state'] = "cancel"

rec.unlink()


You need to enter:

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

2. Action To Do = "Execute Python Code"

3. Then enter the Python code as shown above.

4. 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).

5. Finally, 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()


You may have noticed that Server Actions and Automated Actions are very similar. Actually, all Automated Actions are shown in the Server Actions and you can create a contextual action for them!

116 views0 comments

Recent Posts

See All

Automated Action to create a BOM

There's a newer version of this post here: https://odootricks.tips/about/automated-action-to-create-a-bom/ This is a great example of the...

コメント


bottom of page