Odoo Help

1

inherit create function in the new framework ?

By
Rachid
on 9/8/14, 8:02 AM 5,660 views

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)

3

Hi,

Just do as like below.

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

then how can I call the cr and uid ?

Rachid
on 9/8/14, 9:25 AM

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

Emipro Technologies Pvt. Ltd.
on 9/8/14, 9:28 AM

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

Emipro Technologies Pvt. Ltd.
on 9/8/14, 9:29 AM

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,)

Rachid
on 9/8/14, 9:37 AM

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.

Emipro Technologies Pvt. Ltd.
on 9/8/14, 10:00 AM

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.

Rachid
on 9/9/14, 6:07 AM

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

Emipro Technologies Pvt. Ltd.
on 9/9/14, 6:19 AM

same problem :(

Rachid
on 9/9/14, 7:19 AM

May I know that you are test into fresh database ?

Emipro Technologies Pvt. Ltd.
on 9/9/14, 7:21 AM

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

Rachid
on 9/9/14, 7:29 AM

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

Emipro Technologies Pvt. Ltd.
on 9/9/14, 7:36 AM

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

Rachid
on 9/12/14, 9:57 AM
2
Anil R. Kesariya
On 9/9/14, 7:43 AM

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.

 

0
Rachid
On 9/9/14, 6:45 AM

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.

0
Nikunj Nakum
On 9/9/14, 6:50 AM

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

 

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

Rachid
on 9/9/14, 6:56 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 9/8/14, 8:02 AM
Seen: 5660 times
Last updated: 3/16/15, 8:10 AM