Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
89484 Lượt xem

Hi,

how can i use write and create function ?

thanks

Ảnh đại diện
Huỷ bỏ

Yes you can override these methods to add your logic. Here is complete code with description. http://learnopenerp.blogspot.com/2017/11/how-to-override-odoo-functions.html

Hope this will helpful for you.

Thanks

Câu trả lời hay nhất

Hi Abir,

You can override the default write and create functions in order to add your own logic in.
An example for overriding the create:

@api.model def create(self, values): """Override default Odoo create function and extend.""" # Do your custom logic here return super(ResPartner, self).create(values)

An example for overriding the write:

@api.multi def write(self, values): """Override default Odoo write function and extend.""" # Do your custom logic here return super(ResPartner, self).write(values)

If you're talking about using .write or .create to create records you can do the following:

record = self.env['your.model'].create({
'name': 'Example'
})

For a write:

record_ids = self.env['your.model'].search([('name', '=', 'Example')])
for record in record_ids: record.write({
'some_field': 'some_description'
})

Regards,
Yenthe

Ảnh đại diện
Huỷ bỏ

Hi Yenthe Van Ginneken (Oocademy),

How about create a record using SQL Command such as inserting new record using SQL.

Because if i am using .create (take very long times, i need cut the load and the best solver is SQL command)

How can i inserting that what i means is how i get parameter such as XML ID database ID etc that i must to insert but i dunno how to get the value.

Câu trả lời hay nhất

How to override Odoo Create, Write and Unlink method. Here the question is why we need to override these (create, write and unlink) methods.

The answer is to add or remove additional functionality we use overriding. For example if I want to check some constraints before creating, editing or deleting our record than we may use Odoo override methods.

There are basically three methods which we can override.

  1. Create

  2. Write

  3. Unlink

Read more how to override odoo functions: http://learnopenerp.blogspot.com/2017/11/how-to-override-odoo-functions.html

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 12 16
3037
2
thg 1 16
35705
1
thg 10 23
10724
2
thg 4 15
5190
2
thg 7 25
4196