This question has been flagged
2 Replies
8546 Views

Hello,

I am trying to create new module from new API,I don't want to write cr ,uid, ids, or self._cr, self._uid and other things.

If there are method written in old API style and I want to call it from new API then how to call

Suppose I want to call duplicate_template method in project module

right now I need to call same as old style

new_project_template = self.pool.get('project.project').duplicate_template(self._cr, self._uid, [my_project_template.id], context = context) 

but I want to call as a new API style

new_project_template = self.env['project.project'].duplicate_template(my_project_template.id]) 

OR

new_project_template = self.env['project.project'].duplicate_template(self._cr, self._uid, [my_project_template.id], context = context)

is it possible ?

Thank's for reply.

Avatar
Discard

Missing api decorator for this function (project has not been converted in new api)...

Best Answer

Hello Sagar,

You can only call the methods in new api coding standard those are defined or (Definition) written in  new api coding standard.

Like Base module's methods (Create,write,unlink,copy,name_get etc) this method can be called with new coding standard.

But those method already defined in old coding standard than you have to pass argument while calling it.

So, you have to follow this way.

new_project_template = self.env['project.project'].duplicate_template(self._cr, self._uid, [my_project_template.id], self._context)

But make sure your current method is defined in new coding standard means you are using decorators in your method while calling this method. otherwise you can not define object using self.env

Otherwise you have to use:

new_project_template = self.pool.get('project.project').duplicate_template(cr, uid, [my_project_template.id], context = context) 

While you are calling methods those are written in old standard you have to pass all those arguments.

Hope this will help.


Rgds,

Anil.


Avatar
Discard