odoo.define('mrp.mrp_state', function (require) { "use strict"; var AbstractField = require('web.AbstractField'); var core = require('web.core'); var fields = require('web.basic_fields'); var fieldUtils = require('web.field_utils'); var field_registry = require('web.field_registry'); var time = require('web.time'); var _t = core._t; /** * This widget is used to display the availability on a workorder. */ var SetBulletStatus = AbstractField.extend({ // as this widget is based on hardcoded values, use it in another context // probably won't work // supportedFieldTypes: ['selection'], /** * @override */ init: function () { this._super.apply(this, arguments); this.classes = this.nodeOptions && this.nodeOptions.classes || {}; }, //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- /** * @private * @override */ _renderReadonly: function () { this._super.apply(this, arguments); var bullet_class = this.classes[this.value] || 'default'; if (this.value) { var title = this.value === 'waiting' ? _t('Waiting Materials') : ''; this.$el.attr({'title': title, 'style': 'display:inline'}); this.$el.removeClass('text-success text-danger text-default'); this.$el.html($('' + title + '').addClass('badge badge-' + bullet_class)); } } }); var TimeCounter = fields.FieldFloatTime.extend({ init: function () { this._super.apply(this, arguments); this.duration = this.record.data.duration; }, willStart: function () { var self = this; var def = this._rpc({ model: 'mrp.workcenter.productivity', method: 'search_read', domain: [ ['workorder_id', '=', this.record.data.id], ['date_end', '=', false], ], }).then(function (result) { var currentDate = new Date(); var duration = 0; if (result.length > 0) { duration += self._getDateDifference(time.auto_str_to_date(result[0].date_start), currentDate); } var minutes = duration / 60 >> 0; var seconds = duration % 60; self.duration += minutes + seconds / 60; if (self.mode === 'edit') { self.value = self.duration; } }); return Promise.all([this._super.apply(this, arguments), def]); }, destroy: function () { this._super.apply(this, arguments); clearTimeout(this.timer); }, //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- /** * @override */ isSet: function () { return true; }, //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- /** * Compute the difference between two dates. * * @private * @param {string} dateStart * @param {string} dateEnd * @returns {integer} the difference in millisecond */ _getDateDifference: function (dateStart, dateEnd) { return moment(dateEnd).diff(moment(dateStart), 'seconds'); }, /** * @override */ _renderReadonly: function () { if (this.record.data.is_user_working) { this._startTimeCounter(); } else { this._super.apply(this, arguments); } }, /** * @private */ _startTimeCounter: function () { var self = this; clearTimeout(this.timer); if (this.record.data.is_user_working) { this.timer = setTimeout(function () { self.duration += 1/60; self._startTimeCounter(); }, 1000); } else { clearTimeout(this.timer); } this.$el.text(fieldUtils.format.float_time(this.duration)); }, }); var FieldEmbedURLViewer = fields.FieldChar.extend({ //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- /** * @override */ init: function () { this._super.apply(this, arguments); this.page = 1; this.srcDirty = false; }, /** * force to set 'src' for embed iframe viewer when its value has changed * * @override * */ reset: function () { this._super.apply(this, arguments); this._updateIframePreview(); }, //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- /** * Initializes and returns an iframe for the viewer * * @private * @returns {jQueryElement} */ _prepareIframe: function () { return $('