27
votes

I read here that you can scaffold a module using a command, so you won't need to manually create some initial files. But such command does not work on master (on Odoo development branch):

./oe scaffold Academy ../my-modules

Because there is no such file called oe in openerp directory. Did this thing change in the newest version? How can I scaffold a module in Odoo?

17
Please tell me on which path you are writing this command. Because previously it was written on server directory but now oe file is available in the odoo directory so if you have downloaded from github.com/odoo/odoo then it will show you oe file in odoo itself.Bazzinga...
Yeah, I downloaded from there. And tried to run from odoo, but there is no such file called oe. How should I run from odoo directory?Andrius
Sorry to say but it is not yet updated in odoo/odoo, but if you want to just learn then you can use old openerp from here, Server:code.launchpad.net/~openerp/openobject-server/trunk Addons:code.launchpad.net/~openerp/openobject-addons/trunk Web:code.launchpad.net/~openerp/openerp-web/trunkBazzinga...
Thanks for update. Well the point is I want to learn all new stuff that is in Odoo :). So I guess I'll need to manually create initial files or write some script myself.Andrius

17 Answers

32
votes

Now odoo 10 or later version use odoo-bin insted of odoo.py

  1. On the shell or terminal, change directory to your odoo folder. Maybe it's in /opt/odoo, or maybe it's in /home/odoo :

    cd /opt/odoo
    
  2. Create a new module using the odoo.py script:

    ./odoo.py scaffold my_new_module ./addons/
    

(where my_new_module is a name of your new module, and ./addons/ is the Odoo addons directory)

  1. Edit the ./addons/my_new_module/__openerp__.py file.

    nano ./addons/my_new_module/__openerp__.py
    
  2. Change the name field to set a user friendly name of your module (for example "Andrius's New Module"). Change description and fields also. And add your needed modules, such as 'mail', to the to the list of module dependencies depends.

    'depends': ['base', 'mail'],
    
  3. Edit models.py

    nano ./addons/my_new_module/models.py
    
  4. Add code in your my_new_module/models.py file, for example:

from openerp import models, api

class FooterlessNotification(models.Model)
    _inherit = 'mail.notification'

    @api.model
    def get_signature_footer(self, user_id, res_model=None, res_id=None, context=None, user_signature=True):
        return ""

(As an example, this code will extend the 'mail.notification' model and replace its get_signature_footer method with one that returns an empty footer.)

  1. Install your module via Odoo settings.

To find it there you may need to use the "Update Module List" option.

If you can't find the option "Update Module List" either, you may need to enable the "Technical Features" checkbox in your current user's settings.

To display Modules, not just the Applications, remove the tag "Applications" from the search box filter, by clicking the small "x" before the tag.

8
votes

You can use ./odoo-bin scaffold MODULE_NAME PATH_TO_STORE_YOUR_MODULE_OR_ADDONS

For example: ./odoo-bin scaffold module_name /odoo/odoo-server/custom_addons/

Here custom_addons is your directory in odoo-server/

cmd in Odoo10:

./odoo-bin scaffold <module_name> <destination path where you want to create> 
5
votes

Use odoo.py instead of oe:

./path/to/odoo/odoo.py scaffold my-module
1
votes

From odoo documentation correct way to create a module is following:

odoo.py scaffold [name of module] [desired path of module]

Also I recommend you to use different addons path for your module and don't use odoo/addons, you can create a new directory where you want and then add this directory to odoo configuration or execute odoo with this addon from launch

odoo.py --addons-path=[full path to your dir]
1
votes

I have installed ODOO 9 in AWS in the directory /opt/odoo.

So first I change directory:

 cd /opt/odoo

then executed:

 odoo.py scaffold modulename ./addons/

gives the following error msg:

 odoo.py command not found

the correct command that works for me is:

 sudo python odoo.py scaffold modulename ./addons/

Hope this helps.

1
votes

./"path to odoo.py file"/odoo.py scaffold my-module ./"path for your new addon"/

replace qoutes with your path

0
votes

Another version

\###### begin ########

import sys

from openerp.cli import scaffold

sf = scaffold.Scaffold()

sf.run (sys.argv[1:])

\####### end #########

Save the script at the top to your openerp folder. Then execute with:

$ python (your-script-name) --help

or:

$ python (the-script-name) --init Academy --dest my-modules --model academy --controller academy --web --theme
0
votes

Did you install as source or package.

For source you need to do

./odoo.py scaffold [module_name] [where_to_put_it]

if from package you need to do

 odoo.py scaffold [module_name] [where_to_put_it]

[where_to_put_it] usually is your addons path, your addons path may vary according to your install method.

It is not necessary to create the module in the addons folder. But it is recommended to do so.You can add the new addons path by

odoo.py --addons-path=[where_to_put_it]

For Module structure reference and for building a module.

0
votes

In some cases, it is necessary to pass the Odoo python file to the Python application to execute.

python odoo.py scaffold modulename addons-path
0
votes

I suggest you for the first step to Git clone odoo. Create a directory/folder and you Git clone odoo on your directory/folder. After that run, Python odoo.py scaffold addons test123. Put or module on directory/folder addons for make sure, odoo can be read your module.

0
votes

Goto Terminal and enter the following command:

cd path/to/your/odoo-version/

./odoo-bin scaffold new_module /path/to/your/odoo-version/addons

Then goto /path/to/your/odoo-version/addons and refresh, you can see the "new_module" will be present.

0
votes

Ifyou are using odoo-10 or 11 then intead of using ./oe scaffold Academy ../my-modules use : ./odoo-bin scaffold new_module /path/to/your/odoo-version/addons

and if you are using odoo8 i.e. openerp8 then use odoo.py scaffold <module name> <where to put it>

but make sure you are on the correct location in the directory. Also find tutorial here in the link : https://www.odoo.com/documentation/8.0/howtos/backend.html

--Thanks

ABhay S

0
votes

Here is my answer

cd path/to/odoo/odoo-server/

then

./odoo-bin scaffold new_module_name /path/to/custom/addons

now check /path/to/custom/addons, you will see new module where you can start adding you things.

0
votes

First Change the directory where your odoo source: /opt/odoo

Then write this command: ./odoo-bin scaffold my_module_name /path-where-to-create

Example: ./odoo-bin scaffold odoo_module /Desktop/Repository

0
votes

My file structure :-

Odoo |-- addons |-- debian |-- doc |-- setup |-- odoo-bin

To use the scaffold, you have to cd to (Odoo) folder then use this command

python3 odoo-bin scaffold name_of_your_module path_of_your_module

if i want to create a module named test at odoo/addons

i would just use the command :-

python3 odoo-bin scaffold test odoo/addons

Note:-

  • I haven't included every folder in the file structure, it was just to give you an idea
  • (python3) here depends on your python version
0
votes

In Odoo v14 istalled on ubuntu 20.04 I use

odoo scaffold module_name /opt/extra-addons
-2
votes

May be this code would help. Save it as moe.py or whatever you wanted.

from openerp.cli import scaffold

sf = scaffold.Scaffold()

#sf.run(["--help"])

sf.run (["--init","Academy","--model","academy","--controller","academy","--web","--theme"])

I'm still new to Python programming. If someone could improve the way to send arguments to the run() function, that would be great.