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

Hello everyone !


I'm having an issue on overriding Create() and Write() methods...

Here is my code :

@api.model

def create(self, vals):

rec=super(Label, self).create(vals)

self._registerLabel(vals['real_id'])

return rec

def write(self, vals):

self._unregisterLabel(self.real_id)

rec=super(Label, self).write(vals)

self._registerLabel(vals['real_id'])

return rec


I'm having an issue now with the _registerLabel(labelid) method. When i edit a record in odoo, _registerLabel is well called But when i create a new one, the same method isn't.

Can someone explain me this please ? :)

Thank you ! 

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

Please, post the code of your _registerLabel method

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

Hi Bastien 

in create method 

rec :  representes the created model data. 

self :  contains data from the current form view.

If field "real_id" is computed, or a relationnel field that is not in your form . it won't be in vals dictionnary ( vals["real_id"] = false ).  So right way is :

@api.model

def create(self, vals):

rec=super(Label, self).create(vals)

rec._registerLabel(vals['real_id'])

return rec



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

 here is the _registerLabel definition

@api.one
 def _registerLabel(self, Label_id):
      response=requests.post(url,data='<Label id=\"'+Label_id+'\"/>',headers={'Content-Type':'application/xml'})

Thank you for your time
Ảnh đại diện
Huỷ bỏ

try rec._registerLabel(vals['real_id']) instead of self._registerLabel(vals['real_id'])

Tác giả

This works ! Thank you !

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 1 19
11495
1
thg 10 17
3376
2
thg 1 16
35803
1
thg 3 15
10660
1
thg 8 20
4842