[IMP] sale_stock: refactor availability widget in sale stock
purpose of this commit is to reuse availability widget for rental products so need to refactor the widget task- 2081260 closes- #41598 Related: odoo/enterprise#7169 Signed-off-by: Damien Bouvy (dbo) <dbo@odoo.com>
This commit is contained in:
committed by
Damien Bouvy
parent
222fe36405
commit
e288af818f
@@ -45,15 +45,42 @@ var QtyAtDateWidget = Widget.extend({
|
||||
this._setPopOver();
|
||||
}
|
||||
},
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* Set a bootstrap popover on the current QtyAtDate widget that display available
|
||||
* quantity.
|
||||
* Redirect to the product graph view.
|
||||
*
|
||||
* @private
|
||||
* @param {MouseEvent} event
|
||||
* @returns {Promise} action loaded
|
||||
*/
|
||||
_setPopOver: function () {
|
||||
var self = this;
|
||||
async _openForecast(ev) {
|
||||
ev.stopPropagation();
|
||||
// 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
|
||||
const [action, res] = await Promise.all([
|
||||
data_manager.load_action('stock.report_stock_quantity_action_product'),
|
||||
this._rpc({
|
||||
model: 'product.product',
|
||||
method: 'get_components',
|
||||
args: [[this.data.product_id.data.id]]
|
||||
})
|
||||
]);
|
||||
const additional_context = {
|
||||
grid_anchor: this.data.delivery_date_grid,
|
||||
search_default_warehouse_id: [this.data.warehouse_id.data.id],
|
||||
search_default_below_warehouse: false
|
||||
};
|
||||
action.context = new Context(action.context, additional_context);
|
||||
action.domain = [
|
||||
['product_id', 'in', res]
|
||||
];
|
||||
return this.do_action(action);
|
||||
},
|
||||
|
||||
_getContent() {
|
||||
if (!this.data.scheduled_date) {
|
||||
return;
|
||||
}
|
||||
@@ -62,37 +89,25 @@ var QtyAtDateWidget = Widget.extend({
|
||||
// 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');
|
||||
this.data.debug = config.isDebug();
|
||||
var $content = $(QWeb.render('sale_stock.QtyDetailPopOver', {
|
||||
const $content = $(QWeb.render('sale_stock.QtyDetailPopOver', {
|
||||
data: this.data,
|
||||
}));
|
||||
var $forecastButton = $content.find('.action_open_forecast');
|
||||
$forecastButton.on('click', function(ev) {
|
||||
ev.stopPropagation();
|
||||
data_manager.load_action('stock.report_stock_quantity_action_product').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];
|
||||
additional_context.search_default_below_warehouse = false;
|
||||
action.context = new Context(action.context, additional_context);
|
||||
action.domain = [
|
||||
['product_id', 'in', res]
|
||||
];
|
||||
self.do_action(action);
|
||||
});
|
||||
});
|
||||
});
|
||||
var options = {
|
||||
$content.on('click', '.action_open_forecast', this._openForecast.bind(this));
|
||||
return $content;
|
||||
},
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* Set a bootstrap popover on the current QtyAtDate widget that display available
|
||||
* quantity.
|
||||
*/
|
||||
_setPopOver() {
|
||||
const $content = this._getContent();
|
||||
if (!$content) {
|
||||
return;
|
||||
}
|
||||
const options = {
|
||||
content: $content,
|
||||
html: true,
|
||||
placement: 'left',
|
||||
|
||||
Reference in New Issue
Block a user