Skip to Content
Menu
This question has been flagged
5531 Views

I want to modify odoo datetime widget in a UTC format beacuse it is set to user timezone by default. I am modifying the javascript file but unable to find where should I have to make the changes. I am uploading my code below. I am finding the solution for more than a week ago. Kindly help me out. Your responses will be appreciated.


assets_template.xml

< template id = "assets_backend" inherit_id = "web.assets_backend" name = "DateTime Widget Modify" >
    <xpath expr = "." position = "inside" >
        <script type = "text / javascript" src = "/ custom_template / static / src / js / datetime_widget.js" />
    </xpath >
</ template >


fields_utils.js

odoo.define('crm_2.field_utils', function (require) {
"use strict";
// override Datetime function

var field_utils = require('web.field_utils');


function formatDateTime(value, field, options) {
if (value === false) {
return "";
}
if (!options || !('timezone' in options) || options.timezone) {
value = value.clone().add(session.getTZOffset(value), 'minutes');
}
return value.format(time.getLangDatetimeFormat());
}

});

date_picker.js


odoo.define ( 'crm_2.date_picker' , function (require) { 
"use strict" ;

var date_picker = require ( 'web.date_picker' );

date_picker.include ({

changeDatetime: function () {
if ( this .__ libInput> 0 ) {
if ( this .options.warn_future) {
this ._warnFuture ( this .getValue ());
}
this .trigger ( "datetime_changed" );
return ;
}
var oldValue = this.getValue ();
if ( this .isValid ()) {
this ._setValueFromUi ();
var newValue = this .getValue ();
var hasChanged =! oldValue! ==! newValue;
if (oldValue && newValue) {
var formattedOldValue = oldValue.format (time.getLangDatetimeFormat ());
var formattedNewValue = newValue.format (time.getLangDatetimeFormat ());
if (formattedNewValue! == formattedOldValue) {
hasChanged = true ;
}
}
if (hasChanged) {
if ( this.options.warn_future) {
this ._warnFuture (newValue);
}
this .trigger ( "datetime_changed" );
}
} else {
var formattedValue = oldValue? this ._formatClient (oldValue): null ;
this . $ input.val (formattedValue);
}
},

});



return date_picker;

});




Avatar
Discard

Did you find a way? I want to add Persian Date Time picker.

@Mostafa Barmshory, you need to create a widget for this.

Related Posts Replies Views Activity
5
Dec 22
2608
0
Mar 25
304
0
Feb 25
537
1
Dec 24
2542
2
Nov 24
936