Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
I am coming from a Django world, where you can create custom management commands for custom actions which for example can be put under cron jobs.
Is there something similar in Odoo? If it is possible to add a cli command in an addon, then where to put it so that it is recognized by the system?
OK. I got it working myself by analyzing the source code.
To do that you need a cli module inside your custom module. Then a python file mycommand.py inside of it.
The mycommand.py contains something like this:
# -*- coding: UTF-8 -*- from __future__ import unicode_literals from odoo.cli.command import Command
"""Run a custom command"""
def run(self, args):
print "Custom command 'mycommand' worked.\n"
To get it correctly imported, you need the following in the __init__.py of your module:
from . import cli
And then you need the following in the cli/__init__.py:
To run the custom command, you need to type:
$ odoo --addons-path=/absolute/path/to/my/custom/addons mycommand
custom command 'mycommand' worked.
Here the custom command name "mycommand" is the lowercase name of the class inheriting from Command, i.e. "MyCommand". Note that the order of parameters passed to the odoo script matters: if you put the --addons-path after the custom command name, it won't work.
Interestingly, if you want to also pass odoo configuration to the command, it should go at the end of your parameters like this:
$ odoo --addons-path=/absolute/path/to/my/custom/addons mycommand -c odoo.conf
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 11/21/16, 2:30 PM|
|Seen: 399 times|
|Last updated: 11/21/16, 4:03 PM|