Odoo role uses the vars odoo_role_odoo_core_modules
and odoo_role_odoo_community_modules
to ensure that the given set of modules are installed and recognized by Odoo.
This vars, however, were introduced after several servers were instantiated, so those remained with “local changes” not reflected in their Ansible inventories. To rectify this situation, and as a handy tool in other situations, it’s useful to have a quasi-automated task to retrieve those lists.
Odoo is highly modular because many of its features come packaged in modules, which one can install and install. However, it’s worth to say that there’s no easy way to completely remove an already installed module, it may leave traces in the database.
We can split modules by mantainers: official and community.
Once present in the system and within the reach of Odoo, Odoo database needs to be updated to “discover” the new modules. This can be achieved via:
odoo_bin -c odoo.conf -d odoo_db --update all --stop-after-init --without-demo=all
Once Odoo knows about this module, we can already install it:
odoo_bin -c odoo.conf -d odoo_db --init "one_module,another_module" --stop-after-init --without-demo=all
# log in to your odoo instance server
ssh myuser@my_odoo_server
# become the user with which odoo is run
sudo su - odoo
cd /opt/odoo
# load the python virtual environment
source /opt/.odoo_venv/bin/activate
# create and enter a work directory
mkdir workdir
cd workdir
We filter out anything that doesn’t look an odoo module judging by its name. All OCA modules follow this pattern: odoo<VERSION_MAJOR>-addon-<MODULE_NAME>
pip freeze | \
egrep '^odoo11-addon' | \
tee requirements.txt
Sample output:
odoo11-addon-account-banking-mandate==11.0.1.2.2
odoo11-addon-account-banking-pain-base==11.0.1.0.0
odoo11-addon-account-banking-sepa-credit-transfer==11.0.1.0.0
odoo11-addon-account-banking-sepa-direct-debit==11.0.1.0.2
odoo11-addon-account-due-list==11.0.2.0.0
odoo11-addon-account-financial-report==11.0.1.2.0
odoo11-addon-account-payment-mode==11.0.1.0.1
odoo11-addon-account-payment-order==11.0.1.2.1
odoo11-addon-account-payment-partner==11.0.1.2.1
odoo11-addon-base-bank-from-iban==11.0.1.0.0
odoo11-addon-base-technical-features==11.0.1.0.0.99.dev3
odoo11-addon-contract==11.0.2.1.0
odoo11-addon-contract-sale-invoicing==11.0.1.0.0
odoo11-addon-contract-variable-quantity==11.0.1.2.1
odoo11-addon-date-range==11.0.2.0.1.99.dev8
odoo11-addon-l10n-be-mis-reports==11.0.1.1.0.99.dev21
odoo11-addon-mis-builder==11.0.3.3.0
odoo11-addon-project-stage-closed==11.0.1.0.0.99.dev7
odoo11-addon-project-timesheet-time-control==11.0.1.2.0.99.dev3
odoo11-addon-report-xlsx==11.0.1.0.3
odoo11-addon-web-no-bubble==11.0.1.0.0
odoo11-addon-web-responsive==11.0.1.0.2
odoo11-addon-web-searchbar-full-width==11.0.1.0.0
odoo11-addon-web-widget-color==11.0.1.0.0
Start format:
odoo11-addon-web-responsive==11.0.1.0.2
odoo11-addon-web-searchbar-full-width==11.0.1.0.0
odoo11-addon-web-widget-color==11.0.1.0.0
Goal format:
odoo_role_odoo_community_modules: "web_responsive,web_searchbar_full_width,web_widget_color"
(notice the change from dash to underscore)
Starting from requirements.txt, we want to:
cat requirements.txt | \
sed -r 's/odoo11-addon-([^=]+)==.+/\1/' | \
tee odoo-community-modules.txt | \
tr '\n-' ',_' | \
echo "odoo_role_odoo_community_modules: \"$( cat )\"" | \
sed 's/,"$/"/' | \
tee odoo-community-modules.yml
As a result, we get 2 files:
odoo-community-modules.txt
: debug file with one module per line. Don’t delete it, we’ll need it later.odoo-community-modules.yml
: yml file with just one line, defining a variable as a string, in a format such that odoo-bin recognizes it as a set of modules to install.Sample output:
# odoo-community-modules.txt
account-banking-mandate
account-banking-pain-base
account-banking-sepa-credit-transfer
account-banking-sepa-direct-debit
account-due-list
account-financial-report
account-payment-mode
account-payment-order
account-payment-partner
base-bank-from-iban
base-technical-features
contract
contract-sale-invoicing
contract-variable-quantity
date-range
l10n-be-mis-reports
mis-builder
project-stage-closed
project-timesheet-time-control
report-xlsx
web-no-bubble
web-responsive
web-searchbar-full-width
web-widget-color
# odoo-community-modules.yml
odoo_role_odoo_community_modules: "account_banking_mandate,account_banking_pain_base,account_banking_sepa_credit_transfer,account_banking_sepa_direct_debit,account_due_list,account_financial_report,account_payment_mode,account_payment_order,account_payment_partner,base_bank_from_iban,base_technical_features,contract,contract_sale_invoicing,contract_variable_quantity,date_range,l10n_be_mis_reports,mis_builder,project_stage_closed,project_timesheet_time_control,report_xlsx,web_no_bubble,web_responsive,web_searchbar_full_width,web_widget_color"
Core modules, as far as we know, are only available to list by directly querying the database. Here we asume:
postgres
to run the DBInside the odoo
database, we query ir_module_module
table, and filter out by column state
. This table will contain also available modules (discovered), but not installed. However, community modules will appear indistinctly from the core ones. This is why we can make use of the txt list of community modules: to compare both lists and substract the repeated ones.
We switch back to our sudoer user:
exit
Move again to the workdir, query the database, and parse the output:
TODO work on the SQL to extract the list we want directly
cd ~odoo/workdir &&
sudo -u postgres psql -t \
-d odoo \
-c "SELECT name
FROM ir_module_module
WHERE state = 'installed';" | \
tr -d ' ' | \
sort | \
grep -v "^$" | \
sudo -u odoo tee odoo-all-modules.txt
So this is a list of all modules, both core and community. Next, we are going to “substract” the community ones, by comparing with the file generated before.
But first switch back to odoo user:
sudo su - odoo
cd workdir
comm -2 -3 \
odoo-all-modules.txt \
odoo-community-modules.txt | \
grep -v "^$" | \
tee odoo-core-modules.txt | \
tr '\n-' ',_' | \
echo "odoo_role_odoo_core_modules: \"$( cat )\"" | \
sed 's/,"$/"/' | \
tee odoo-core-modules.yml
Sample output:
# odoo-core-modules.txt
account
account_analytic_default
account_asset
account_banking_mandate
account_banking_pain_base
account_banking_sepa_credit_transfer
account_banking_sepa_direct_debit
account_bank_statement_import
account_cancel
account_cash_basis_base_account
account_check_printing
account_due_list
account_financial_report
account_invoicing
account_payment_mode
account_payment_order
account_payment_partner
analytic
auth_crypt
auth_signup
barcodes
base
base_automation
base_bank_from_iban
base_iban
base_import
base_setup
base_technical_features
base_vat
base_vat_autocomplete
board
bus
contacts
contract_sale_invoicing
contract_variable_quantity
date_range
decimal_precision
document
fetchmail
hr
hr_timesheet
http_routing
iap
l10n_be
l10n_be_mis_reports
l10n_generic_coa
l10n_multilang
l10n_us
mail
mis_builder
payment
payment_transfer
portal
procurement_jit
product
project
project_stage_closed
project_timesheet_time_control
report_xlsx
resource
sale
sale_management
sales_team
sale_stock
sale_timesheet
sms
stock
stock_account
web
web_diagram
web_editor
web_kanban_gauge
web_no_bubble
web_planner
web_responsive
web_searchbar_full_width
web_settings_dashboard
web_tour
web_widget_color
# odoo-core-modules.yml
odoo_role_odoo_core_modules: "account,account_analytic_default,account_asset,account_banking_mandate,account_banking_pain_base,account_banking_sepa_credit_transfer,account_banking_sepa_direct_debit,account_bank_statement_import,account_cancel,account_cash_basis_base_account,account_check_printing,account_due_list,account_financial_report,account_invoicing,account_payment_mode,account_payment_order,account_payment_partner,analytic,auth_crypt,auth_signup,barcodes,base,base_automation,base_bank_from_iban,base_iban,base_import,base_setup,base_technical_features,base_vat,base_vat_autocomplete,board,bus,contacts,contract_sale_invoicing,contract_variable_quantity,date_range,decimal_precision,document,fetchmail,hr,hr_timesheet,http_routing,iap,l10n_be,l10n_be_mis_reports,l10n_generic_coa,l10n_multilang,l10n_us,mail,mis_builder,payment,payment_transfer,portal,procurement_jit,product,project,project_stage_closed,project_timesheet_time_control,report_xlsx,resource,sale,sale_management,sales_team,sale_stock,sale_timesheet,sms,stock,stock_account,web,web_diagram,web_editor,web_kanban_gauge,web_no_bubble,web_planner,web_responsive,web_searchbar_full_width,web_settings_dashboard,web_tour,web_widget_color"
Finally, we have odoo-core-modules.yml
too. The file odoo-core-modules.txt
is generated for convenience and consistence.
Unwrapping it all, remember that this files are generated at the Odoo server. In order to include them to an inventory, we may either download them to the dev machine, or just “cat n copy” their content.
When finished, please remove ~odoo/workdir
.