Reputation: 1004
I am beginner to openerp framwork I want to know how to use write() and create() methods and what is its purpose?. I already read the docs from openerp but still I am not getting it.
Upvotes: 0
Views: 9207
Reputation: 16753
Create: when ever user saves record in the OpenERP for particular model, that time the create method is being called by the ORM.
Write: once the record is being created and then if the user modify & save the record that time the write method is being called.
This is the basic difference of create and write method.
Download the OpenERP Developer Memento, It will help you a lot!
Upvotes: 1
Reputation: 2393
create(cr, uid, values, context=None)
Creates new record. This method is invoked every time click on the 'New' button and the you save trough the 'Save' button.
The parameters cr
and uid
are well known - the database cursor object and the ID of the user executing the action.
values
is a dictionary containing the values to store in the new record. The dictionary elements are in the form {'field_name': 'field_value',}
.
Let say you have a Student(osv.osv)
model with name
, fac_id
and fac_no
fields. You can create a new Student's record using the following call somewhere inside the Student
class:
new_student_id = self.create(cr, uid, {'name': 'Joe Doe',
'fac_id': 15,
'fac_no': '161832'})
write(cr, uid, ids, values, context=None)
Similar to create()
but updates existing record(s). Which records to update is defined by the ids
parameter. If you want to update the fac_id
field of students with ids 166 and 299 you can do it in the following way:
self.write(cr, uid, [166, 299], {'fac_id': 21})
Upvotes: 7