### Run Odoo with Custom Theme Module Installation Source: https://www.odoo.com/documentation/18.0/developer/tutorials/website_theme/01_theming.html Use this command to start the Odoo server, specifying addon paths, database filter, and installing a custom theme module like 'website_airproof' with development XML enabled. ```bash ./odoo-bin --addons-path=../enterprise,addons,../myprojects --db-filter=theming -d theming --without-demo=all -i website_airproof --dev=xml ``` -------------------------------- ### Install Upgrade Utils with Odoo-bin Source: https://www.odoo.com/documentation/18.0/developer/reference/upgrades/upgrade_utils.html Use this command to start Odoo with the `upgrade-util` repository prepended to the `--upgrade-path` option for local development. ```bash $ ./odoo-bin --upgrade-path=/path/to/upgrade-util/src,/path/to/other/upgrade/script/directory [...] ``` -------------------------------- ### Run Odoo Server with Configuration Source: https://www.odoo.com/documentation/18.0/developer/howtos/website_themes/setup.html Example shell script command to launch the Odoo server with specified addon paths, database filters, initial module installation, and development features. ```bash ./odoo-bin --addons-path=../enterprise,addons --db-filter= -d --without-demo=all -i website --dev=xml ``` -------------------------------- ### Import Upgrade Script and Get Module Object Source: https://www.odoo.com/documentation/18.0/developer/reference/upgrades/upgrade_utils.html This example demonstrates importing an upgrade script and shows the Python module object returned by `util.import_script`. ```python >>> util.import_script("base/0.0.0/end-moved0.py", name="my-moved0") ``` -------------------------------- ### start() Source: https://www.odoo.com/documentation/18.0/developer/reference/external_api.html This operation requests a new test database from `https://demo.odoo.com/start` and returns connection details. ```APIDOC ## XML-RPC Call: start() ### Description This operation requests a new test database from `https://demo.odoo.com/start` and returns connection details. ### Method XML-RPC Call ### Endpoint `https://demo.odoo.com/start` ### Parameters None ### Response #### Success Response - **host** (string) - The hostname or IP address of the Odoo instance. - **database** (string) - The name of the newly created database. - **user** (string) - The username for accessing the database. - **password** (string) - The password for the specified user. #### Response Example ``` { "host": "https://your-odoo-instance.com", "database": "your_db_name", "user": "admin", "password": "your_password" } ``` ``` -------------------------------- ### Example Odoo Unit Test Class with setUpClass Source: https://www.odoo.com/documentation/18.0/developer/tutorials/unit_tests.html Defines an Odoo unit test class inheriting from `TransactionCase`, demonstrating `setUpClass` for shared data setup and example test methods for property actions and computations. ```python from odoo.tests.common import TransactionCase from odoo.exceptions import UserError from odoo.tests import tagged # The CI will run these tests after all the modules are installed, # not right after installing the one defining it. @tagged('post_install', '-at_install') class EstateTestCase(TransactionCase): @classmethod def setUpClass(cls): # add env on cls and many other things super(EstateTestCase, cls).setUpClass() # create the data for each tests. By doing it in the setUpClass instead # of in a setUp or in each test case, we reduce the testing time and # the duplication of code. cls.properties = cls.env['estate.property'].create([...]) def test_creation_area(self): """Test that the total_area is computed like it should.""" self.properties.living_area = 20 self.assertRecordValues(self.properties, [ {'name': ..., 'total_area': ...}, {'name': ..., 'total_area': ...} ]) def test_action_sell(self): """Test that everything behaves like it should when selling a property.""" self.properties.action_sold() self.assertRecordValues(self.properties, [ {'name': ..., 'state': ...}, {'name': ..., 'state': ...} ]) with self.assertRaises(UserError): self.properties.forbidden_action_on_sold_property() ``` -------------------------------- ### Example Predefined and Custom Tour Steps in JavaScript Source: https://www.odoo.com/documentation/18.0/developer/reference/backend/testing.html Shows examples of both predefined utility steps and custom steps with a trigger, isActive condition, and run action. Steps define the sequence of actions in a tour. ```javascript // First step tour.stepUtils.showAppsMenuItem(), // Second step { trigger: '.o_app[data-menu-xmlid="your_module.maybe_your_module_menu_root"]', isActive: ['community'], // Optional run: "click", }, { // Third step }, ``` -------------------------------- ### Odoo Configuration File Example Source: https://www.odoo.com/documentation/18.0/developer/reference/cli.html Demonstrates a sample '[options]' section in an Odoo configuration file, setting database user and filter. ```INI [options] db_user=odoo dbfilter=odoo ``` -------------------------------- ### Initialize Dashboard Items in Setup Method Source: https://www.odoo.com/documentation/18.0/developer/tutorials/discover_js_framework/02_build_a_dashboard.html Assigns a list of dashboard items to the component's `this.items` property within the `setup` method, making them available for rendering in the template. ```javascript setup() { this.items = items; } ``` -------------------------------- ### Registering a Web Tour in JavaScript Source: https://www.odoo.com/documentation/18.0/developer/reference/backend/testing.html Registers a new web tour with a unique name and an optional starting URL. This is the initial setup for defining a user journey. ```javascript import tour from 'web_tour.tour'; tour.register('rental_product_configurator_tour', { url: '/web', // Here, you can specify any other starting url }, [ // Your sequence of steps ]); ``` -------------------------------- ### Patching an Owl Component's `setup` Method Source: https://www.odoo.com/documentation/18.0/developer/reference/frontend/patching_code.html For Owl components, patch the `setup` method on the component's prototype to add custom hooks or initialization logic, leveraging the recommended best practice. ```javascript patch(MyComponent.prototype, { setup() { useMyHook(); }, }); ``` -------------------------------- ### Clone Odoo Petstore Module Source: https://www.odoo.com/documentation/18.0/developer/tutorials/web.html Use this command to download the example `petstore` module from GitHub, which contains the necessary files for this tutorial. ```bash $ git clone http://github.com/odoo/petstore ``` -------------------------------- ### Launch Odoo Server with odoo-bin Source: https://www.odoo.com/documentation/18.0/developer/tutorials/setup_guide.html Use this command to start the Odoo server, specifying the addons path and the database to use. Ensure you are in the Odoo source directory. ```bash $ cd $HOME/src/odoo/ $ ./odoo-bin --addons-path="addons/,../enterprise/,../tutorials" -d rd-demo ``` -------------------------------- ### Install Upgrade Utils via Pip Source: https://www.odoo.com/documentation/18.0/developer/reference/upgrades/upgrade_utils.html Install the `upgrade-util` library using pip on platforms where you do not manage Odoo yourself. ```bash $ python3 -m pip install git+https://github.com/odoo/upgrade-util@master ``` -------------------------------- ### Define Odoo Unit Tests with `at_install` and `post_install` Tags Source: https://www.odoo.com/documentation/18.0/developer/tutorials/unit_tests.html Use `at_install` for tests whose behavior might be affected by the installation of other modules. Employ `post_install` to run tests after all modules are installed, which can optimize CI execution time. ```python from odoo.tests.common import TransactionCase from odoo.tests import tagged # The CI will run these tests after all the modules are installed, # not right after installing the one defining it. @tagged('post_install', '-at_install') # add `post_install` and remove `at_install` class PostInstallTestCase(TransactionCase): def test_01(self): ... @tagged('at_install') # this is the default class AtInstallTestCase(TransactionCase): def test_01(self): ... ``` -------------------------------- ### Example values for ensure_xmlid_match_record in Python Source: https://www.odoo.com/documentation/18.0/developer/reference/upgrades/upgrade_utils.html These examples show dictionary structures for the `values` parameter when using `ensure_xmlid_match_record` to specify criteria for matching records. ```Python values = {"id": 123} values = {"name": "INV/2024/0001", "company_id": 1} ``` -------------------------------- ### Configuring Test Case Execution Timing Source: https://www.odoo.com/documentation/18.0/developer/reference/backend/testing.html This snippet illustrates how test cases can be configured to run at different stages, either right after module installation or after all modules have been installed. ```python ``` -------------------------------- ### Expand Braces in String Source: https://www.odoo.com/documentation/18.0/developer/reference/upgrades/upgrade_utils.html This example shows how to use `expand_braces` to generate a list of strings by expanding a single pair of braces within the input string. ```python >>> util.expand_braces("a_{this,that}_b") ['a_this_b', 'a_that_b'] ``` -------------------------------- ### Define Odoo Onboarding Tour in XML Source: https://www.odoo.com/documentation/18.0/developer/reference/backend/testing.html Example of an XML record definition for `web_tour.tour`, linking it to a JavaScript tour and configuring its behavior like sequence and completion message. ```xml your_tour 10 Congrats, that was a great tour ``` -------------------------------- ### Native JavaScript Module with Import/Export Source: https://www.odoo.com/documentation/18.0/developer/reference/frontend/javascript_modules.html This example demonstrates a native JavaScript module using standard `import` and `export` syntax, typically located in `web/static/src`. ```javascript import { someFunction } from "./file_b"; export function otherFunction(val) { return someFunction(val + 3); } ``` -------------------------------- ### Combining Domains with Static Methods Source: https://www.odoo.com/documentation/18.0/developer/reference/frontend/framework_overview.html Examples of using the `Domain` class's static methods (`and`, `or`, `not`, `combine`) to logically combine multiple domain representations. ```javascript // ["&", ("a", "=", 1), ("uid", "<=", uid)] Domain.and([[["a", "=", 1]], "[('uid', '<=', uid)]"]).toString(); // ["|", ("a", "=", 1), ("uid", "<=", uid)] Domain.or([[["a", "=", 1]], "[('uid', '<=', uid)]"]).toString(); // ["!", ("a", "=", 1)] Domain.not([["a", "=", 1]]).toString(); // ["&", ("a", "=", 1), ("uid", "<=", uid)] Domain.combine([[["a", "=", 1]], "[('uid', '<=', uid)]"], "AND").toString(); ``` -------------------------------- ### Interact with Odoo using XML-RPC in Python Source: https://www.odoo.com/documentation/18.0/developer/howtos/web_services.html This Python 3 example demonstrates how to log in to an Odoo server and create a new note record using the `xmlrpc.client` library. ```python import xmlrpc.client root = 'http://%s:%d/xmlrpc/' % (HOST, PORT) uid = xmlrpc.client.ServerProxy(root + 'common').login(DB, USER, PASS) print("Logged in as %s (uid: %d)" % (USER, uid)) # Create a new note sock = xmlrpc.client.ServerProxy(root + 'object') args = { 'color' : 8, 'memo' : 'This is a note', 'create_uid': uid, } note_id = sock.execute(DB, uid, PASS, 'note.note', 'create', args) ``` -------------------------------- ### Verbose Utility Classes in Qweb Source: https://www.odoo.com/documentation/18.0/developer/howtos/scss_tips.html This example demonstrates a common issue where utility classes, especially when combined with conditional logic, can lead to reduced readability in Qweb templates. ```xml ``` -------------------------------- ### Defining and Registering a Custom Sepia Effect Source: https://www.odoo.com/documentation/18.0/developer/reference/frontend/services.html This example demonstrates how to create an Owl component for a custom visual effect and register it with the effect service, making it available for use. ```javascript import { registry } from "@web/core/registry"; import { Component, xml } from "@odoo/owl"; class SepiaEffect extends Component { static template = xml`
`; } export function sepiaEffectProvider(env, params = {}) { return { Component: SepiaEffect, }; } const effectRegistry = registry.category("effects"); effectRegistry.add("sepia", sepiaEffectProvider); ``` -------------------------------- ### Get a Widget's Parent Element in JavaScript Source: https://www.odoo.com/documentation/18.0/developer/tutorials/web.html Overrides the `start` method to log the root element (`$el`) of the widget's parent to the console. ```JavaScript local.GreetingsWidget = instance.Widget.extend({ start: function() { console.log(this.getParent().$el ); // will print "div.oe_petstore_homepage" in the console }, }); ``` -------------------------------- ### Define a Basic Odoo Widget (JavaScript) Source: https://www.odoo.com/documentation/18.0/developer/tutorials/web.html Extends the base `Widget()` class to create a new component, overriding the `start()` method for initial setup and logging a message. ```javascript local.HomePage = instance.Widget.extend({ start: function() { console.log("pet store home page loaded"); }, }); ``` -------------------------------- ### Example Upgrade Script Execution Order Source: https://www.odoo.com/documentation/18.0/developer/reference/upgrades/upgrade_scripts.html This list illustrates the lexical order in which upgrade scripts are executed within each phase (pre, post, end) for a given module and version. ```text pre-10-do_something.py pre-20-something_else.py post-do_something.py post-something.py end-01-migrate.py end-migrate.py ``` -------------------------------- ### Accessing DOM Elements with useRef and onMounted in Owl Source: https://www.odoo.com/documentation/18.0/developer/tutorials/discover_js_framework/01_owl_components.html The `useRef` hook is called in `setup` to get a reference to a DOM element. Access to the element (`.el`) is only available after the component is mounted, typically within an `onMounted` callback. ```javascript setup() { this.myRef = useRef('some_name'); onMounted(() => { console.log(this.myRef.el); }); } ``` -------------------------------- ### Display Odoo-bin Help Options Source: https://www.odoo.com/documentation/18.0/developer/tutorials/unit_tests.html Use this command to view all available options for the `odoo-bin` command-line tool, including testing configurations. ```bash $ odoo-bin -h Usage: odoo-bin [options] Options: --version show program's version number and exit -h, --help show this help message and exit [...] Testing Configuration: --test-file=TEST_FILE Launch a python test file. --test-enable Enable unit tests. --test-tags=TEST_TAGS Comma-separated list of specs to filter which tests to execute. Enable unit tests if set. A filter spec has the format: [-][tag][/module][:class][.method] The '-' specifies if we want to include or exclude tests matching this spec. The tag will match tags added on a class with a @tagged decorator (all Test classes have 'standard' and 'at_install' tags until explicitly removed, see the decorator documentation). '*' will match all tags. If tag is omitted on include mode, its value is 'standard'. If tag is omitted on exclude mode, its value is '*'. The module, class, and method will respectively match the module name, test class name and test method name. Example: --test-tags :TestClass.test_func,/test_module,external Filtering and executing the tests happens twice: right after each module installation/update and at the end of the modules loading. At each stage tests are filtered by --test-tags specs and additionally by dynamic specs 'at_install' and 'post_install' correspondingly. --screencasts=DIR Screencasts will go in DIR/{db_name}/screencasts. --screenshots=DIR Screenshots will go in DIR/{db_name}/screenshots. Defaults to /tmp/odoo_tests. ``` -------------------------------- ### Selecting DOM elements within a widget using the $() shortcut Source: https://www.odoo.com/documentation/18.0/developer/tutorials/web.html Widgets provide a `$()` shortcut method that is equivalent to `this.$el.find()`, scoping selections to the widget's DOM root. This example demonstrates its usage within a widget's `start` method. ```javascript local.MyWidget = instance.Widget.extend({ start: function() { this.$("input.my_input")... }, }); ``` -------------------------------- ### Example Odoo Settings View Structure Source: https://www.odoo.com/documentation/18.0/developer/reference/user_interface/view_architectures.html Demonstrates an Odoo settings view using ``, ``, and `` elements to organize configuration options with help and documentation links. ```xml