1

I want to add validations for data that I've added to Odoo's POS client model. By the moment I've created the following code:

   screens.ClientListScreenWidget.include({
        // Client save alerts
        save_client_details: function (partner) {
            if (!fields.custom_field) {
                this.gui.show_popup('error', 'Missing custom_field!')
            }
            this._super(partner)
        }
    })

If my custom_field is empty it raises the popup and that's fine. The problem is that even if the user fills the field, the popup appears too. Checking Odoo's code I've found that they check what the user filled in the window "fields" with the following code:

   save_client_details: function(partner) {
        var self = this;

        var fields = {};
        this.$('.client-details-contents .detail').each(function(idx,el){
            if (self.integer_client_details.includes(el.name)){
                var parsed_value = parseInt(el.value, 10);
                if (isNaN(parsed_value)){
                    fields[el.name] = false;
                }
                else{
                    fields[el.name] = parsed_value
                }
            }
            else{
                fields[el.name] = el.value || false;
            }
        });

        if (!fields.name) {
            this.gui.show_popup('error',_t('A Customer Name Is Required'));
            return;
        }

I'm not used to javascript so I didn't manage mimic this code for my custom field. How can I achieve this? How should my code look like for this?

Simon Capriles
  • 143
  • 2
  • 21

0 Answers0