This question has been flagged
2 Replies
3719 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.

Avatar
Discard
Author Best Answer

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

Avatar
Discard

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

Author

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

Best Answer

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

Avatar
Discard