Search code examples
pythonodooodoo-11

Odoo open new window


I want to create a button in opportunities of CRM in Odoo 11. I want to open a window with all messages of this opportunity (Model mail.message)

I tried to create my first addon.

Here is my structure:

  • /odoo/addons/test
    • __init__.py
    • __manifest__.py
    • models
      • __init__.py
      • test.py

Here is my code:

/odoo/addons/test/__manifest__.py

{
'name': 'test',
'version': '2.0',
'category': 'Sales',
'sequence': 5,
'summary': 'test',
'description': "",
'website': 'https://test.net',
'depends': [
    'crm'
],
'data': [
],
'demo': [
],
'css': [],
'installable': True,
'application': True,
'auto_install': False,
}

/odoo/addons/test/__init__.py

from . import models

/odoo/addons/test/models/__init__.py

from . import test

/odoo/addons/test/models/test.py

from odoo import models, fields


class test_test(models.Model):
    _inherit = 'crm.lead'

    @api.multi
    def test_test(self):
        return {
            'name': 'test_test',
            'res_model': 'mail.message',
            'view_type': 'list',
            'view_mode': 'tree,list',
            'type': 'ir.actions.act_window',
            'target': 'inline'
        }

crm.lead.form.opportunity

 <button name='%(test_test)d' string="test" type="action" />

I installed my application but the button does not work and it does not show any error. And I am not able to see my action in the UI.


Solution

  • to call a function from the view you need to define object type button like below.

    <button name='test_test' string="test" type="object" />
    

    it will call function test_test in your model crm.lead, (make sure your button is in the crm.lead model view.)

    and you need to change your function like below

    @api.multi
    def test_test(self):
        return {
            'name': 'test_test',
            'res_model': 'mail.message',
            'view_type': 'list',
            'view_mode': 'tree,list',
            'type': 'ir.actions.act_window',
            'target': 'new' # will open a popup with mail.message list
        }
    

    hope this helps!