Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
2416 Weergaven

Can anyone please tell how can I create records in timesheet using external api. I want control odoo system by external api. I can't find proper documentation for external api. Please try to help me if someone know about this.

Avatar
Annuleer
Beste antwoord

Hi,


You can create records in any Odoo model using the JSON-RPC API. This method allows you to call any function on any model programmatically.

Basic Structure


The general structure for creating records is:


json


{


  "jsonrpc": "2.0",


  "method": "call",


  "id": 3,


  "params": {


    "service": "object",


    "method": "execute_kw",


    "args": [


      "database_name",    // Your Odoo database name


      user_id,            // User ID (integer)


      "password",         // User password or API key


      "model.name",       // Technical name of the model


      "create",           // Method to execute


      [


        [


          {


            "field1": "value1",


            "field2": "value2",


            // ... more fields


          },


          // ... more records


        ]


      ]


    ]


  }


}

Example: Creating Timesheet Records


Here's a practical example showing how to create multiple timesheet entries:


json


{


  "jsonrpc": "2.0",


  "method": "call",


  "id": 3,


  "params": {


    "service": "object",


    "method": "execute_kw",


    "args": [


      "fresh_test",             // Database name


      2,                        // User ID


      "1",                      // Password


      "account.analytic.line",  // Timesheet model


      "create",                 // Create method


      [


        [


          {


            "name": "Development Task",


            "project_id": 1,


            "task_id": 1,


            "employee_id": 1,


            "unit_amount": 8.0,


            "date": "2024-05-27"


          },


          {


            "name": "Testing and QA",


            "project_id": 1,


            "task_id": 2,


            "employee_id": 1,


            "unit_amount": 4.0,


            "date": "2024-05-27"


          },


          {


            "name": "Code Review",


            "project_id": 2,


            "task_id": 3,


            "employee_id": 2,


            "unit_amount": 2.0,


            "date": "2024-05-27"


          },


          {


            "name": "Documentation",


            "project_id": 2,


            "task_id": 4,


            "employee_id": 2,


            "unit_amount": 3.0,


            "date": "2024-05-27"


          },


          {


            "name": "Client Meeting",


            "project_id": 1,


            "employee_id": 1,


            "unit_amount": 1.5,


            "date": "2024-05-27"


          }


        ]


      ]


    ]


  }


}


Hope it helps

Avatar
Annuleer
Beste antwoord

To Control odoo system the XML-RPC api,which is the officially supported way to control odoo from outside
Here its documentation link 
-> https://www.odoo.com/documentation/16.0/developer/misc/api/odoo.html
 i hope it is use full

Avatar
Annuleer