Enable Dark Mode!
odoo-technical-tips.png
By: Niyas Raphy

Odoo Technical Tips

Technical

In this blog, we are going to discuss some technical features in Odoo.

 

1. How to make a menu visible for users?         

To make a menu visible for the users other than the administrator, we have to use the group’s keyword. On defining the menu we have to add groups along with it.

 

<menuitem id="menu_test_view" name="Test” />

  

If we define a menu like the above, the menu will be only visible to the administrator.

If the menu has to be visible for all the users, then we have to change the above menu definition as follows

 

<menuitem id="menu_test_view" name="Test” groups=”base.group_user”/>

 

Where the “base.group_user” is the group name of the employees.

As we define the menu like this, the menu will be visible for all the users. If the menu wants to show only for specific groups, such as Sales/manager,

 

<menuitem id="menu_test_view" name="Test” groups=”sales_team.group_sale_manager/>

 

2. How to make a field visible in Debug mode only?

 

To make a field visible only in debug mode, we have to add group attribute for the field,

 

                   <field name="amount_total"/>

  

Suppose the above field has to be visible only in the debug mode, then add groups=base.group_no_one” to this field


<field name="amount_total" groups=”base.group_no_one”/>


Then the field will be visible only in the debug mode.


3. How to Access current user and current db in XML?

 

 To get the current user details in the XML, we can use the following

 

          user.id -> it will give the Id of the current user

          user.name -> it will give the name of current user

          user.groups_id -> this will return the groups in which user is a member

 

To get the database name, we can use the following

 

          request.session.db -> this will return the db name

 

4. How to send Email via Python Code?

 

Now let us check how can we send the e-mail from the python code,

 

template_obj = request.env['mail.mail']
template_data = {
    'subject': 'Subject of the Mail',
    'body_html': 'Hi, you can add the message body here',
    'email_from': 'admintest@gmail.com',
    'email_to': 'test@mail.com'
}
template_id = template_obj.create(template_data)
template_obj.send(template_id)

 By using the above code we can send the email. First of all, we have to access the mail. Mail object, then set the subject, body, from and to. The above code is based on V10.

 

5. How to override an existing function?

 

How to override an existing function without affecting the original. Suppose def get_val is a function in the model test.test, now we can look how to override this get_val function in the test.test model.

 

class TestTest(models.Model):
    _inherit = 'test.test'
 
    @api.model
    def get_val(self):
        res = super(TestTest, self).get_val()
        #add new code here
        return  res

By the above format, we can override an existing function. By this, you can add new codes so that this will also get executed along with the original function execution.


If you need any assistance in odoo, we are online, please chat with us.



1
Comments

Hunain

Guys you are doing a great job. A bug shout-out to your team!

19/04/2019

-

10:47AM



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message