How to Change Default Sorting of Odoo Shop Catalog
Setting the default sorting order for the catalog of products in the shop
Sooner or later, users of Odoo ERP system for website shopping may need to have a preffered default sorting order for the website product catalog.
Default sorting pattern
By default products seem to be randomly arranged; but in its real sense, the default is that products are sorted in an order that reads published>>sequence>>name. In other words:
- All product are first grouped into two fractions, the published ones comes first while the unpublished ones are pushed to the end and only shown to internal users.
- Within each fraction, products with lower sequence value comes first followed by higher ones in ascending order
- Products with the same sequence are alphabetically arranged.
Set the default sorting pattern
From the foregoing, the easiest way may be to make sure the sequence is in the desired order. If the sequence can't be ascertained to be in the desired order then read on.
Disclaimer: This post is just to show how the aforestated feature can be achieved and I will be editing the actual Odoo file; generally, it is always considered a good practice not to modify an Odoo file but through a custom module.
That said, choose your ooperating system:
Linux
Windows
- Launch your terminal
- cd to your Odoo installation directory
- just to make sure you have the write access, do
sudo su
- with your preferred editor, in my own case I will be using vim, open the main.py file in the location
addons/website_sale/controllers/main.py
Thus, I will dovi addons/website_sale/controllers/main.py
search for
url = shop
: in vi/url = shop
HitEnter
, theni
to change the mode to INSERTAfter the Matching line Sort as needed, for alphabetically ascending order do:
if "order" not in post: post["order"]="name asc"
Save and exit. Press Esc to change the mode Type
:wq
to save and exit in vimRestart the server:
/etc/init.d/odoo restart
Done
- Open any text editor
- open the odoo installation directory and locate
server\odoo\addons\website_sale\controllers\main.py
.
In my case, the path isC:\Program Files (x86)\Odoo 12.0\server\odoo\addons\website_sale\controllers\main.py
- search for
url = shop
- After the Matching line Sort as needed, for alphabetically ascending order do:
if "order" not in post: post["order"]="name asc"
Save and exit.
Restart the server:
- Go to services
- Search for the odoo server, mine is odoo-server-12.0
- Select an click restart in the left pane
Done