write_record and write does not update and resets change

Asked by codemonk

I am trying to update a product record, but on write_record it is always reversed to the original entry:

>>> import oerplib
>>> oerp = oerplib.OERP(server='localhost', protocol='xmlrpc', database='fau_fablab', port=8069)
>>> user = oerp.login(user='admin', passwd='xxxxxxxxxxx')
>>> m = oerp.get('product.product')
>>> product = oerp.browse('product.product', 1)
>>> product.name
'Dienstleistung'
>>> product.name = "FOO"
>>> product.name
'FOO'
>>> oerp.write_record(product)
True
>>> product.name
'Dienstleistung'

What is happening here?

Question information

Language:
English Edit question
Status:
Solved
For:
OERPLib Edit question
Assignee:
No assignee Edit question
Solved by:
Sébastien Alix
Solved:
Last query:
Last reply:
Revision history for this message
Sébastien Alix (sebastien-alix) said :
#1

Hi,

What version are you using?

>>> import oerplib
>>> oerplib.__version__
0.8.1

Sadly, I can not reproduce this bug myself:

>>> import oerplib
>>> oerp = oerplib.OERP('localhost', port=8869)
>>> oerp.login('admin', 'admin', 'oerplib_test4')
browse_record('res.users', 1)
>>> product = oerp.browse('product.product', 1)
>>> product.name
'Service'
>>> product.name = "FOO"
>>> product.name
'FOO'
>>> oerp.write_record(product)
True
>>> product.name
'FOO'

But can you try this piece of code, to check if there is no bug about internationalization?

>>> m = oerp.get('product.product')
>>> m.read([1], ['name'], context={'lang': 'en_US'})
[{'id': 1, 'name': 'BAR'}]
>>> m.read([1], ['name'], context={'lang': 'de_DE'})
[{'id': 1, 'name': 'BAR'}]

Revision history for this message
Sébastien Alix (sebastien-alix) said :
#2

Needs info

Revision history for this message
codemonk (codemonk) said :
#3

>>> oerplib.__version__
 '0.8.1'
>>> m = oerp.get('product.product')
>>> m.read([1], ['name'], context={'lang': 'en_US'})
[{'id': 1, 'name': 'FOO'}]
>>> m.read([1], ['name'], context={'lang': 'de_DE'})
[{'id': 1, 'name': 'Dienstleistung'}]
>>> oerp.context
{'lang': 'de_DE', 'tz': 'Europe/Berlin', 'uid': 1}

Your right, it's because of the internationalization. How can I choose which context I write to using browse_record and write_record?

Revision history for this message
Best Sébastien Alix (sebastien-alix) said :
#4

Well done, you discovered a bug! Currently the write_record() method does not retrieve the context of the browse_record by default. I will fix that.

In the meantime, you can simply force the context like that:

>>> oerp.write_record(product, context=oerp.context)

It should be OK.

Revision history for this message
codemonk (codemonk) said :
#5

Thanks!

Revision history for this message
codemonk (codemonk) said :
#6

Thanks Sébastien Alix, that solved my question.