Load Models & Fields to POS in Odoo 17

April 25, 2024

The most recent version of the widely used open-source ERP software is Odoo 17. Several new features and enhancements are included, including a POS module that is both more robust and easier to use. The new Odoo 17 POS module’s ability to load custom models and fields is one of its most important features. This enables you to customize the POS’s capabilities to meet your company’s requirements.

Loading models

You must overwrite the _pos_ui_models_to_load() method and inherit the post-session model to load a custom model into the POS. A list of all the models that should be loaded into the POS is returned by this method. Append the model’s name to the list to include it.

The following code, for instance, demonstrates how to load the custom model custom. model into the POS:

from odoo import models


    “””Extends the `pos.session` model.”””

    _inherit = ‘pos.session’

def _pos_ui_models_to_load(self):

    res = super()._pos_ui_models_to_load()


    return res

Loading fields

A brand-new function called _loader_params_custom_model() must be defined before a custom field can be loaded into the POS. Search_params should be the key in the dictionary that this function should return. A dictionary with two keys should be used as the value of search_params. They are fields and domains. The fields should be a list of the names of the fields you want to load into the POS, and the domain should be a list with a tuple that specifies filters.

The following code, for instance, demonstrates how to load a custom field called custom_field into the POS from the custom. model model:


Create a new function called _get_pos_ui_custom_model that accepts a params parameter. This function should use the search_read method of the env object to retrieve records from the custom. model model, using the search parameters provided in the params dictionary.

We need to import the necessary components to patch the PosStore, override the _processData function, and load the custom model data into the POS. Take the PosStore and patch functions out of their respective folders and import them. PosStore is the central repository for the state of the Point of Sale application, and the patch function is a powerful tool for making changes to existing classes or methods.

This line of code makes certain that the necessary components are imported, the PosStore class patch is applied, and the _processData function is overridden. The function’s original behavior will always be preserved when super._processData is used. Additionally, the POS application can access and utilize data related to the custom model by assigning it to the custom_model property.

Loading fields to existing models in Odoo 17 POS

To add a custom field to an existing model, override the _loader_params_existing_model function (replace “existing_model” with the target model). Within this override, invoke the parent function and augment the custom field to the “search_params” within the “fields” list.

This is how we can load the models and their fields, and loading custom fields into an existing model is accomplished.

"Unlock the Full Potential of Your Business with Odoo ERP!"

"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"

Get a Free Quote

Leave a Reply

Your email address will not be published. Required fields are marked *