How to Load Custom Field to POS in Odoo 17 - Odoo 17 Slides
CelineGeorge1
1,328 views
14 slides
Jul 23, 2024
Slide 1 of 14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
About This Presentation
This slide explains how to load custom fields you've created into the Odoo 17 Point-of-Sale (POS) interface. This approach involves extending the functionalities of existing POS models (e.g., product.product) to include your custom field.
Size: 218.59 KB
Language: en
Added: Jul 23, 2024
Slides: 14 pages
Slide Content
How to Load Custom Field to POS in Odoo 17 Enterprise
Introduction Enterpr ise This slide explains how to load custom fields you've created into the Odoo 17 Point-of-Sale (POS) interface.
Enterprise There are two main approaches: Loading Fields to Existing Models Loading a Custom Model to the POS
Enterprise Loading Fields to Existing Models This approach involves extending the functionalities of existing POS models (e.g., product.product) to include your custom field. Steps: 1. Create the Custom Field: In your custom module, define the custom field using Odoo's field types (e.g., char, float, boolean) within your model definition.
Enterprise 2. E xtend the _loader_params_<model_name> Function: Create a function named _loader_params_<model_name> (replace <model_name> with the actual model name, e.g., product.product) by inheriting the pos.session model. This function returns a dictionary with a key named "search_params". The "search_params" value should be another dictionary with two keys: "domains" (optional): A list of domain filters to apply when searching for the model (relevant for custom filtering based on your field). "fields": A list containing your custom field name to ensure it's loaded in the POS view.
Enterprise 3. (Optional) Override _get_pos_ui_<model_name> Function (Advanced): If you need to manipulate the retrieved data before it reaches the POS UI, you can define a function named _get_pos_ui_<model_name> . This function takes a record (e.g., product object) as input and can modify or format the custom field value before returning it.
Enterprise Example: from odoo import models # Assuming your custom field is named "custom_field" on the "product.product" model class PosSession(models.Model): _inherit = 'pos.session' def _loader_params_product_product(self): result = super()._loader_params_product_product() result['search_params']['fields'].append(custom_field) return result
Enterprise 2. Loading a Custom Model to the POS This approach involves creating a completely new model for your custom data and then loading it into the POS interface. Steps: Load the model to the pos Inherit the pos.session model and load the custom model to the pos as follows
Enterprise class PosSession(models.Model): _inherit = 'pos.session' def _pos_ui_models_to_load(self): result = super()._pos_ui_models_to_load() result += [ custom.model ] return result
Enterprise Create a function named _loader_params_ <model_name> (replace <model_name> with the actual model name, e.g., custom.model). def _loader_params_custom_model(self): return { 'search_params': { 'domain': [], 'fields': [ ‘field1’, ‘field2’,’field3’, ‘field4’ ], }, }
Enterprise define a function named _get_pos_ui_<model_name> . This function takes a record as input and can modify or format the custom field value before returning it. def _get_pos_ui_custom_model(self, params): return self.env[custom.model].search_read(**params['search_params'])
Enterprise Now create a js fil e and add the code below to load the custom model data into pos /** @odoo-module */ import { patch } from "@web/core/utils/patch"; import { PosStore } from "@point_of_sale/app/store/pos_store"; patch(PosStore.prototype, { async _processData(loadedData) { await super._processData(...arguments); this.model = loadedData["custom.model"]; } }, });
Enterprise Now the custom model and its data will be available in the point of sale interface
For More Info. Check our company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com