No more console.log()

Image for post
Image for post
MORE ducks for debugging!!! Photo by JOSHUA COLEMAN on Unsplash

In my previous story, I’ve shown you the ease of debugging Python code from Odoo project. For three months ago, understanding this knowledge is more than enough for me to master tracking and suspecting bugs from the particular code’s part. But for now? Unfortunately, IT’S NOT. Maybe yeah it’s enough when the next plan of my development is completely not related to Javascript (JS). In the reality, I can’t be sure about that. I have to know how to debug JS too because when you can’t, it means that I’ve set a limit to myself. And I don’t wanna be that. …


Only show a list of data that you want to show in Odoo

Image for post
Image for post
Photo by Alex Block on Unsplash

Whenever I want to filter the list in many2many field, I just need to add a domain into that field in Python file or in XML side. For example, I want to show only locations used for internal purposes. So I add domain=[(’usage’, ‘=’, 'internal’)] into Python field or domain=”[(’usage’, ‘=’, ‘internal’)]” into XML field. But that is just one simple/plain filtering. What if I want to filter more than one condition AND based on value of another field, can Odoo handle it easily too?

Limitation

Unfortunately, it can’t. Odoo can’t handle dynamic filtering based on another field. At least not in provided syntax template. But, it turns out there is a way to get the job done. …


An easy syntax and its comparison to the original query

Image for post
Image for post
Querying is just like searching for a specific book in a LARGE library. Photo by Tobias Fischer on Unsplash

The more complex the system I created, the more complex the way I need to get my data. This also happens when I need to create/write data because its field relation has too complicated. This sort of problem often just appears in the middle of development. Many frameworks have poor handling template syntaxes. So what I need to do?! Thank god, Odoo syntax is completely readable. I just need to type one-or-two word to do it. Let me show you the ease.

Create

Basic operation starts with Create as it is the first letter in CRUD (Create Read Update Delete). When I want to call create method of a model from its own model, I just have to type self.create(vals_list)


No more print()

Image for post
Image for post
Rubber Duck Debugging. Photo by Timothy Dykes on Unsplash

For you that have been work in a computer-related field, certainly feel familiar with debugging term. It is the process of finding where and how bugs ‘accidentally’ created in the system so then we can resolve it. We can use the manual way or the automatic way. For the latter, there are so many tools to do it, usually be distinguished by its programming language base.

In Odoo (that uses Python as its base), there are few tricks we can use.

Odoo Debug

Odoo has provided us a series of tools like: check metadata of a record, view UI (form, list) id, showing field name while hovering until it can show some part of the XML code that responsible for viewing. All of that can be accessed by activating debugging mode. …


Handle various import for many occasions

Image for post
Image for post
Where should I place my extension in the world full of Spaghetti Code? Photo by Immo Wegmann on Unsplash

Odoo has provided us an easy way to import data from excel or CSV file. It can be accessed from all of existing tree’s menu. I just need to click import button, select a file, and then import. Just like that.


That refers to filtered records in Odoo

Image for post
Image for post
Photo by Juan Gomez on Unsplash

There are two easy ways to create Smart Button in Odoo. Object type and Action type. The difference is just the place of the logic code will be written. This button is created to call records of selected database table from the current place. Also when I call it, I can filter the records so the shown list will be just the one that accept a few condition.

Smart button is located in the top-right form Odoo.


Odoo report and form modification

Image for post
Image for post
Photo by Tuân Nguyễn Minh on Unsplash

In a rapid development, I often use the existing template/framework and then modify/create new only if the existing feature doesn’t meet the requirement. This way can be applied to Odoo too. But how? Let’s take an example to modify a form and a report.

Modify Form

I want to add new field in existing form of Transfer. First, I write this code in existing model (or can be in new model).

class StockPickingInherit(models.Model):
_inherit = 'stock.picking'

send_by = fields.Char(
string="Dikirim Oleh"
)

Create new object that inherit stock.picking then define new field (i.e. send_by) .

For XML view, same with model, I write in existing view (or can be in new view). …


Or you can called him Jono Terbakar

Image for post
Image for post
Photo by Jacek Dylag on Unsplash

Burning Jono (Jono Terbakar) is a band/soloist from Yogyakarta, Indonesia that initiated on 2013 by Nihan Lanisy. So far, he has released 22 albums. So it’s not too exaggerated if I call him as the most productive musician, whether is good or not. But hey, the music is limitless. If you can’t see the unique side or the catchy/funny song of him, maybe you are not the targetted market.

He dedicated himself as the rich unemployment (translate: pengangguran berpenghasilan tinggi), not the freelancer musician. …


For modifying the exists or just creating a whole new one

Image for post
Image for post
Photo by Oliver Hae on Unsplash

Odoo Structure

First, I learn about structure of an Odoo module. Here’s the summary.


A better way to develop

Image for post
Image for post
Photo by Yancy Min on Unsplash

In the beginning, I’m developing Odoo modul with my basic IDE VS Code. But when I know that there is a better way to do with PyCharm Python IDE, I try it immediately. This is how I done.

If you need to know how I install odoo 12 in ubuntu 18.04, you can check my previous story.

Setup Run Configuration

In daily basis, I often to run stop re-run my Odoo to see the change that i made. If I did it with manual way in terminal, it will be too much time consuming. Luckily there is easy way to do.

  • First, install PyCharm and…

About

Amirul M.

Tech writer. Currently about Odoo development

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store