3

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.

Pestana
  • 132
  • 1
  • 10

1 Answers1

3

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!

Atul Arvind
  • 16,054
  • 6
  • 50
  • 58
  • Thanks for the answer. I am trying to do it in another model, in my custom module. How I can do that?. – Pestana Aug 17 '18 at 11:30
  • Hi. Finally I solved it, with my code and your button. I had mixed tabs and spaces. – Pestana Aug 20 '18 at 12:44
  • I just miss the domain to view only the messages of the opportunity and de delete button of messages. I tried adding view_id to the return with out success and the domain broke the code. I tried "[('res_id','=', self.id)]" to the domain and "mail.message.search" to the view_id. Any help can be appreciated. – Pestana Aug 20 '18 at 12:51