Just Odoo

Thursday 14 May 2020




I bring to you a very great opportunity to begin your desire of how you can start building an odoo module.

I understand that you might have being wondering, how do i build a module? You might have gone through so many resources, out there and you cant just combine the pieces together. You used some of these resources half way and you got lost.

Well, I have a gift for you and it is totally free. I have created a course for you and you will learn so many things about building an odoo module, you will even do a bit of practicing.

Without wasting much of your time, I will list out the course outline, after which you can drop your email for me to send you this gift, then you can watch and learn anytime you like.

Here is the course outline:
  1. Getting Started
    • Welcome
    • Install Odoo 13 on Ubuntu 18.04
    • Easy Development with PyCharm
    • PyCharm Hacks for Odoo Development
    • Module Structure and Compositions
  1. Building our First Module [Business Logic]
    • Getting the Workflow right
    • Adding our Models and Inheriting Models
    • Adding security access to models [Access Rights]
  1. Visualizing our First Module [Adding Views and Menus]
    • Visualize with Basic Views - Form, Tree and Search
    • Inheriting Views - Form and Tree
    • Add Navigation - Actions and Menus
    • Working with Data Files
  1. Adding More Menus 
    • Adding Semester
    • Course Work: Add a course Registration functionality, adding Student Name, Level, Session
    • Solution to Course Work
  1. Advance Logic
    • Creating Relationships between Models
    • Working with domains and filters
    • Understanding Odoo API: constraints, computed fields, default values and onchange 
    • Working with Wizards
  1. Advanced Views
    • Working with Calendar View
    • Adding Search View
    • Working with Gantt and Graph View
  1. Security
    • Creating Security Groups
    • Assigning Groups to Users and Limiting Access to Fields and Menus
    • Limiting Record Access using Record Rules 
  1. Internalization
  2. Creating your PDF Report (QWeb)
  3. Automation, Workflows and Emails
    • Creating Automated actions 
    • Working with Workflows
    • Creating Email Template
  1. Odoo Web Services
    • XML-RPC Library
Visit the main blog to get more details about it - TheOdooGuy






















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

Friday 13 October 2017



Hi Odoo Developers,

In this tutorial i will teach you how to use Xpath expression. Xpath expressions give you the ability to add new pages, groups, fields, to an already existing view.

Adding pages, groups and fields to an existing view is not really complicated, but involves more codes unlike adding more key values to a selection field.

The odoo standard way of adding xpath is simply through this format;

<xpath expr="//element[@name='ElementName']" position="yourPosition"/>

To do this,

Step 1: Inherit Existing Model and Create New Fields

To add fields to an existing model, you need to inherit an existing model and add more fields to the model. For the sake of this tutorial, I will be using the sale.order model



Step 2: Inherit Existing View

To inherit an existing view means, you have to call up the existing model with the id as the ref just like in the code below.


Adding Page to an Existing View

To add a new page to the sale.order model, you need to get the name or id of the existing page. For example,  on the Sale Order, the Pages available are Order Lines and Other Information. We will add a new page between the Order Lines and the Other Information, and call the new page New Page and I will add a new field, so the page won't be empty.



In the format above, you will notice there is //element[@name='ElementName'] but in the code no @name='ElementName' was found, that's because the page does not have a name and you can't use the string on a page to add a new page, it will throw errors. So you need to observe well.



Adding Group to an Existing View

To add group to the existing groups, all you just need is to get the path of the where the group belongs, that is why in the code i had something like this //page[3]/group/group[@name='technical'], that is, on the page you want to add the group, there are two groups, a inner group and an outer group, that's why you have two groups on the xpath.



Adding Field to an Existing View


The code shows how to add a new field called New Field after the existing field called Customer. That was simple and straight forward, just the element and the name of the field //field[@name='partner_id']



Conclusion

To wrap this up, i will like to put all the xml, changes together, for simplicity;


I hope you enjoy the tutorial. Kindly drop comment below, if you have anything to share and do kindly share.


In this tutorial, i will teach you the simplest way to get the currently logged in user in Odoo. These tutorial is based on version 8, 9 and 10.

Let's get to it...

To get the currently logged user in Odoo, i will create a small method that gets the logged in user and default the method on a field.


Now that you have the method, all you need is to default the method on a field. The field you are returning the method on, can either be Char or a Many2one field, it's your choice


If the field is Char, then you need to return record.name, as shown in the code, because the model it searches returns an id value, so you need the name to be able to get the exact value from the model.

If your field is Many2one, then you dont need to return record.name, all you need is just to return record alone, and the Many2one field will do the magic.

Now, let's put the pieces together...