summaryrefslogtreecommitdiff
path: root/addons/stock/static/src/js/forecast_widget.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/stock/static/src/js/forecast_widget.js')
-rw-r--r--addons/stock/static/src/js/forecast_widget.js38
1 files changed, 29 insertions, 9 deletions
diff --git a/addons/stock/static/src/js/forecast_widget.js b/addons/stock/static/src/js/forecast_widget.js
index 6cbf4986774..b3535121268 100644
--- a/addons/stock/static/src/js/forecast_widget.js
+++ b/addons/stock/static/src/js/forecast_widget.js
@@ -3,22 +3,42 @@ odoo.define('stock.forecast_widget', function (require) {
const AbstractField = require('web.AbstractField');
const fieldRegistry = require('web.field_registry');
+const field_utils = require('web.field_utils');
+const utils = require('web.utils');
const core = require('web.core');
const QWeb = core.qweb;
const ForecastWidgetField = AbstractField.extend({
- supportedFieldTypes: ['char'],
+ supportedFieldTypes: ['float'],
_render: function () {
- const forecastData = JSON.parse(this.value);
- if (!forecastData) {
- this.$el.html('');
- } else {
- // Don't display the graph button for non-storable products or if was explicited.
- forecastData.hideReportButton = this.recordData.product_type !== 'product';
- this.$el.html(QWeb.render('stock.forecastWidget', forecastData));
- this.$el.on('click', this._onOpenReport.bind(this));
+ var data = Object.assign({}, this.record.data, {
+ forecast_availability_str: field_utils.format.float(
+ this.record.data.forecast_availability,
+ this.record.fields.forecast_availability,
+ this.nodeOptions
+ ),
+ reserved_availability_str: field_utils.format.float(
+ this.record.data.reserved_availability,
+ this.record.fields.reserved_availability,
+ this.nodeOptions
+ ),
+ forecast_expected_date_str: field_utils.format.date(
+ this.record.data.forecast_expected_date,
+ this.record.fields.forecast_expected_date
+ ),
+ });
+ if (data.forecast_expected_date && data.date_deadline) {
+ data.forecast_is_late = data.forecast_expected_date > data.date_deadline;
}
+ data.will_be_fulfilled = utils.round_decimals(data.forecast_availability, this.record.fields.forecast_availability.digits[1]) >= utils.round_decimals(data.product_qty, this.record.fields.product_qty.digits[1]);
+
+ this.$el.html(QWeb.render('stock.forecastWidget', data));
+ this.$el.on('click', this._onOpenReport.bind(this));
+ },
+
+ isSet: function () {
+ return true;
},
//--------------------------------------------------------------------------