Odoo Help
Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM
|
e-Commerce
|
Accounting
|
Inventory
|
PoS
|
Project management
|
MRP
|
etc.
How to autosave a record on save a particular field?
Hi,
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
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.
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.
RegisterOdoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.
Test it nowQuestion tools
Stats
Asked: 5/2/13, 5:39 AM |
Seen: 3311 times |
Last updated: 3/16/15, 8:10 AM |
for partner_id use assign part.id (see, I change your code)
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.
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.
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.
so, how do i change the state so that the created record id is saved and the view is refreshed?
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.
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!!
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).