Use Server Actions to copy (and delete)

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:
  record['state'] = "cancel"

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:

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!

9 thoughts on “Use Server Actions to copy (and delete)

  1. first of all, excellent blog. Very useful. i am using server action to copy a few selected lines from a customized model (with studio) to one invoice. however, it is not grouping as expected. Can you share some tips for me please?

    for case_line in records:
    ‘x_studio_business_unit’: case_line.x_studio_billing_centre,
    ‘price_unit’: case_line.x_studio_price,
    env [‘account.invoice’].create({


      1. Hi Martynas, I have used the default “invoice order” function to transfer all these extra details from sales module to invoice.


  2. Bonjour ,
    Je trouve votre blog très instructif , j’aimerais savoir si je peut utiliser l ‘action du serveur pour mettre à jour automatiquement un champs date dans mon formulaire selon une fréquence très précise.


    1. Sorry, my French is not so good, but yes it should be possible to have a Server Action to update dates automatically. Can you give an example of what you want to achieve?


  3. Hello,
    Very good article thanks you!!
    Is there a way to do it but with a specific sale order. (a button that can duplicate specific sale order)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s