2

I'm trying to change the state of a created invoice from 'draft' to 'posted' using the Web APIs (Python) by referring to this documentation : https://www.odoo.com/documentation/13.0/webservices/odoo.html

I'm updating the invoice as follows :

def makeInvoicePosted(invoice_id):

    invoice_ids = []

    invoice_ids.append(invoice_id)

    common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))

    print(common)

    uid = common.authenticate(db, username, password, {})

    print("makeInvoicePosted : Odoo Admin User Id : ", uid)

    models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))

    models.execute_kw(db, uid, password, 'account.move', 'write', [[invoice_id], {'state':"posted"}])

But I'm getting this error : odoo.exceptions.ValidationError: ('Posted journal entry must have an unique sequence number per company.', None)\n'

What could be causing this ? is there something missing in the request?

Thanks in advance!

CZoellner
  • 13,553
  • 3
  • 25
  • 38
Ahmad Sabeh
  • 526
  • 5
  • 18

1 Answers1

3

I recommend to use Odoo's workflow and business logic here by calling post instead of directly writing the state.

models.execute_kw(db, uid, password, 'account.move', 'post', [[invoice_id],])

Why: because there are a lot of checks and also a lot of things done in this method, you could miss or just do wrong (invoices are very complex). You probably will find some mistakes in your calls right before doing the post, because of the checks in it.

CZoellner
  • 13,553
  • 3
  • 25
  • 38
  • Thanks! that did it. Is there a way i can see where i can use Odoo's workflow on web APIs ? This is not posted in the documentation. – Ahmad Sabeh Oct 20 '20 at 20:37
  • 1
    No you won't find a really good documentation about it. It's more of knowing the workflows as user and then trying to recap the process behind (which methods are used, which fields are filled and so on) in the code. The `post` one here is an easy one, because it's found very fast with client debug mode and the button on the invoices. – CZoellner Oct 21 '20 at 07:08