I'm making an Android app for OpenERP and I'm trying to create new Sales Order. One of the required fields however is Order Reference, which is normaly generated from the sequence.
Is there some way to get this sequence via xmlrpc?
Or do I have to make my own sequence in the app? ...but then how can I make sure that it would not colide with order references generated via web client?
Thank you.
You should not need to do anything special: just call sale.order
's create
method with the content of your Sales Order. As you noticed when you create a Sales Order using the web interface, the reference field is automatically filled in with a proper sequence number.
This happens because sale.order
has a default value for the reference field (the sale.order
's name
field, technically). Default values work as follows:
default_get
on the corresponding model (which will take the values from the _defaults
dictionary.As a result, you don't need to do anything: just call create
without giving a value for the name
field, and the system will automatically set its value to a valid sequence number, just as it would in the UI. Alternatively if you'd like to pre-process the default values or to exactly mimic what the UI does, then you should call default_get
yourself via XML-RPC and use the returned values to prepare the parameters you will pass to create
.
Version note: you did not mention any specific OpenERP version, and the actual behavior may vary a little bit depending on the version. In OpenERP 6.1 the sale.order
model did exactly what I described above, as you can see in the source. In OpenERP 7.0 however the logic was slightly modified to avoid consuming sequence numbers that might never be used (if the user cancels before saving): instead of generating a new number in default_get
, the name
field is initialized to '/'
by default, and the create
method replaces it with a new number, as you can see in the source. The net effect is the same.