diff --git a/addons/sale_stock/static/src/js/qty_at_date_widget.js b/addons/sale_stock/static/src/js/qty_at_date_widget.js index f19403f4f3b..db168822008 100644 --- a/addons/sale_stock/static/src/js/qty_at_date_widget.js +++ b/addons/sale_stock/static/src/js/qty_at_date_widget.js @@ -6,9 +6,9 @@ var QWeb = core.qweb; var Widget = require('web.Widget'); var Context = require('web.Context'); -var Dialog = require('web.Dialog'); var data_manager = require('web.data_manager'); var widget_registry = require('web.widget_registry'); +var config = require('web.config'); var _t = core._t; var time = require('web.time'); @@ -29,58 +29,77 @@ var QtyAtDateWidget = Widget.extend({ this._super(parent); }, - //-------------------------------------------------------------------------- - // Handlers - //-------------------------------------------------------------------------- - _onClickButton: function (ev) { - ev.stopPropagation(); + start: function () { var self = this; + return this._super.apply(this, arguments).then(function () { + self._setPopOver(); + }); + }, + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + /** + * Set a bootstrap popover on the current QtyAtDate widget that display available + * quantity. + */ + _setPopOver: function () { + var self = this; + if (!this.data.scheduled_date) { + return; + } this.data.delivery_date = this.data.scheduled_date.clone().add(this.getSession().getTZOffset(this.data.scheduled_date), 'minutes').format(time.getLangDateFormat()); // The grid view need a specific date format that could be different than // the user one. this.data.delivery_date_grid = this.data.scheduled_date.clone().add(this.getSession().getTZOffset(this.data.scheduled_date), 'minutes').format('YYYY-MM-DD'); - var $content = $(QWeb.render('sale_stock.QtyDetailDialog', { + this.data.debug = config.isDebug(); + var $content = $(QWeb.render('sale_stock.QtyDetailPopOver', { data: this.data, })); - this.dialog = new Dialog(this, { - size: 'medium', - title: _.str.sprintf(_t('%s Availability'), self.data.product_id.data.display_name), - $content: $content, - buttons: [{ - text: _t('Close'), - classes: 'btn-primary', - close: true, - }], - }); - this.dialog.opened().then(function () { - var $forecastButton = self.dialog.$('.action_open_forecast'); - $forecastButton.on('click', function(ev) { - ev.stopPropagation(); - data_manager.load_action('stock.report_stock_quantity_action').then(function (action) { - // Change action context to choose a specific date and product(s) - // As grid_anchor is set to now() by default in the data, we need - // to load the action first, change the context then launch it via do_action - // additional_context cannot replace a context value, only add new - // - // in case of kit product, the forecast view show the kit's components - self._rpc({ - model: 'product.product', - method: 'get_components', - args: [[self.data.product_id.data.id]] - }).then(function (res) { - var additional_context = {}; - additional_context.grid_anchor = self.data.delivery_date_grid; - additional_context.search_default_warehouse_id = [self.data.warehouse_id.data.id] - action.context = new Context(action.context, additional_context); - action.domain = [ - ['product_id', 'in', res] - ]; - self.do_action(action); - }); + var $forecastButton = $content.find('.action_open_forecast'); + $forecastButton.on('click', function(ev) { + ev.stopPropagation(); + data_manager.load_action('stock.report_stock_quantity_action').then(function (action) { + // Change action context to choose a specific date and product(s) + // As grid_anchor is set to now() by default in the data, we need + // to load the action first, change the context then launch it via do_action + // additional_context cannot replace a context value, only add new + // + // in case of kit product, the forecast view show the kit's components + self._rpc({ + model: 'product.product', + method: 'get_components', + args: [[self.data.product_id.data.id]] + }).then(function (res) { + var additional_context = {}; + additional_context.grid_anchor = self.data.delivery_date_grid; + additional_context.search_default_warehouse_id = [self.data.warehouse_id.data.id]; + action.context = new Context(action.context, additional_context); + action.domain = [ + ['product_id', 'in', res] + ]; + self.do_action(action); }); }); }); - this.dialog.open(); + var options = { + content: $content, + html: true, + placement: 'left', + title: _t('Availability'), + trigger: 'focus', + delay: {'show': 0, 'hide': 100 }, + }; + this.$el.popover(options); + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + _onClickButton: function () { + // We add the property special click on the widget link. + // This hack allows us to trigger the popover (see _setPopOver) without + // triggering the _onRowClicked that opens the order line form view. + this.$el.find('.fa-info-circle').prop('special_click', true); }, }); diff --git a/addons/sale_stock/static/src/xml/qty_at_date.xml b/addons/sale_stock/static/src/xml/qty_at_date.xml index b0cd34626f1..beed0fe0325 100644 --- a/addons/sale_stock/static/src/xml/qty_at_date.xml +++ b/addons/sale_stock/static/src/xml/qty_at_date.xml @@ -1,55 +1,52 @@
-
+
- + - +
-
-
-
-
-
-
Delivery Date
-
-
-
-
Forecasted Stock
On delivery date
-
-
-
-
-
- -
-
-
-
-
-

Stock On Hand

-
-
-
-
-

Stock Available

On Hand - Reserved
-
-
-
-
-
-
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +

This product is replenished on demand.

- - - - + + + +
Expected Delivery
Forecasted Stock +
Stock On Hand +
Stock Available
On Hand - Reserved
+
+