Community mailing list archives

Re: V8 - Fields defaults not getting loaded in Create method

- 01/29/2016 08:41:29
Great description Jay.

On Fri, Jan 29, 2016 at 6:27 PM, Aires Silvestre <> wrote:
Jay Vora

You're the chosen one!

Thanks a lot!
Aires Silvestre

On 01/29/2016 01:36 PM, Jay Vora wrote:
<blockquote cite="" type="cite">

Logically, you must pass values for mandatory fields, disregard to the fact that you use GUI or a script.(manual or automated)

In your case, you must pass mandatory fields.

Do this:
1. Call default_get() of purchase order, store values in a dict
2. Call onchange of the partner(partner_id=XXX) of purchase order, store values in a dict, append to the dict of 1.
3. Call create and use the result of 1 and 2 as vals.


dist =  {
                     'partner_id'   :,
                     'amount'       : invoice.amount_paid,
                     'journal_id'   :                    
dist.update(self.pool.get('account.voucher').onchange_partner_id(cr, uid, [],, , 0,, False,, context= ctx)['value'])
 dist.update(self.pool.get('account.voucher').onchange_amount(cr, uid, [], invoice.amount_paid, 1,, ,, False,,,, context= ctx)['value'])
voucher_id = voucher_obj.create(cr, uid, dist)


On Fri, Jan 29, 2016 at 5:51 PM, Aires Silvestre <> wrote:
Hello Community, I need help, please

In Odoo V8 if you create a Puchase Order using the Odoo interface you'll realize that there are some required (not null) fields that get their default values computed automatically (location_id, date_order, picking_type_id, etc) and the only field you have to enter is the vendor.

But if I try to create a Purchase Order using the ORM (by Create method) and passing only the partner_id as data all those field are not computed and therefore I get Integrity Error (
[object with reference: location_id -] ).

My code (using new API):
self.env['purchase.order'].create({'partner_id': XXX})

I now I can overcome this by passing all required fields but if they have defaults computed in the model, should not the create in ORM behave the same way?
How can I use the create and have the same required fields computed and loaded for me?

Thanks in advance and kind regards 
<img src="" alt="ALIEN GROUP LDA">

Aires Silvestre


tm.+244 925 999 331

<img src="" alt="Código QR">

Rua Doutor Agostinho Neto, 156, Bairro Azul, Luanda - Angola, Tel: +244 913 728 600 | +244 913 728 650,
Website:, Email:

<img src="" style="vertical-align:top;" alt=""> Não imprima este email caso não seja estritamente necessário. A Terra agradece-lhe!

Post to:


The Splendid journey of 4 years in Numbers
Jay Vora
Managing Director

Direct: +91-9879354457
Office: +91-9033472982
Skype: jaynvora
Twitter : jaynvora

Visit our website :
Please consider the environment before printing this email

Post to:

Post to:

Jake Shelter,