Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
4 Odpowiedzi
11175 Widoki

I did:

    @api.model
    def create(self, cr, uid, vals, context=None):

 

 

Traceback (most recent call last):
  File "/opt/odoo/odoo-8.0/openerp/http.py", line 476, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo-8.0/openerp/http.py", line 495, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/odoo-8.0/openerp/http.py", line 311, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo-8.0/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo-8.0/openerp/http.py", line 308, in checked_call
    return self.endpoint(*a, **kw)
  File "/opt/odoo/odoo-8.0/openerp/http.py", line 685, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo-8.0/openerp/http.py", line 360, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/odoo-8.0/addons/web/controllers/main.py", line 941, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/opt/odoo/odoo-8.0/addons/web/controllers/main.py", line 933, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/opt/odoo/odoo-8.0/openerp/api.py", line 234, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/odoo-8.0/openerp/api.py", line 329, in old_api
    result = method(recs, *args, **kwargs)
TypeError: create() takes at least 4 arguments (2 given)

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

Just do as like below.

@api.model
def create(self, vals, context=None):

Awatar
Odrzuć
Autor

then how can I call the cr and uid ?

You can find the cr and uid into self.env. Because this is the new api structure.

If you get this as an answer then please accept this answer. And give me up vote. Thanks.

Autor

I get this MissingError One of the documents you are trying to access has been deleted, please try again after refreshing. the create function has the line: new_id = super(res_partner, self).create( vals,)

Hello, For the calling of the create method you have two option. 1) As like normal calling with cr and uid. for that you can call new_id = super(res_partner,self).create(self.env.cr, self.env.uid, vals, context=context) 2) As like new API. For that you can call. new_id = super(res_partner,self).create(vals, context=context) Note : You have to confirm that here self is an recordset.

Autor

I get the TypeError: create() takes exactly 2 arguments (5 given) when I use: new_id = super(res_partner,self).create(self.env.cr, self.env.uid, vals, context=context) AND TypeError: create() got an unexpected keyword argument 'context' WHEN USING new_id = super(res_partner,self).create(vals, context=context) I DIDN'T UNDERSTAND WHAT DO YOU MEAN WITH You have to confirm that here self is an recordset.

"self" have to be recordset (as like browse record) to call the new api. From the calling just remove the context argument.

Autor

same problem :(

May I know that you are test into fresh database ?

Autor

no it's not fresh I'm trying update all modules whit option -u all

Can you try it in fresh database ? Might be it is an error of some other module or may be issue of some data.

Autor

I tryid in a different database but the same problem :(

Najlepsza odpowiedź

Hello Rachid,

Here you go!

    @api.model
    def create(self, vals):
        cr, uid, context = self.env.args  #cursor , user and context can be fetch from env. if there is need of use.
        <Your code gose here...>
        res = super(<your model name>, self).create(vals)

      <Your code gose here...>
        return res

Hope this will helps you.

Anil.

 

Awatar
Odrzuć
Autor Najlepsza odpowiedź

I copied the same code of create function in the res_partner class HIERE IS

    @api.model
    def create(self, vals):
        if vals.get('website'):
            vals['website'] = self._clean_website(vals['website'])

        print vals

        partner = super(res_partner, self).create(vals)
        self._fields_sync(partner, vals)
        self._handle_first_contact_creation(partner)
        return partner

 

I get the same error One of the documents you are trying to access has been deleted, please try again after refreshing.

Awatar
Odrzuć
Najlepsza odpowiedź

@api.model
@api.returns('self', lambda value: value.id)
 def create(self, vals):

 

Awatar
Odrzuć
Autor

no changes MissingError: ('MissingError', u'One of the documents you are trying to access has been deleted, please try again after refreshing.')

Powiązane posty Odpowiedzi Widoki Czynność
3
wrz 22
17531
6
gru 16
11489
0
mar 15
3121
1
mar 15
5805
1
mar 15
3457