Is XML-RPC transactional ?

Asked by Alexandre Boyer

i would like to know if it is possible to call XML-RPC method in transactional way ?
For example, i create an order, i create two lines, the second lines generates an error, can i proceed to a rollback (and cancel the order and the first lines) ?

regards

Question information

Language:
English Edit question
Status:
Answered
For:
OpenERP Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Numérigraphe (numerigraphe) said :
#1

From what I understand, you can send several pieces of data in a single XML-RPC call and they will be treated as a single transaction.

However if you make several XML-RPC calls, there is no way they can be treated as a single transaction because the protocol does not hold session data, i.e the server can't know that the second call is a follow-up to the first call.

Revision history for this message
Alexandre Boyer (aboyer) said :
#2

how can i do to make this a code transactional (if address creation failed, i do not want the partner to be inserted):
import xmlrpclib

sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
uid = 1
pwd = 'demo'

partner = {
    'title': 'Monsieur',
    'name': 'Fabien Pinckaers',
    'lang': 'fr',
    'active': True,
}

partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner)

address = {
    'partner_id': partner_id,
    'type': 'default',
    'street': 'Rue du vieux chateau, 21',
    'zip': '1457',
    'city': 'Walhain',
    'phone': '(+32)10.68.94.39',
    'fax': '(+32)10.68.94.39',
}

sock.execute(dbname, uid, pwd, 'res.partner.address', 'create', address)

Revision history for this message
Numérigraphe (numerigraphe) said :
#3

You should try this :

partner = {
    'title': 'Monsieur',
    'name': 'Fabien Pinckaers',
    'lang': 'fr',
    'address': [(0,0,{
        'partner_id': partner_id,
        'type': 'default',
        'street': 'Rue du vieux chateau, 21',
        'zip': '1457',
        'city': 'Walhain',
        'phone': '(+32)10.68.94.39',
        'fax': '(+32)10.68.94.39',
    })]
}
address_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner).

That's what the GTK client would do ; the [(0,0, {} ] thing is probably an internal convention.

Good luck,
Lionel

Revision history for this message
Numérigraphe (numerigraphe) said :
#4

Small typo : the last line should read "partner_id=..." instead of "address_id = ...".
Lionel.

Revision history for this message
Mantavya Gajjar (Open ERP) (mga) said :
#5

Hello,

This is bit easy for all recotd to be translated, while any operations [read, write, create]

here i do the sampel code a you shown above

address = {
    'partner_id': partner_id,
    'type': 'default',
    'street': 'Rue du vieux chateau, 21',
    'zip': '1457',
    'city': 'Walhain',
    'phone': '(+32)10.68.94.39',
    'fax': '(+32)10.68.94.39',
}
context = {
 'lang': 'fr_FR',
 'tz': False
}
sock.execute(dbname, uid, pwd, 'res.partner.address', 'create', address)
just replace this line by
sock.execute(dbname, uid, pwd, 'res.partner.address', 'create', address, context)

Context is the special argument when dealing client server transection, it holdes language, timezone, some times active_id and active_ids too

Try this one

Can you help with this problem?

Provide an answer of your own, or ask Alexandre Boyer for more information if necessary.

To post a message you must log in.