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:
- they are fetched by the client UI to pre-populate the creation form. The client obtains these value by calling
default_get
on the corresponding model (which will take the values from the_defaults
dictionary. - when the create method is called to create a new record, the system will call default_get again in order to complete the values for all the fields that have defaults and were not explicitly passed to create
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.