İçereği Atla
Menü
Bu soru işaretlendi
4 Cevaplar
13984 Görünümler

Hello,

I'm trying to insert a new record. Following guide i need to call self.create({'name':'Value'}) within the model. But on try, i get following error:

TypeError: old_api() takes at least 3 arguments (2 given)

I dont unterstand the system of the old api mapping. Please help to find the error.

Best regards

Michael

Avatar
Vazgeç
En İyi Yanıt

Hello Michael

I guess the method inside which you use create call have old api argument.

Example:

def btn_send(self,cr,uid,ids,context=None):

     self.create({name:'AAAA'}) #you cant use new api call in old api like this

This is wrong

Now, what you have to do is :

@api.v8

def btn_send(self):

     self.write({name:'AAAA'}) 

You can use any method but you cant use create method because you are trying to create the record in which you are already in.

Complete Example:

class a(models.Model)

_name = 'a.a'

con = fields.Char('Country')

 

class B(models.Model)

_name = 'b.b'

lnam = fields.Char('lnam')

@api.v8

def btn_join(self):

  self.env['a.a'].create({con:self.lnam}) #result : value_of_Lnam in Country

 

You can refer guidline of How to use Environment in new api click here 

Hope that this answer will help you.

Please don't hesitate to ask any question regarding this.

Thank You

 

 

 

Avatar
Vazgeç
En İyi Yanıt

 Try this,

            new_id = phonecall.create(cr, uid, vals, context=context)

 

Avatar
Vazgeç
En İyi Yanıt

AFAIK, Not all of v8.0 code has been migrated to new API.  So, you need to check what model that you are writing and if has supported new API.

Avatar
Vazgeç
Üretici En İyi Yanıt

Thx for the nice answer. I got it. I needed to rewrite the button function from:

def btn_send(self,cr,uid,ids,context=None):

to:

@api.multi #otherwise the form view cant access this function
def btn_send(self):

Problem solved. best regards Michael

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
2
Kas 22
9473
2
Ara 20
8230
2
Nis 15
4686
2
Şub 22
5415
2
Oca 20
15080