<commit_before>openerp.base.form = function (openerp) {

openerp.base.views.add('form', 'openerp.base.FormView');
openerp.base.FormView =  openerp.base.View.extend( /** @lends openerp.base.FormView# */{
    /**
     * Indicates that this view is not searchable, and thus that no search
     * view should be displayed (if there is one active).
     */
    searchable: false,
    template: "FormView",
    /**
     * @constructs
     * @param {openerp.base.Session} session the current openerp session
     * @param {String} element_id this view's root element id
     * @param {openerp.base.DataSet} dataset the dataset this view will work with
     * @param {String} view_id the identifier of the OpenERP view object
     *
     * @property {openerp.base.Registry} registry=openerp.base.form.widgets widgets registry for this form view instance
     */
    init: function(view_manager, session, element_id, dataset, view_id) {
        this._super(session, element_id);
        this.view_manager = view_manager || new openerp.base.NullViewManager();
        this.dataset = dataset;
        this.model = dataset.model;
        this.view_id = view_id;
        this.fields_view = {};
        this.widgets = {};
        this.widgets_counter = 0;
        this.fields = {};
        this.datarecord = {};
        this.ready = false;
        this.show_invalid = true;
        this.touched = false;
        this.flags = this.view_manager.flags || {};
        this.default_focus_field = null;
        this.default_focus_button = null;
        this.registry = openerp.base.form.widgets;
        this.has_been_loaded = $.Deferred();
    },
    start: function() {
        //this.log('Starting FormView '+this.model+this.view_id)
        if (this.embedded_view) {
            return $.Deferred().then(this.on_loaded).resolve({fields_view: this.embedded_view});
        } else {
            var context = new openerp.base.CompoundContext(this.dataset.context);
            if (this.view_manager.action && this.view_manager.action.context) {
                context.add(this.view_manager.action.context);
            }
            return this.rpc("/base/formview/load", {"model": this.model, "view_id": this.view_id,
                toolbar:!!this.flags.sidebar, context: context}, this.on_loaded);
        }
    },
    on_loaded: function(data) {
        var self = this;
        this.fields_view = data.fields_view;
        var frame = new (this.registry.get_object('frame'))(this, this.fields_view.arch);

        this.$element.html(QWeb.render(this.template, { 'frame': frame, 'view': this }));
        _.each(this.widgets, function(w) {
            w.start();
        });
        this.$element.find('div.oe_form_pager button[data-pager-action]').click(function() {
            var action = $(this).data('pager-action');
            self.on_pager_action(action);
        });

        this.$element.find('#' + this.element_id + '_header button.oe_form_button_save').click(this.do_save);
        this.$element.find('#' + this.element_id + '_header button.oe_form_button_save_edit').click(this.do_save_edit);
        this.$element.find('#' + this.element_id + '_header button.oe_form_button_cancel').click(this.do_cancel);
        this.$element.find('#' + this.element_id + '_header button.oe_form_button_new').click(this.on_button_new);

        this.view_manager.sidebar.set_toolbar(data.fields_view.toolbar);
        this.has_been_loaded.resolve();
    },
    do_show: function () {
        var self = this;
        self.$element.show();
        if (this.dataset.index === null || (this.dataset.index === 0 && this.dataset.ids.length == 0)) {
            // null index means we should start a new record
            // 0 index with empty ids means we called the form with empty dataset (wizards, switched to form from empty list, ...)
            this.on_button_new();
        } else {
            this.dataset.read_index(_.keys(this.fields_view.fields), this.on_record_loaded);
        }
        this.view_manager.sidebar.do_refresh(true);
    },
    do_hide: function () {
        this.$element.hide();
    },
    on_record_loaded: function(record) {
        this.touched = false;
        if (record) {
            this.datarecord = record;
            for (var f in this.fields) {
                var field = this.fields[f];
                field.touched = false;
                field.set_value(this.datarecord[f] || false);
                field.validate();
            }
            if (!record.id) {
                // New record: Second pass in order to trigger the onchanges
                this.touched = true;
                this.show_invalid = false;
                for (var f in record) {
                    this.on_form_changed(this.fields[f]);
                }
            }
            this.on_form_changed();
            this.show_invalid = this.ready = true;
        } else {
            this.log("No record received");
        }
        this.do_update_pager(record.id == null);
        this.do_update_sidebar();
        if (this.default_focus_field) {<commit_msg>[FIX] Form view does not send back untouched fields with default value when saving record<commit_after>openerp.base.form = function (openerp) {

openerp.base.views.add('form', 'openerp.base.FormView');
openerp.base.FormView =  openerp.base.View.extend( /** @lends openerp.base.FormView# */{
    /**
     * Indicates that this view is not searchable, and thus that no search
     * view should be displayed (if there is one active).
     */
    searchable: false,
    template: "FormView",
    /**
     * @constructs
     * @param {openerp.base.Session} session the current openerp session
     * @param {String} element_id this view's root element id
     * @param {openerp.base.DataSet} dataset the dataset this view will work with
     * @param {String} view_id the identifier of the OpenERP view object
     *
     * @property {openerp.base.Registry} registry=openerp.base.form.widgets widgets registry for this form view instance
     */
    init: function(view_manager, session, element_id, dataset, view_id) {
        this._super(session, element_id);
        this.view_manager = view_manager || new openerp.base.NullViewManager();
        this.dataset = dataset;
        this.model = dataset.model;
        this.view_id = view_id;
        this.fields_view = {};
        this.widgets = {};
        this.widgets_counter = 0;
        this.fields = {};
        this.datarecord = {};
        this.ready = false;
        this.show_invalid = true;
        this.touched = false;
        this.flags = this.view_manager.flags || {};
        this.default_focus_field = null;
        this.default_focus_button = null;
        this.registry = openerp.base.form.widgets;
        this.has_been_loaded = $.Deferred();
    },
    start: function() {
        //this.log('Starting FormView '+this.model+this.view_id)
        if (this.embedded_view) {
            return $.Deferred().then(this.on_loaded).resolve({fields_view: this.embedded_view});
        } else {
            var context = new openerp.base.CompoundContext(this.dataset.context);
            if (this.view_manager.action && this.view_manager.action.context) {
                context.add(this.view_manager.action.context);
            }
            return this.rpc("/base/formview/load", {"model": this.model, "view_id": this.view_id,
                toolbar:!!this.flags.sidebar, context: context}, this.on_loaded);
        }
    },
    on_loaded: function(data) {
        var self = this;
        this.fields_view = data.fields_view;
        var frame = new (this.registry.get_object('frame'))(this, this.fields_view.arch);

        this.$element.html(QWeb.render(this.template, { 'frame': frame, 'view': this }));
        _.each(this.widgets, function(w) {
            w.start();
        });
        this.$element.find('div.oe_form_pager button[data-pager-action]').click(function() {
            var action = $(this).data('pager-action');
            self.on_pager_action(action);
        });

        this.$element.find('#' + this.element_id + '_header button.oe_form_button_save').click(this.do_save);
        this.$element.find('#' + this.element_id + '_header button.oe_form_button_save_edit').click(this.do_save_edit);
        this.$element.find('#' + this.element_id + '_header button.oe_form_button_cancel').click(this.do_cancel);
        this.$element.find('#' + this.element_id + '_header button.oe_form_button_new').click(this.on_button_new);

        this.view_manager.sidebar.set_toolbar(data.fields_view.toolbar);
        this.has_been_loaded.resolve();
    },
    do_show: function () {
        var self = this;
        self.$element.show();
        if (this.dataset.index === null || (this.dataset.index === 0 && this.dataset.ids.length == 0)) {
            // null index means we should start a new record
            // 0 index with empty ids means we called the form with empty dataset (wizards, switched to form from empty list, ...)
            this.on_button_new();
        } else {
            this.dataset.read_index(_.keys(this.fields_view.fields), this.on_record_loaded);
        }
        this.view_manager.sidebar.do_refresh(true);
    },
    do_hide: function () {
        this.$element.hide();
    },
    on_record_loaded: function(record) {
        this.touched = false;
        if (record) {
            this.datarecord = record;
            for (var f in this.fields) {
                var field = this.fields[f];
                field.touched = false;
                field.set_value(this.datarecord[f] || false);
                field.validate();
            }
            if (!record.id) {
                // New record: Second pass in order to trigger the onchanges
                this.touched = true;
                this.show_invalid = false;
                for (var f in record) {
                    var field = this.fields[f];
                    if (field) {
                        field.touched = true;
                        this.on_form_changed(field);
                    }
                }
            }
            this.on_form_changed();
            this.show_invalid = this.ready = true;
        } else {
            this.log("No record received");
        }
        this.do_update_pager(record.id == null);
        this.do_update_sidebar();
        if (this.default_focus_field) {
{'fraction_non_alphanumeric': 0.12738669238187078, 'fraction_numerical': 0.0007714561234329798, 'mean_word_length': 2.1979648473635525, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5195368', 'n_tokens_mistral': 3096, 'n_tokens_neox': 3005, 'n_words': 619}