Odoo Help


How to autosave a record on save a particular field?

on 5/2/13, 5:39 AM 3,410 views


I would like to save my sale order automatically after selecting the customer. How to do that in openerp 7.

Class: sale.py

Method: onchange_partner_id

I added the below lines

val.update({'origin': False,
        'message_follower_ids': False, 
        'date_order': '2013-05-02', 
        'order_line': [], 
        'payment_term': False, 
        'fiscal_position': False, 
        'note': False, 
        'shop_id': 1, 
        'client_order_ref': False, 
        'project_id': False, 
        'partner_id': part.id, 
        'message_ids': False
    self.create(cr, uid, val, context=context)

And i get the following error ProgrammingError: can't adapt type 'browse_record'

Thanks in advance

for partner_id use assign part.id (see, I change your code)

Vasiliy Birukov
on 5/2/13, 8:02 AM

also you don't check state of your records (new or exist). If you change partner twice, you create 2 record. Also you must rewrite original create method for consider that not standard behavior.

Vasiliy Birukov
on 5/2/13, 8:04 AM

Hey, you are right, how do i change the state of the record(new or exist). with your code i solved that error, but the record actually is not saved. when i replace the last line self.create(cr, uid, val, context=context) with the content of the function it inserts the record and still the save and discard is highlighted.

on 5/2/13, 8:23 AM

When record new (yet not created) it don't have ID. When record created it have ID. When you create new record in form, while you don't save, it have not ID. When you create from your method it create other record with new ID.

Vasiliy Birukov
on 5/3/13, 7:10 AM

so, how do i change the state so that the created record id is saved and the view is refreshed?

on 5/3/13, 7:18 AM

I speak "state", mean that if record yet not created it "new" (exist only in form not in db). Onchange method take IDs as parameter. You can check it. For example if it False then call create, if not then call write. I don't know how simple refresh view. Try return new value for ID, but I not sure.

Vasiliy Birukov
on 5/3/13, 7:37 AM

yeah that's what i did and i thought some variable called state will be there. In the class sale order there is no function called write. should i create my own or should i go about in different way? Really Thanks for your continuous support wowas!!

on 5/3/13, 8:00 AM

Create and Write method is inherited from OSV (http://doc.openerp.com/v6.1/developer/03_modules_2.html#orm-methods). If you need change their standard behavior you can rewrite it in your class. You define your own method, but call in it original (see other modules for example).

Vasiliy Birukov
on 5/3/13, 8:12 AM

Vasiliy Birukov

--Vasiliy Birukov--
| 7 6 8
Russian Federation
--Vasiliy Birukov--

Help develop and implement any project on base Odoo.

Vasiliy Birukov
On 5/2/13, 5:50 AM

You can write onchange method for field that must trigger autosave. And in this method call create or write methods (dependent from state of record) for it record.

But such behavior conceptually is not good. You can't make cancel of your change!

Hi, wowas, Thanks for your reply, yeah i am aware that it's conceptually not a good practice. i get the following error "ProgrammingError: can't adapt type 'browse_record'" when i call the create method in onchange_partner_id. i revised my question, please have a look at it. Thanks.

on 5/2/13, 7:32 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 5/2/13, 5:39 AM
Seen: 3410 times
Last updated: 3/16/15, 8:10 AM