In this blog post, we will explore the process of loading models and fields in POS Odoo 16. POS, or Point of Sale, is a crucial component of any business that serves as the interface between the customer and the company’s sales and inventory management systems. With the release of Odoo 16, a new version of the popular open-source business software, there have been several updates to the POS module that make it more user-friendly and efficient. This blog will cover the basics of loading models and fields in POS, including how to create custom models and fields and how to access them in the POS interface. By the end of this blog, you will have a solid understanding of how to manage models and fields in POS Odoo 16 and how to use them to streamline your business operations.
How to load models in POS Odoo16?
First, inherit the ‘pos.session’ model in your python file. Then, use the ‘super’ function to extend the ‘_pos_ui_models_to_load’ function and add your new models to the result list. Your updated function should look like this:
def _pos_ui_models_to_load(self):
result = super()._pos_ui_models_to_load()
result.append('your.model')
return result.
def _loader_params_your_model(self):
return {
'search_params': {
'domain': [('state', '=', 'draft')],
'fields': ['name', 'partner_id', 'state'],
},
}
def _get_pos_ui_your_model(self, params):
return self.env['your.model'].search_read(**params['search_params'])
import { PosGlobalState} from 'point_of_sale.models';
import Registries from 'point_of_sale.Registries';
const NewPosGlobalState = (PosGlobalState) => class NewPosGlobalState extends PosGlobalState {
async _processData(loadedData) {
await super._processData(...arguments);
this.your_model = loadedData['your.model'];
}
}
Registries.Model.extend(PosGlobalState, NewPosGlobalState);
How to load fields to existing in POS Odoo16?
def _loader_params_your_model(self):
result = super()._loader_params_your_model()
result['search_params']['fields'].extend(['field_to_add'])
return result