Read Odoo Source Code : Delivery Order Journal Entry

This article is the second part of the Read Odoo Source Code thread series. This time I will discuss how to find a source code snippet that responsible to create a journal entry when a Delivery Order is validated.

To follow this article, make sure you have a product with the Inventory Valuation value is Automated. To check this setting, open your master product then click the Product Category field. The image below is an example of how to set up Inventory Valuation on my odoo installation.

Next, open one of the python file on your original odoo module or source code, or on your custom module. Make sure the module where the file you open has been installed, so the code that we are going to add will be executed by odoo. Then add the code like below.

class AccountMove(models.Model):
    _inherit = 'account.move'

    def create(self, value):
        # force error if there is an activity call this method
        a = 1 / 0

On my computer, I wrote the code above in the stock module or addon, precisely in the stock/models/stock_picking.py file. The code above means, if there is a journal creation activity, where the create method of the account.move model is called, we force an error, so odoo will display a Traceback message, an error message that contain file and method that python execute until the code which causes the error. Then by read this Traceback message, we can trace what file that call the create method of the account.move model, the method that odoo call to create a journal entry.

Create a sales order, with a product that inventory valuation value is Automated. Then click the Confirm button to create a delivery order. Validate the delivery order, then an error will appear like in the image below.

Then we just have to read each file in the error message above to find the code snippet that responsible to make a journal entry. Not all files need to be read. Make sure the file that you are reading is part of a module or addon. In the picture above File “/odoo14/odoo14-server/odoo/api.py”, line 344, in _model_create_multi is not part of the module or addon that we can install or uninstall, so just ignore it.

The first file is File “/odoo14/odoo14-server/addons/stock/models/stock_picking.py”, line 25, in create . The 25th line in this file is the code I added, so it is not a code that responsible to create a journal entry. Ignore it.

Next let’s take a look at File “/odoo14/odoo14-server/addons/purchase/models/account_invoice.py”, line 102, in create , here is a screenshot of the code on my computer.

It can be seen that the code above is similar to the code that we just added, which is the code that overide the create method of account.move model. So it is not the file that responsible to create a journal entry.

Let’s take a look at the next file which is File “/odoo14/odoo14-server/addons/stock_account/models/stock_move.py”, line 457, in _create_account_move_line . here is a screenshot of the code on my computer.

Finally, we have found out the file and method that are used to create a delivery order’s journal entry. As seen from the picture above, the create method from the account.move model is called in this file. To check this, let’s change the contents of the method in this file a little, like below.

Remove the create method which caused the error that we just added before. Restart the odoo service then re-validate the delivery order. If the delivery order is successfully validated, go to the Accounting >> Accounting >> Journal Entries menu to see the journal entry that was just created. Now the reference of the journal contain the words that we just added, it’s mean the code that we change is the correct code, which is the code that responsible to create a journal entry when the delivery order is validated.

You can use this procedure to debug other methods such as the write or unlink method. Do not forget to restore all the files that we have change to their original state.

Related Article

Leave a Reply

Your email address will not be published.