Se rendre au contenu

Json Library in Server Action

Allow JSON in code to create Server Action
42,96 € 42,96 € (Hors taxes)
US$ 50,00 (Hors taxes)

  • Versions
Conditions générales
Garantie satisfait ou remboursé de 30 jours
Livraison : 2-3 jours ouvrables


ODOO'S FUNCTION

In Odoo, developers can use Server Actions to create automated actions for all modules through code execution. For example, in the standard Odoo process (Quotation -> Sales Order -> Project and Task), the project and task are created automatically at the quotation confirmation.

CLUEDOO'S FUNCTION

CLuedoo extends this Server Action functionality by allowing the use of JSON in the code. This helps developers easily use JSON in their coding, leading to a more convenient development process. It is highly recommended to install this template on 100% of your databases.

CONFIGURATION


1. Setup Action & Code Editor
  • Go to Settings > Technical > Server Actions and click New.
  • Set up:

    • Action Name: Set an explicit name (e.g., test 1).
    • Model: Choose your target model (e.g., Purchase Order).
    • Type: Click on the Execute Code button from the horizontal options list to reveal the code text box below

2. Insert Python Code & Data

  • Paste your Python script into the Code tab. Define a raw_data variable using triple quotes (''' ... ''') and paste your JSON data inside. Use the built-in json.loads() to parse it.

  • Click the Create Contextual Action button on the top-left corner. This binds the Server Action as an option inside the target model's interface

  • Example code:

raw_data = '''
{
  "order_id": "SO0019",
  "total_amount": 1500,
  "status": "done"
}
'''
parsed_data = json.loads(raw_data)
log(f"V19 TEST - Order {parsed_data['order_id']} split successfully with amount {parsed_data['total_amount']}", level='info')

USAGE


1. Trigger the Action

  • Go to the Purchase app and open any random Purchase Order record.

  • Click the Actions (Gear icon) menu at the top of the record and select your newly created action name (e.g., test 1).

2. Verify the System Log

  • Go to Settings > Technical > Database Structure > Logging.

  • If successful, you will see a new line generated in the system log displaying the parsed JSON values matching your execution.


STORY BEHIND THE FEATURES

ODOO BEHAVIOUR

In Odoo, you can create Server Actions in order to create actions for all modules through code execution. 

Odoo Standard process is Quotation -> Sales Order -> Project and Task.

So, the project and task are created automatically at the quotation confirmation.


CLUEDOO BEHAVIOUR

Cluedoo extends this function by allowing the use of JSON in code.


MODULE +

This module helps developers to use JSON in their code, leading to a more convenient development module.

CLUEDOO RECOMMENDATION

Install this template on 100% of your databases.

HOW TO USE THE MODULE

Step 1. Go to Settings > Technical > Server Actions > New

Step 2. 

  • Choose type: Execute code, Model...
  • Copy this code:

Step 3.  Go to a random project  > e-commerce integration > External Order Data > Choose a random "record" > Raw data
Step 4. Copy and paste to raw data in Server Action
Step 5. Run server action. Go to Settings > Technical > Database Structure > Logging. If successful, you will see a line like the one shown beside