Odoo Integration - Create Draft Invoice with line items

Describe the problem/error/question

We are trying to - with n8n - create a draft invoice in odoo that has some line items on the invoice. What we achieved so far is:

  • Read some customer data from a database and based upon that information create a draft invoice for that customer (empty) → Success

Now - as soon as I want to add some line items (meaning: e.g. a Product that i want to invoice or any other “line” for that matter) I get the following error:


NodeApiError: Wrong value for account.move.invoice_line_ids: [(0, 0, {

    'product_id': 11,

    'quantity': 1,

    'price_unit': 100.00,

    'account_id':1,

})]

at Object.odooCreate (/usr/lib/node_modules/n8n/node_modules/n8n-nodes-base/nodes/Odoo/GenericFunctions.ts:204:9)

at processTicksAndRejections (node:internal/process/task_queues:95:5)

at Object.execute (/usr/lib/node_modules/n8n/node_modules/n8n-nodes-base/nodes/Odoo/Odoo.node.ts:448:22)

at Workflow.runNode (/usr/lib/node_modules/n8n/node_modules/n8n-workflow/src/Workflow.ts:1335:8)

at /usr/lib/node_modules/n8n/node_modules/n8n-core/src/WorkflowExecute.ts:1045:29

Please share your workflow

The complete workflow looks like this.

{
“meta”: {
“instanceId”: “fa5408989f5e3242812deda8b482116c7c6002a68286b40addea6948e8de5dd6”
},
“nodes”: [
{
“parameters”: {},
“id”: “25076687-2d1f-4d98-8448-f1d8fc494eb1”,
“name”: “When clicking "Execute Workflow"”,
“type”: “n8n-nodes-base.manualTrigger”,
“typeVersion”: 1,
“position”: [
-180,
-20
]
},
{
“parameters”: {
“resource”: “custom”,
“customResource”: “account.move”,
“fieldsToCreateOrUpdate”: {
“fields”: [
{
“fieldName”: “partner_id”,
“fieldValue”: “={{ $json.erp_knr }}”
},
{
“fieldName”: “invoice_date”,
“fieldValue”: “2023-12-25”
},
{
“fieldName”: “move_type”,
“fieldValue”: “out_invoice”
},
{
“fieldName”: “invoice_line_ids”,
“fieldValue”: “[(0, 0, {\n ‘product_id’: 11,\n ‘quantity’: 1,\n ‘price_unit’: 100.00,\n ‘account_id’:1,\n })]”
}
]
}
},
“id”: “87f4407d-642e-4104-9bb1-075a99681bc2”,
“name”: “Create Invoice Draft”,
“type”: “n8n-nodes-base.odoo”,
“typeVersion”: 1,
“position”: [
380,
-80
],
“credentials”: {
“odooApi”: {
“id”: “XXX”,
“name”: “XXX”
}
}
},
{
“parameters”: {
“operation”: “select”,
“schema”: {
“__rl”: true,
“mode”: “list”,
“value”: “public”
},
“table”: {
“__rl”: true,
“value”: “v_ticket_time_accounting_invoice”,
“mode”: “list”,
“cachedResultName”: “v_ticket_time_accounting_invoice”
},
“returnAll”: true,
“options”: {}
},
“id”: “0bf76e43-6918-4639-8188-50e2ca80047d”,
“name”: “Get_Invoiced_Data-TimeAccounting”,
“type”: “n8n-nodes-base.postgres”,
“typeVersion”: 2.3,
“position”: [
60,
200
],
“credentials”: {
“postgres”: {
“id”: “mtOCshBNp5ZuYKHd”,
“name”: “TEC-DB-01 - invoicing”
}
}
},
{
“parameters”: {
“operation”: “executeQuery”,
“query”: “SELECT \n public.v_ticket_time_accounting_invoice.erp_knr, \n public.v_ticket_time_accounting_invoice.display_name, \n public.v_ticket_time_accounting_invoice.year, \n public.v_ticket_time_accounting_invoice.month \nFROM \n public.v_ticket_time_accounting_invoice\nGROUP BY\n public.v_ticket_time_accounting_invoice.erp_knr, \n public.v_ticket_time_accounting_invoice.display_name, \n public.v_ticket_time_accounting_invoice.year, \n public.v_ticket_time_accounting_invoice.month;”,
“options”: {}
},
“id”: “605fbe67-2f17-4e09-8b87-f31e892935d8”,
“name”: “Get Invoice Basic Data”,
“type”: “n8n-nodes-base.postgres”,
“typeVersion”: 2.3,
“position”: [
60,
-20
],
“credentials”: {
“postgres”: {
“id”: “mtOCshBNp5ZuYKHd”,
“name”: “TEC-DB-01 - invoicing”
}
}
},
{
“parameters”: {
“resource”: “custom”,
“customResource”: “account.move”,
“operation”: “delete”,
“customResourceId”: “={{ $
json.id
}}”
},
“id”: “10880ef9-b8b3-4881-b25e-b4d6d4b4a903”,
“name”: “Odoo”,
“type”: “n8n-nodes-base.odoo”,
“typeVersion”: 1,
“position”: [
740,
-80
],
“credentials”: {
“odooApi”: {
“id”: “FWJDWHfcEdcmXavI”,
“name”: “TECXERO-EU-ERP”
}
},
“disabled”: true
}
],
“connections”: {
“When clicking "Execute Workflow"”: {
“main”: [
[
{
“node”: “Get Invoice Basic Data”,
“type”: “main”,
“index”: 0
},
{
“node”: “Get_Invoiced_Data-TimeAccounting”,
“type”: “main”,
“index”: 0
}
]
]
},
“Create Invoice Draft”: {
“main”: [
[
{
“node”: “Odoo”,
“type”: “main”,
“index”: 0
}
]
]
},
“Get Invoice Basic Data”: {
“main”: [
[
{
“node”: “Create Invoice Draft”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“pinData”: {}
}

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • **n8n version: 1.20.0
  • **Database (default: SQLite): PostgreSQL
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • **Running n8n via (Docker, npm, n8n cloud, desktop app): LCX-Container
  • **Operating system: Linux

My guess would be that we are not providing the correct format, amount, … of parameters in the account.move.invoice_line_ids, but i can not find any helpful comment on how to correctly put it into n8n to get it going.

Any support / ideas – much appreciated!
Best regards, Martin

My guess would be that we are not providing the correct format, amount, … of parameters in the account.move.invoice_line_ids, but i can not find any helpful comment on how to correctly put it into n8n to get it going.

Hi @Martin, I suspect you’re right. Unfortunately I am not familiar with Odoo, but my guess is that Odoo might expect an array rather than a string. So perhaps you want to wrap your value in {{ and }} to mark your input as JS? n8n will recognise this as a valid array. You can verify this in the preview:

image

1 Like

Hi @Martin , did you solve this? I’m also trying to automate this, but I’m also stuck when trying to add invoice lines.

Help would be very much appreciated!
Cadish

This is what I get as error:

Anyone who knows and can help? :pray: :pray: