Community mailing list archives

community@mail.odoo.com

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

by
Serpent Consulting Services Pvt. Ltd., Jay Vora
- 01/29/2016 07:35:09
Aires,

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.

Example:

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

Thanks.

On Fri, Jan 29, 2016 at 5:51 PM, Aires Silvestre <aires.silvestre@alien-group.com> 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 - 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="cid:part1.00060100.01010305@alien-group.com" alt="ALIEN GROUP LDA">

Aires Silvestre

COO

em.aires.silvestre@alien-group.com

tm.+244 925 999 331

<img src="cid:part9.06020200.06030003@alien-group.com" alt="Código QR">

Rua Doutor Agostinho Neto, 156, Bairro Azul, Luanda - Angola, Tel: +244 913 728 600 | +244 913 728 650,
Website: www.alien-group.com, Email: geral@alien-group.com

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

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe




--

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


 
Direct: +91-9879354457
Office: +91-9033472982
Skype: jaynvora
Twitter : jaynvora
   
-------------------------------------------------------------------------------------------------
Visit our website : http://www.serpentcs.com
Please consider the environment before printing this email