Api Objects#

class odoo_tools.api.objects.CompanySpec(country_code)[source]#

This class represent a company object.

This object can be used along database initialization. When creating a new database, it is possible to configure the main company before installing more modules. One example where the company is particularly important is when you attempt to install the account module.

Without a valid company, Odoo will try to install a default l10n module for accounting for a locale that you would likely not use.

When a company object is provided to the database initialization, it will start by initializing the database with the base module.

Then when the base module is installed, it will update some objects like the res.company and then it will install other modules that were requested to be installed for the database initialization.

country_code#

Country code based on the Alpha-2 of the ISO 3166-1 code.

Type:

str

class odoo_tools.api.objects.Manifest(path, attrs=None, manifest_file=None)[source]#

Manifest Object

The manifest object contains data stored in odoo/openerp manifests.

_attrs#

Data of the manifest file. You can see the whole set of attributes in the odoo documentation.

Type:

dict

path#

The path in which the manifest got loaded.

Type:

Path

_manifest_file#

The path of the manifest file of this manifest if it was loaded from a path. If the path of the manifest wasn’t provided, it defaults to the filename __manifest__.py in the path of the module.

technical_name#

This attribute is stored into the _attrs but is defined as the module name. The name attribute in a manifest is just a name that will then get loaded in odoo. The technical name is the unique identifier for the module path in the addons paths.

checksum()[source]#

Computes the checksum of the module itself. This can later be used to check if the module has changed and force an update of the module as the version that is installed doesn’t match the one on the filesystem.

defaults = {'application': False, 'data': <class 'list'>, 'demo': <class 'list'>, 'depends': <class 'list'>, 'external_dependencies': <class 'dict'>, 'installable': True, 'version': '0.0.0'}#
disable()[source]#

Set the manifest as uninstallable.

export_translations(db, languages)[source]#

Exports translation in the corresponding module’s path.

It will store all potential translations into the i18n folder of the corresponding module.

Parameters:
  • db (DbApi) – the api used to access the database.

  • languages (list(str)) – list of locales to export.

Returns:

Nothing

files()[source]#

Yields all file located in the module’s folder.

Iterating over this iterator yields all file in the module’s folder except pyc files or potentially other files that aren’t considered as “sources”. It will also yield files located in the static folder.

classmethod from_path(manifest, render_description=False)[source]#

Loads the manifest from a given path.

It automatically define the module name to the path name of the folder in which the manifest is located to those attributes:

  • name

  • technical_name

A custom attribute description_html can be generated to store the rendered html description.

Parameters:
  • manifest (Path) – The path of the manifest or module.

  • render_description (bool) – Set to True if you need to render the description.

Returns:

The manifest that was loaded.

Return type:

Manifest

package()[source]#

Returns a file handle to a zipfile of the packaged module.

This methods will generate a zip file based on the result of a call to self.files().

The zipfile will get destroyed once it is closed or garbage collected.

Returns:

A file handle containing the zipped module.

Return type:

File

properties = {'_attrs', '_manifest_file', 'path'}#
remove()[source]#

Remove the module from the file system.

It will attempt to remove the folder in which the manifest is located.

If the directory doesn’t exist, it does nothing. If the directory does exist. It will try to remove all files located in the module folder recursively.

requirements(package_map=None)[source]#

Return a list of packages required by module.

save()[source]#

Saves changes made to the manifest in python.

All changes will be dumped into the original manifest file or in __manifest__.py.

set_attribute(attribute, value)[source]#

Set attribute to a value.

This is a shortcut method to set attributes in a nested dict.

manifest.set_attribute(
    ['external_dependencies', 'python'], ['request']
)
assert manifest.external_dependencies['python'] == ['request']
Parameters:
  • attribute (list(str)) – List of attribute key to set

  • value (any) – Value to set to the attribute path

set_defaults()[source]#

Set some defaults when initializing an object.

It uses the values as defined in Manifest.defaults. If a value is already present in self._attrs, it will not update the value from the defaults.

static_assets()[source]#

Returns static asset files.

This lookup all files in the static folder of the current module/manifest. It will return all files without exceptions.

This can be mainly used to lookup for static assets of specific modules. For example, you’d want to upload all static assets somewhere else or you’d want to preprocess static assets before deployment.

Returns:

A list of files static subdirectory

Return type:

list(Path)

values()[source]#

Returns the manifest’s properties.

odoo_tools.api.objects.get_translation_filename(language, module)[source]#

Get the filename for translation file.

When no language is provided to translate a module, the name of the file will the name of the module as a pot file.

For example, exporting the pot file for module bus would be exported by calling:

get_translation_filename(None, 'bus')
>> 'bus.pot'

When exporting the translation file for fr_FR language for the module bus. It will return the family of the language as the langage and dialect are the same.

get_translation_filename('fr_FR', 'bus')
>> 'fr.po'

If the language and dialect are different it returns the language locale as is.

get_translation_filename('fr_CA', 'bus')
>> 'fr_CA.po'
Parameters:
  • language (str|None) – locale to export

  • module (str) – Name of the module to export

Returns:

The filename of the translation file based

on the arguments.

Return type:

str

odoo_tools.api.objects.try_compile_manifest(data)[source]#

Attempt compiling the manifest.

In some specific cases, if the literal eval doesn’t work. It can provide more information to compile the manifest and evaluate its content.

As manifest file are python modules, it is technically possible to import or use python code directly within the manifest file.

In that case a simple literal_eval wouldn’t be enough. That said, this evaluator should never be used.

Parameters:

data (str) – Content of the manifest to load

Returns:

The parsed data of the manifest.

Return type:

dict

odoo_tools.api.objects.try_parse_manifest(data)[source]#

Attempt parsing a manifest.

It used the literal_eval native function to attempt parsing a manifest.

Parameters:

data (str) – Content of the manifest to load

Returns:

The parsed data of the manifest.

Return type:

dict