Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
1624 Tampilan

I'm writing a solution for managing my etsy store and am using Odoo online. I can successfully create an invoice via the API using my Make.com instance, however when I try to add the line items to the invoice, I get the error 1 , shown at the bottom of this post.


I'm sure it's a syntax issue, but I'm strugging to figure out what's wrong with it.

My research suggests the issue is the curly braces inside the invoice_line_ids array, however when I remove them, I end up with Error 2.


I'm using Odoo Online with Stuido, so custom code isn't possible.


Is this a language compatibility issue, because I've witten the API call in json?


Invoice Model: account.move

My code.

[
    {
        "partner_id": 14,
        "move_type": "out_invoice",
        "invoice_date": "{{now}}",
        "invoice_date_due": "{{now}}",
        "invoice_payment_term_id": 1,
        "journal_id": 8,
        "currency_id": 173,
        "invoice_line_ids": [{
                "product_id": 9056,
                "name": "Font: Julzy",
                "quantity": 1,
                "product_uom_id": 30,
                "price_unit": 10.00,
                "discount": 0,
                "account_id": 175,
                "tax_ids": [39]
        }]
    }
]


Error 1:

RuntimeError

[1] Traceback (most recent call last): File "/home/odoo/src/odoo/18.0/odoo/addons/base/controllers/rpc.py", line 165, in xmlrpc_2 response = self._xmlrpc(service) ^^^^^^^^^^^^^^^^^^^^^ File "/home/odoo/src/custom/trial/saas_trial/controllers/main.py", line 306, in _xmlrpc res = super(OdooRPC, self)._xmlrpc(service) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/18.0/odoo/addons/base/controllers/rpc.py", line 139, in _xmlrpc result = dispatch_rpc(service, method, params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/18.0/odoo/http.py", line 398, in dispatch_rpc return dispatch(method, params) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/18.0/odoo/service/model.py", line 58, in dispatch res = execute_kw(db, uid, *params[3:]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/18.0/odoo/service/model.py", line 81, in execute_kw return execute(db, uid, obj, method, *args, **kw or {}) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/18.0/odoo/service/model.py", line 87, in execute res = execute_cr(cr, uid, obj, method, *args, **kw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/18.0/odoo/service/model.py", line 72, in execute_cr result = retrying(partial(odoo.api.call_kw, recs, method, args, kw), env) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/18.0/odoo/service/model.py", line 156, in retrying result = func() ^^^^^^ File "/home/odoo/src/odoo/18.0/odoo/api.py", line 533, in call_kw result = getattr(recs, name)(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<decorator-gen-214>", line 2, in create File "/home/odoo/src/odoo/18.0/odoo/api.py", line 495, in _model_create_multi return create(self, [arg]) ^^^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/18.0/addons/purchase/models/account_invoice.py", line 167, in create moves = super(AccountMove, self).create(vals_list) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<decorator-gen-70>", line 2, in create File "/home/odoo/src/odoo/18.0/odoo/api.py", line 496, in _model_create_multi return create(self, arg) ^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/18.0/addons/account/models/account_move.py", line 3189, in create moves = super().create(vals_list) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "<decorator-gen-41>", line 2, in create File "/home/odoo/src/odoo/18.0/odoo/api.py", line 496, in _model_create_multi return create(self, arg) ^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/18.0/addons/mail/models/mail_thread.py", line 268, in create threads = super(MailThread, self).create(vals_list) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<decorator-gen-0>", line 2, in create File "/home/odoo/src/odoo/18.0/odoo/api.py", line 496, in _model_create_multi return create(self, arg) ^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/18.0/odoo/models.py", line 5020, in create records = self._create(data_list) ^^^^^^^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/18.0/odoo/models.py", line 5263, in _create field.create([ File "/home/odoo/src/odoo/18.0/odoo/fields.py", line 4503, in create self.write_batch(record_values, True) File "/home/odoo/src/odoo/18.0/odoo/fields.py", line 4529, in write_batch self.write_real(records_commands_list, create) File "/home/odoo/src/odoo/18.0/odoo/fields.py", line 4714, in write_real to_link[recs[-1]].update(line_ids) File "/home/odoo/src/odoo/18.0/odoo/tools/misc.py", line 1076, in update self._map.update(zip(elems, itertools.repeat(None))) TypeError: unhashable type: 'dict'


Error 2

IMLError

Function 'createRequestBody' finished with error! Expected ',' or ']' after array element in JSON at position 312



Avatar
Buang
Jawaban Terbai

Hi Dan

for One2many and Many2many fields, you need to pass a tuple with 3 elements (see https://www.odoo.com/documentation/18.0/developer/reference/backend/orm.html#odoo.fields.Command).

You must use this format for the invoice_line_ids and tax_ids attribute.
In your case, the first element will have the value 0 (create a new record), the second value 0 (no related record) and the third the dictionary you have defined.

[
    {
        "partner_id": 14,
        "move_type": "out_invoice",
        "invoice_date": "{{now}}",
        "invoice_date_due": "{{now}}",
        "invoice_payment_term_id": 1,
        "journal_id": 8,
        "currency_id": 173,
        "invoice_line_ids": [(0, 0, {
                "product_id": 9056,
                "name": "Font: Julzy",
                "quantity": 1,
                "product_uom_id": 30,
                "price_unit": 10.00,
                "discount": 0,
                "account_id": 175,
                "tax_ids": [(0, 0, 39)]
        })]
    }
]

I hope it will work. Good luck


Best regards
Yvan

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
0
Okt 24
1175
0
Agu 24
1257
1
Des 17
3509
0
Mar 15
3458
2
Mei 24
3478