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

Hello,

In a custom module that I'm developping, I've got an error when clicking on a button "apply".

In facts, I inherited the create function that is called by a click on this button like this :

def create(self, cr, uid, vals, context=None):

  self.write(cr, uid, 1, vals, context=context)

  return True

But currently, this error appear when I click on this button :

Odoo Warning - Missing Record

One of the records you are trying to modify has already been deleted (Document type: to.magento).

How can I solve that ?


Thank you in advance !
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

The code you posted doesn't make any sense, you are overriding the create method to call the write method to change the record with id = 1 with the vals of the create method. The error is that the record with id = 1 could be not created or deleted, you are not calling the super create so you cannot create anything using this method. 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Tutorial - Learn How to override create method in Odoo with Example - 

http://odootechnical.com/learn-overriding-create-method-in-odoo-8/

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

If you want to write / update some value after record create you should write like that:

def create(self, cr, uid, vals, context=None):

   id = super(class_name, self).create(cr, uid, vals, context = context)

   vals.update({'field_name': value})    //   here you can give fields name for which you want to update value.

   self.write(cr, uid, id, vals, context=context)

  return True


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 25
4442
1
thg 1 20
5566
0
thg 9 15
4003
1
thg 3 15
7466
1
thg 3 15
6589