Monday, 4 February 2019



In this tutorial i will teach you how to add Chatter to an existing model or to a new model.

Why Chatter

One of the most important reason why you want to add chatter to your module is simply because you want to keep track of activities carried on in a particular section of your module. One beautiful things about Odoo Chatter is, you can actually add people to follow the activity, just like you follow a topic on a forum and you are also notified of a new comment or like.
Everyone that is added as a follower will be notified whenever an action is performed.
So let’s see how you can add this in your code…

Add Chatter to a Model

Adding chatter to an existing model or a new model can be done by the inheritance of mail mixins: mail.thread and mail.activity.mixinyou may also add mail.alias.mixin. 

So, whatever module you are working on, always remember to add this line of code to your python file:

_inherit = ['mail.thread', 'mail.activity.mixin']

This takes care of the message_ids and message_follower_ids 
Once you are done with the above, you need to add some lines of code to your xml, add the xml code must be inside your form tag but after the sheet closing tag:

</sheet> 
    <div class="oe_chatter"> 
      <field name="message_follower_ids" widget="mail_followers"/> 
      <field name="activity_ids" widget="mail_activity"/> 
      <field name="message_ids" widget="mail_thread"/> 
</div>
 </form>

Having done the above, your result should be like this (below) when you save a record or perform an action.



I hope this was resourceful, if you have questions you can comment below, also remember to share.

Sunday, 3 February 2019

In this tutorial, we will learn how to validate if a user belongs to a group or not. Checking or validating if a user belongs to a group can be done using the odoo technical method called has_group. The has_group is a method that is attached to the res.users model, which means you can only use this on the res.users model.

How to Check

The first thing to do is to get the Id of the user, it can either be a currently logged in user or another user, just make sure it is a res.users related field. This can be seen below;

user = self.env['res.users'].browse(self.env.uid)

After you have gotten the Id of the user, the next thing is to utilize the method has_group and that can be done against the variable user, as shown below:

if user.has_group('sale.group_analytic_accounting'):
    print("The User belongs to an Analytic Accounting Group")
else:
    print("Whoops! User does not belong to this Group")

The above shows a checkmate of the user, if the user belongs to the Sales Analytic Accounting Group, then the user will be able to perform some operations and if not, another operation is performed, but in this case the message will be printed on your terminals.

Bonus: I have created a small module, which makes you click on a button on sales orders and the button tells you, if a user belongs to the sales group_analytic_accounting group or not.  Go to Repository

Kindly share your opinion by commenting below, if this helps you, also remember to share.

Friday, 1 February 2019



In this tutorial, I will like to share my first experience when i tried installing Odoo 12, and this will be as straight forward as possible.

I assume you have already downloaded Odoo 12 and you are about to start. Now, most people start Odoo from their terminals, which is fine, whichever way is fine as long as your Odoo is running. Since your Odoo is running on the terminal, let’s get the styling error fixed:

Step 1: Face the Fear

What I mean by this is, you type in your address on your browser, for most people it is: http://0.0.0.0:8069, as for me, it is my PC name, then the 8069 port.
When you enter the web address, you will probably get this kind of error:




That’s scary right?, but relax, the solution is coming

Step 2: Kick out the Fear 

Now, it is time to kick out the fear, the first way you can do this is by installing the requirement file with the extension .txt. You can locate this by locating your odoo path and point down to where you have addons, odoo-bin etc.



You will notice from the above picture, that you have the requirement.txt file. Staying on the path on your terminal, you should install all the dependencies on the file.

You can install the dependencies by using the command line below:

sudo pip3 install -r requirements.txt



If all the dependencies are completely installed, kindly restart your server and boom the styling should be fixed.



Note: The dependency that actually fixed the styling is called libsass with the version 0.12.3 . 

I hope this solves your styling issues, if you have any question to ask, probably this did not solve your issue, kindly comment below and I will be willing to help out.

Also remember to share this.


I will be showing you how you can hide some values in your selection field to a group of users and to show the remaining values to another group of users. If you are an odoo developer, you already know how selection field works and if you are not an odoo developer, you are familiar with instances where you select from a drop down field and from a radio field, this is the way Odoo Selection field works also.
Selection field can be populated from another module but most times it is always predefined, sometimes you even extend an inherit selection field which is still predefined, here is what i mean:
fields.Selection([('service', 'Service'), ('product', 'Product')], string="Business Type")

You will realize that I already have service, product on the field and their is no way you can achieve what I will be explaining, so what do you do.

First Step: Define a Function

Defining a function can be done by anyone, but in our own case, when defining our function, you need to attach a decorator called @api.model to populate values on the field that calls the function
You will use @api.model as seen below:
@api.model
def _populate_choice(self):
    choices = [
        ('team_a', 'Team A'), ('team_b', 'Team B')
    ]
    return choices

Second Step: Call the Function

The next thing to do is to call the function on a field, and this should be a Selection field type:
sales_people = fields.Selection(string="Sales People", selection=_populate_choice, default='team_a')
You will notice that the method was called on the field and a default choice was set, that is optional though, but you should set the choices by calling the method on the attribute selection.

Third Step: Add a Condition

The aim of this tutorial is to show other choices based on a group you have already created.

And what you need to do is to check if the user model belong to a group, if the user belong to the defined group, then the other choices will be visible to the user, if not, it will be hidden.

This is how you do it:
@api.model
def _populate_choice(self):
    choices = [
        ('team_a', 'Team A'), ('team_b', 'Team B')
    ]
    if self.env['res.users'].has_group('module_name.group_id'):
        choices += [('team_c', 'Team C')]
    return choices

If you compare the method in Step #1 with this, you will notice that, I have conditioned the remaining choice, using the has_group. Now any user that belongs to the group will see "Team C"

Final Step: Make it Visible

All this we have done will be useless, if we can't see what we have done. So what you need to do is to add the field to your xml view just the way you add every other field.
<field name="sales_people" widget="radio"/>


I added the widget attribute because i want to see it in form of radio buttons, which i can remove, so the choice is yours.

Here is the result you should see, when the user is added to your group of choice and when the user is removed from the group.

User Belongs to Group



User Not in Group


I hope the guide was resourceful, kindly give your feedback as to what you feel or your experience working with selection fields