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...

Thursday 12 October 2017



To the Odoo developers out there, i know some of you already have your editors, you use to develop your modules, which is perfectly okay, but for those who are thinking of using PyCharm to develop modules. I will walk you through how to set PyCharm up for easy development.

If you don't know PyCharm, you should probably check this out their website and how to install pycharm. It's a very cool editor i use for development both for Odoo and Django.

Enough of the talk...Let me walk you through the process of setting up Odoo after installing Pycharm

Step 1: Install Odoo Dependencies 

To install odoo dependencies on any linux machine, ubuntu especially. 

You need to follow some process, this process is applicable to any version of Odoo you want to use later on.

Check out this to install the necessary dependencies you need to keep Odoo working.

Once these dependencies are installed, then you can proceed to the next step.

Step 2: Download Odoo

Download Odoo 10 or 11 from her repository, make sure you select the right branch after that unzip the file.





Step 3: Launch PyCharm and Open the Odoo folder

Once you launch PyCharm, make sure you open the version of Odoo you downloaded. Take note of the location where you unzipped the Odoo version and what you should be seeing must be similar to this.



Step 4: Run the Odoo Server

To run the Odoo server, navigate to the python file called odoo-bin, right click on the file and select "Run odoo-bin" or use the keyboard shortcut Ctrl+Shift+F10.

Now your server should be running after the command


Navigate to your favorite browser, use http://localhost:8069/ to load up your odoo version.



Note this is also applicable to Odoo version 11, so you have no problem using Odoo 11 on your machine.

Conclusion

I hope you found this resourceful, kindly drop your reactions on the comment box and feel free to share across.

Tuesday 10 October 2017



You might have ever wondered how to add more keys to an existing selection field in Odoo, well the truth is its very easy and i will put you through that in this tutorial.

This tutorial is assumed you know how to develop a module and add the necessary dependencies in the __manifest__.py file.

So for the purpose of this tutorial, we will make changes on the product model in the sales module, and whatever is done here can be replicated in any instance, in any module, you are trying to add more selection keys.


Step 1: Get the model, where you want to add your selection key. 



This the product form and the model name is template.product , we are adding more keys to the Product Type field.

In the Product Type field, we have Consumable,  Service and Stockable Product, just as shown below...



The essence of this above illustration is to fully understand what we have on ground, so we can be able to add what we want. So i hope we are on the same page. Let's move to the code part.

Step 2: Coding out our Wish

Now that we are ready to code what we want.

Open your editor, create or edit your python file and add this.

The last part of the code, does that magic

Now, load your server and install the module or refresh your browser and the changes has been done, just as you can see below;


Conclusion

You can see the process was short and easy, just with selection_add, and this usually used in odoo 10, if you search through other versions of odoo, you will barely see them, but you can also use the selection_add in version 9.

If you find this tutorial helpful, kindly comment below and share.