• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

How to Add a Custom Button in Odoo 18 CRM Module View Switcher?

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
1,481
Баллы
155
Introduction


If you're working with Odoo 18 and want to enhance your CRM module by adding a custom button to the view switcher, you've come to the right place. This guide will walk you through the process of integrating a button with a custom icon next to the standard views (like Kanban, List, and Calendar) and ensure it opens a predefined view. By the end of this article, you’ll have a clear understanding of how to implement this correctly using a custom Odoo module, following best practices.

Understanding the Requirements


First, let's break down your requirements:

  • A custom button next to the view switcher in Odoo CRM.
  • The button should display a specific icon (e.g., fa-puzzle-piece).
  • Upon clicking the button, a custom view should appear, even if it only displays a simple 'Hello World' message.
Step-by-Step Guide to Implement the Custom Button

Step 1: Create a Custom Odoo Module


To get started, create a new Odoo module. Use the following command in your terminal:

$ odoo-bin scaffold custom_crm_button addons


This command creates a basic module framework under the addons directory named custom_crm_button.

Step 2: Define the Module Structure


In your module, you need to define the required files, including __manifest__.py and a new XML view file. Here’s how the basic structure should look:

/custom_crm_button
|-- __init__.py
|-- __manifest__.py
|-- models
| |-- __init__.py
|-- views
| |-- crm_views.xml


The __manifest__.py file should contain metadata about your module and can look like this:

{
'name': 'Custom CRM Button',
'version': '1.0',
'depends': ['crm'],
'data': ['views/crm_views.xml'],
'installable': True,
'application': False,
}

Step 3: Create the Custom View XML


In the views/crm_views.xml file, you will add the necessary XML to define your custom button and action. Here’s an example:

<odoo>
<data>
<!-- Define the action that opens the custom view -->
<record id="action_custom_view" model="ir.actions.act_window">
<field name="name">Custom View</field>
<field name="res_model">custom.model</field>
<field name="view_mode">form,tree</field>
<field name="res_id" eval="False"/>
</record>

<!-- Custom button in the view switcher -->
<record model="ir.ui.view" id="view_crm_tree_custom_button">
<field name="name">crm.lead.tree.custom.button</field>
<field name="model">crm.lead</field>
<field name="arch" type="xml">
<xpath expr="//div[@class='o_cp_left']/div[@class='o_cp_buttons']" position="inside">
<button type="object" name="%(action_custom_view)d" class="oe_highlight" title="Open Custom View">
<i class="fa fa-puzzle-piece"></i>
</button>
</xpath>
</field>
</record>
</data>
</odoo>

Step 4: Define the Model for the Custom View


You need a model that will be linked to your custom view action. Create a Python file in the models directory:

from odoo import models, fields

class CustomModel(models.Model):
_name = 'custom.model'
_description = 'Custom Model'
name = fields.Char(string='Name', required=True)

Step 5: Update Odoo and Test Your Module


After implementing the above code, you will need to update your Odoo instance to recognize your new module. You can do this by going to the Apps menu, clicking on 'Update Apps List', and then installing your Custom CRM Button module.

Step 6: Verify the Custom Button


Navigate to the CRM module, and you should now see your custom button on the top-right view switcher. Click the button, and it should lead you to a blank view associated with your new model.

Frequently Asked Questions (FAQ)

How do I ensure my custom view opens correctly?


Make sure that you have defined the action correctly in your XML file and that the model associated with it exists.

Can I add more functionality to my custom view?


Absolutely! You can enhance your custom view by defining more fields in your model and designing the frontend as needed.

Is there a way to customize the button's appearance?


Yes, you can use additional CSS to customize the appearance of your button by adding styles in the static directory of your module.

Conclusion


By following the steps outlined in this article, you can successfully add a custom button to the Odoo 18 CRM view switcher. This method ensures that you maintain the integrity of the Odoo framework while providing room for future enhancements to your custom view. Now that you have a solid foundation, feel free to expand on it by adding more advanced functionalities and engaging user experiences.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу