How it works...

To provide some context, an Odoo addon module can have three types of files:

  •  The Python code is loaded by the __init__.py files, where the .py files and code subdirectories are imported. Subdirectories containing code Python, in turn, need their own __init__.py.
  • Data files that are to be declared in the data and demo keys of the __manifest__.py module manifest in order to be loaded are usually XML and CSV files for the user interface, fixture data, and demonstration data. There can also be YAML files, which can include some procedural instructions that are run when the module is loaded, for instance, to generate or update records programmatically rather than statically in an XML file.
  • Web assets such as JavaScript code and libraries, CSS, and QWeb/HTML templates also play an important part. There are declared through an XML file extending the master templates to add these assets to the web client or website pages.

The addon files are to be organized in these directories:

  • models/ contains the backend code files, creating the Models and their business logic. A file per Model is recommended, with the same name as the model, for example, library_book.py for the library.book model. These are addressed in depth in Chapter 5, Application Models.
  • views/ contains the XML files for the user interface, with the actions, forms, lists, and so on. As with models, it is advised to have one file per model. Filenames for website templates are expected to end with the _template suffix. Backend views are explained in Chapter 10, Backend Views, and website views are addressed in Chapter 16, CMS Website Development.
  • data/ contains other data files with module initial data. Data files are explained in Chapter 7, Module Data.
  • demo/ contains data files with demonstration data, useful for tests, training, or module evaluation.
  • i18n/ is where Odoo will look for the translation .pot and .po files. Refer to Chapter 12, Internationalization, for more detail. These files don't need to be mentioned in the manifest file.
  • security/ contains the data files defining access control lists, usually a ir.model.access.csv file, and possibly an XML file to define access Groups and Record Rules for row level security. Take a look at Chapter 11, Access Security, for more details on this.
  • controllers/ contains the code files for the website controllers, and for modules providing that kind of feature. Web controllers are covered in
    Chapter 14, Web Server Development.
  • static/ is where all web assets are expected to be placed. Unlike other directories, this directory name is not just a convention, and only files inside it can be made available for the Odoo web pages. They don't need to be mentioned in the module manifest, but will have to be referred to in the web template. This is discussed in detail in Chapter 16, CMS Website Development.
When adding new files to a module, don't forget to declare them either in the __manifest__.py (for data files) or __init__.py (for code files); otherwise, those files will be ignored and won't be loaded.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.253.62