diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/mrp/static/src/js/mrp_should_consume.js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/mrp/static/src/js/mrp_should_consume.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 00000000..d432c5cf --- /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"; + +const BasicFields = require('web.basic_fields'); +const FieldFloat = BasicFields.FieldFloat; +const fieldRegistry = require('web.field_registry'); +const 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'. + */ +const MrpShouldConsume = FieldFloat.extend({ + /** + * @override + */ + init: function (parent, name, params) { + this._super.apply(this, arguments); + this.displayShouldConsume = !['done', 'draft', 'cancel'].includes(params.data.state); + this.should_consume_qty = field_utils.format.float(params.data.should_consume_qty, params.fields.should_consume_qty, this.nodeOptions); + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Prefix the classic float field (this.$el) by a static value. + * + * @private + * @param {float} [value] quantity to display before the input `el` + * @param {bool} [edit] whether the field will be editable or readonly + */ + _addShouldConsume: function (value, edit=false) { + const $to_consume_container = $('<span class="o_should_consume"/>'); + if (edit) { + $to_consume_container.addClass('o_row'); + } + $to_consume_container.text(value + ' / '); + this.setElement(this.$el.wrap($to_consume_container).parent()); + }, + + /** + * @private + * @override + */ + _renderEdit: function () { + if (this.displayShouldConsume) { + if (!this.$el.text().includes('/')) { + this.$input = this.$el; + this._addShouldConsume(this.should_consume_qty, true); + } + this._prepareInput(this.$input); + } else { + this._super.apply(this); + } + }, + /** + * Resets the content to the formated value in readonly mode. + * + * @override + * @private + */ + _renderReadonly: function () { + this.$el.text(this._formatValue(this.value)); + if (this.displayShouldConsume) { + this._addShouldConsume(this.should_consume_qty); + } + }, +}); + +fieldRegistry.add('mrp_should_consume', MrpShouldConsume); + +return { + MrpShouldConsume: MrpShouldConsume, +}; + +}); |
