1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
odoo.define('stock.forecast_widget', function (require) {
'use strict';
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: ['float'],
_render: function () {
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.forecast_availability.digits[1]);
this.$el.html(QWeb.render('stock.forecastWidget', data));
this.$('.o_forecast_report_button').on('click', this._onOpenReport.bind(this));
},
isSet: function () {
return true;
},
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
/**
* Opens the Forecast Report for the `stock.move` product.
*
* @param {MouseEvent} ev
*/
_onOpenReport: function (ev) {
ev.preventDefault();
ev.stopPropagation();
if (!this.recordData.id) {
return;
}
this._rpc({
model: 'stock.move',
method: 'action_product_forecast_report',
args: [this.recordData.id],
}).then(action => {
action.context = Object.assign(action.context || {}, {
active_model: 'product.product',
active_id: this.recordData.product_id.res_id,
});
this.do_action(action);
});
},
});
fieldRegistry.add('forecast_widget', ForecastWidgetField);
return ForecastWidgetField;
});
|