diff options
| author | William Henrotin <whe@odoo.com> | 2020-04-27 11:56:02 +0200 |
|---|---|---|
| committer | Simon Lejeune <sle@openerp.com> | 2020-06-15 16:59:41 +0200 |
| commit | 0e2765f5fd0ca0079f1f024ec3a1448b6d2ea3db (patch) | |
| tree | 90ea03d1aca1bf87a080775e7db07977b645c5cc /addons/mrp/static/src/js | |
| parent | 1b6421285c6bc4c61be3242cea30c2813251cbc7 (diff) | |
[REF] mrp: no more produce wizard
Use a view similar as the pickings one.
task-2241471
Diffstat (limited to 'addons/mrp/static/src/js')
| -rw-r--r-- | addons/mrp/static/src/js/mrp_should_consume.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/addons/mrp/static/src/js/mrp_should_consume.js b/addons/mrp/static/src/js/mrp_should_consume.js new file mode 100644 index 00000000000..50b4f3f893b --- /dev/null +++ b/addons/mrp/static/src/js/mrp_should_consume.js @@ -0,0 +1,81 @@ +odoo.define('mrp.should_consume', function (require) { +"use strict"; + +var BasicFields = require('web.basic_fields'); +var FieldFloat = BasicFields.FieldFloat; +var fieldRegistry = require('web.field_registry'); +var field_utils = require('web.field_utils'); + +/** + * This widget is used to display alongside the total quantity to consume of a production order, + * the exact quantity that the worker should consume depending on the BoM. Ex: + * 2 components to make 1 finished product. + * The production order is created to make 5 finished product and the quantity producing is set to 3. + * The widget will be '3.000 / 5.000'. + */ +var MrpShouldConsume = FieldFloat.extend({ + /** + * @override + */ + init: function (parent, name, params) { + this._super.apply(this, arguments); + this.displayShouldConsume = !['done', 'draft', 'cancel'].includes(params.data.state); + let options = {'digits': [false, 3]}; + this.should_consume_qty = field_utils.format.float(params.data.should_consume_qty, false, options); + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @private + * @param {Object} [el] jquery input element that will be surrounded by a new span + * @param {float} [value] quantity to display before the input `el` + * @return {jquery element} + */ + _addShouldConsume: function (el, value) { + var $to_consume_container = $('<span class="o_should_consume"/>'); + $to_consume_container.text(value + ' / '); + $to_consume_container.append(el); + return $to_consume_container + }, + + /** + * @private + * @override + */ + _renderEdit: function () { + // Keep a reference to the input so $el can become something else + // without losing track of the actual input. + var def = this._super.apply(this, arguments); + if (this.displayShouldConsume) { + var $container = this._addShouldConsume(this.$el, this.should_consume_qty); + $container.addClass('o_row'); + this.$el = $container; + }; + return def; + }, + /** + * Resets the content to the formated value in readonly mode. + * + * @override + * @private + */ + _renderReadonly: function () { + var def = this._super.apply(this, arguments); + if (this.displayShouldConsume) { + var $container = this._addShouldConsume(this.$el, this.should_consume_qty); + this.$el = $container; + }; + return def; + }, +}); + +fieldRegistry.add('mrp_should_consume', MrpShouldConsume); + +return { + MrpShouldConsume: MrpShouldConsume, +}; + +}); |
