Как включить понедельник, чтобы быть выбранным из canlendar в odoo?

1

Я работаю над odoo9, у меня есть поле даты в моей модели, я хочу включить только понедельники в свой календарь, я нашел решения JQuery в google и применил к моему дате, но не смог получить желаемый результат. Вместо этого я получаю два календаря, второй отображается, когда я продолжаю нажимать левый клик на поле даты. Посмотрите второе изображение.

Изображение 174551 Второе изображение. Изображение 174551

Это мой код JQuery:

       $('.o_datepicker_input').datepicker({
        beforeShowDay: function (date)
        {

        return [(date.getDay() == 1), ""];
        },

        });
  • 0
    Возможно, вы добавили два объекта календаря к одному входу. Можем ли мы взглянуть на HTML и более JS-код? Скрипка с воспроизводимой проблемой может помочь
  • 0
    Вы можете добавить этот код в DatePicker JS. База odoo JS для даты.
Показать ещё 1 комментарий
Теги:
odoo-9

2 ответа

0

Вот ответ. Немного сложно.

          odoo.define('automation.saturday_datepicker', function (require) {
          "use strict";

          var core = require('web.core');
          var formats = require('web.formats');
          var time = require('web.time');
          var Widget = require('web.Widget');

           var _t = core._t;

         'enter code here'var DateWidget = Widget.extend({
        template: "web.datepicker",
        type_of_date: "date",
        events: {
            'dp.change': 'change_datetime',
            'dp.show': 'set_datetime_default',
            'change .o_datepicker_input': 'change_datetime',
        },
        init: function(parent, options) {
            this._super.apply(this, arguments);

            var l10n = _t.database.parameters;

            this.name = parent.name;
            this.options = _.defaults(options || {}, {
                pickTime: this.type_of_date === 'datetime',
                useSeconds: this.type_of_date === 'datetime',
                startDate: moment({ y: 1900 }),
                endDate: moment().add(200, "y"),
                calendarWeeks: true,
                icons: {
                    time: 'fa fa-clock-o',
                    date: 'fa fa-calendar',
                    up: 'fa fa-chevron-up',
                    down: 'fa fa-chevron-down'
                },
                language : moment.locale(),
                format : time.strftime_to_moment_format((this.type_of_date === 'datetime')? (l10n.date_format + ' ' + l10n.time_format) : l10n.date_format),
                daysOfWeekDisabled: [0, 1,2,3,4,5],
            });
        },
        start: function() {
            this.$input = this.$('input.o_datepicker_input');
            this.$el.datetimepicker(this.options);
            this.picker = this.$el.data('DateTimePicker');
            this.set_readonly(false);
            this.set_value(false);
        },
        set_value: function(value) {
            this.set({'value': value});
            this.$input.val((value)? this.format_client(value) : '');
            this.picker.setValue(this.format_client(value));
        },
        get_value: function() {
            return this.get('value');
        },
        set_value_from_ui: function() {
            var value = this.$input.val() || false;
            this.set_value(this.parse_client(value));
        },
        set_readonly: function(readonly) {
            this.readonly = readonly;
            this.$input.prop('readonly', this.readonly);
        },
        is_valid: function() {
            var value = this.$input.val();
            if(value === "") {
                return true;
            } else {
                try {
                    this.parse_client(value);
                    return true;
                } catch(e) {
                    return false;
                }
            }
        },
        parse_client: function(v) {
            return formats.parse_value(v, {"widget": this.type_of_date});
        },
        format_client: function(v) {
            return formats.format_value(v, {"widget": this.type_of_date});
        },
        set_datetime_default: function() {
            //when opening datetimepicker the date and time by default should be the one from
            //the input field if any or the current day otherwise
            var value = moment().second(0);
            if(this.$input.val().length !== 0 && this.is_valid()) {
                value = this.$input.val();
            }

            // temporarily set pickTime to true to bypass datetimepicker hiding on setValue
            // see https://github.com/Eonasdan/bootstrap-datetimepicker/issues/603
            var saved_picktime = this.picker.options.pickTime;
            this.picker.options.pickTime = true;
            this.picker.setValue(value);
            this.picker.options.pickTime = saved_picktime;
        },
        change_datetime: function(e) {
            if(this.is_valid()) {
                this.set_value_from_ui();
                this.trigger("datetime_changed");
            }
        },
        commit_value: function() {
            this.change_datetime();
        },
        destroy: function() {
            this.picker.destroy();
            this._super.apply(this, arguments);
        },
    });

    var DateTimeWidget = DateWidget.extend({
        type_of_date: "datetime"
    });

    return {
        DateWidget: DateWidget,
        DateTimeWidget: DateTimeWidget,
    };

    });

     odoo.define('web.form_widgets_custom', function (require) {
"use strict";

var core = require('web.core');
var common = require('web.form_common');
var formats = require('web.formats');

var automation_saturday_date_picker = require('automation.saturday_datepicker')
var _t = core._t;
var QWeb = core.qweb;

var FieldDatetime = core.form_widget_registry.get('datetime')
var FieldDate = FieldDatetime.extend({
    template: "FieldDate",
    build_widget: function() {
        return new automation_saturday_date_picker.DateWidget(this);
    }
});

core.form_widget_registry
    .add('saturday_date_widget', FieldDate)

});

И, наконец, дайте widget = "saturday_date_widget" для моделирования поля в xml.

0

попробуй это

$(".week").datepicker("option", {
beforeShowDay: function (date)
{
    return [date.getDay() == 1, ''];
}
});


var weekOptions = { "changeMonth": false, "changeYear": false, "stepMonths": 0, 
beforeShowDay: function (date) {
    return [date.getDay() == 1, ''];
} 
};
$(function () {
$(".week").datepicker("option", weekOptions);
});

Ещё вопросы

Сообщество Overcoder
Наверх
Меню