diff options
| author | Simon Lejeune <sle@openerp.com> | 2020-07-15 12:31:51 +0000 |
|---|---|---|
| committer | svs-odoo <svs@odoo.com> | 2020-07-31 12:36:54 +0000 |
| commit | f44da631f49e83533f11a3303b88d00b2864255d (patch) | |
| tree | be46b85c116b20e04972eacb7b56e9e54793484b /addons/stock/static | |
| parent | ea48c5e75617ba675df0f2332cf1ef7a6c698fe8 (diff) | |
[ADD] stock: forecast widget
Diffstat (limited to 'addons/stock/static')
| -rw-r--r-- | addons/stock/static/src/js/forecast_widget.js | 53 | ||||
| -rw-r--r-- | addons/stock/static/src/scss/forecast_widget.scss | 8 | ||||
| -rw-r--r-- | addons/stock/static/src/xml/forecast_widget.xml | 11 |
3 files changed, 72 insertions, 0 deletions
diff --git a/addons/stock/static/src/js/forecast_widget.js b/addons/stock/static/src/js/forecast_widget.js new file mode 100644 index 00000000000..ae6e39f1d41 --- /dev/null +++ b/addons/stock/static/src/js/forecast_widget.js @@ -0,0 +1,53 @@ +odoo.define('stock.forecast_widget', function (require) { +'use strict'; + +const AbstractField = require('web.AbstractField'); +const fieldRegistry = require('web.field_registry'); +const core = require('web.core'); +const QWeb = core.qweb; + +const ForecastWidgetField = AbstractField.extend({ + supportedFieldTypes: ['char'], + + _render: function () { + const forecastData = JSON.parse(this.value); + if (!forecastData) { + this.$el.html(''); + } else { + this.$el.html(QWeb.render('stock.forecastWidget', forecastData)); + this.$el.on('click', this._onOpenReport.bind(this)); + } + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Opens the Forecast Report for the `stock.move` product. + * + * @param {MouseEvent} ev + */ + _onOpenReport: function (ev) { + ev.preventDefault(); + ev.stopPropagation(); + const productId = this.recordData.product_id.res_id; + const resModel = 'product.product'; + this._rpc({ + model: resModel, + method: 'action_product_forecast_report', + args: [productId], + }).then(action => { + action.context = { + active_model: resModel, + active_id: productId, + }; + this.do_action(action); + }); + }, +}); + +fieldRegistry.add('forecast_widget', ForecastWidgetField); + +return ForecastWidgetField; +}); diff --git a/addons/stock/static/src/scss/forecast_widget.scss b/addons/stock/static/src/scss/forecast_widget.scss new file mode 100644 index 00000000000..d9167a69e11 --- /dev/null +++ b/addons/stock/static/src/scss/forecast_widget.scss @@ -0,0 +1,8 @@ +.o_forecast_widget_cell { + text-align: right; + padding-right: 24px!important; + + button { + position: absolute; + } +} diff --git a/addons/stock/static/src/xml/forecast_widget.xml b/addons/stock/static/src/xml/forecast_widget.xml new file mode 100644 index 00000000000..2e53943803c --- /dev/null +++ b/addons/stock/static/src/xml/forecast_widget.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<templates id="template" xml:space="preserve"> + <t t-name="stock.forecastWidget"> + <span t-if="reservedAvailability" t-esc="reservedAvailability"/> + <span t-elif="!expectedDate" style="color: red;">Not Available</span> + <span t-else="" t-att-style="'color: ' + (isLate ? 'red;' : 'orange;')">Exp <t t-esc="expectedDate"/></span> + <button t-if="!hideReportButton" class="o_forecast_report_button btn btn-link o_icon_button ml-2" title="Forecasted Report"> + <i class="fa fa-fw fa-area-chart"/> + </button> + </t> +</templates> |
