Odoo Help

1

New API syntax

api
By
Manuel Pérez
on 1/4/15, 6:27 PM 1,353 views

Hi there gurus!

I've developed a custom module (V8) following the new API syntax and I'l like to use the same functionality available in the Projects module which links the project form with the attachments form via a button. The method that achieves this in Projects follows the old syntax, so I'd like to know how to rewrite the following piece of code according to the new API:

    def attachment_tree_view(self, cr, uid, ids, context):
        domain = [ ('res_model', '=', 'project.project'), ('res_id', 'in', ids)]
        res_id = ids and ids[0] or False
        return {
            'name': _('Attachments'),
            'domain': domain,
            'res_model': 'ir.attachment',
            'type': 'ir.actions.act_window',
            'view_id': False,
            'view_mode': 'kanban,tree,form',
            'view_type': 'form',
            'limit': 80,
            'context': "{'default_res_model': '%s','default_res_id': %d}" % (self._name, res_id)
        }

I would have thought it to be something like this, but unfortunatelly I don't get it to work:

    @api.one

    def attachment_tree_view(self):
        domain = [ ('res_model', '=', 'project.project'), ('res_id', '=', self.id)]
        res_id = self.id
        return {
            'name': _('Attachments'),
            'domain': domain,
            'res_model': 'ir.attachment',
            'type': 'ir.actions.act_window',
            'view_id': False,
            'view_mode': 'kanban,tree,form',
            'view_type': 'form',
            'limit': 80,
            'context': "{'default_res_model': '%s','default_res_id': %d}" % (self._name, res_id)
        }

Any help will be much appreciated.

0

You will have to write @api.multi instead of @api.one. For wizards use @api.multi
 

0
Manuel Pérez
On 1/9/15, 12:06 PM

Hi - I used @api.multi without success either...

For me :) ... you test @api.returns(). See: http://odoo-new-api-guide-line.readthedocs.org/en/latest/decorator.html and http://djpatelblog.blogspot.com/2014/09/odoo-new-api-metaclasses-and-decorators.html

Zbik
on 1/9/15, 2:48 PM

Thanks, I'll try @api.returns !!

Manuel Pérez
on 1/9/15, 4:01 PM

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

2 follower(s)

Stats

Asked: 1/4/15, 6:27 PM
Seen: 1353 times
Last updated: 3/16/15, 8:10 AM