diff options
| author | svs-odoo <svs@odoo.com> | 2019-03-12 12:22:41 +0000 |
|---|---|---|
| committer | svs-odoo <svs@odoo.com> | 2019-05-29 14:03:29 +0000 |
| commit | cc9324f74084760da3e49f069e3ef62f0d4280d7 (patch) | |
| tree | 5f40efdd92de7cddb73c91a06f8a0de4ffe08dc4 /addons/stock/static/src/js/inventory_validate_button_controller.js | |
| parent | da33eb36b80d1b2a0004c28cf20d6b0263bcb643 (diff) | |
[IMP] *: usability of Inventory Adjustment
Change the use of Inventory Adjustment, notable changes are:
- Removed filter field: When user creates a new inventory
adjustment, he can set one or multiple locations and/or products.
An inventory adjustment will worry only about defined
locations/products, but if neither product or location was set,
it'll manage all stock.
- Inventory Adjustment Lines have their own view instead of be
listed on the Inventory Adjustment form view.
Inventory adjustment lines have new color legend:
- Red: The quantity is outdated.
- Blue: There is difference between the on hand quantity and the
counted quantity.
New inventory lines created by the user are written in bold.
- User can't modify already existing inventory lines, except for the
counted quantity.
- When an inventory line is outdated, the user has the possibility
to select and update it, that'll recompute the on hand quantity.
- When an inventory adjustment is validated, it will take in account
only the difference between the theoretical quantity ('On Hand
Quantity') and the counted quantity to adjust the quants.
- When an inventory adjustment is canceled, it will keep its
inventory lines and won't regenerate them when re-started.
- When an Inventory Adjustment generates Account Moves, user can now
find them in a stat button in the Inventory Adjustment form view.
Also, made some changes in demo data to match new requirement.
Task #1935921
Diffstat (limited to 'addons/stock/static/src/js/inventory_validate_button_controller.js')
| -rw-r--r-- | addons/stock/static/src/js/inventory_validate_button_controller.js | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/addons/stock/static/src/js/inventory_validate_button_controller.js b/addons/stock/static/src/js/inventory_validate_button_controller.js new file mode 100644 index 00000000000..ac5367b8d25 --- /dev/null +++ b/addons/stock/static/src/js/inventory_validate_button_controller.js @@ -0,0 +1,95 @@ +odoo.define('stock.InventoryValidationController', function (require) { +"use strict"; + +var core = require('web.core'); +var ListController = require('web.ListController'); + +var _t = core._t; +var qweb = core.qweb; + +var InventoryValidationController = ListController.extend({ + events: _.extend({ + 'click .o_button_validate_inventory': '_onValidateInventory' + }, ListController.prototype.events), + /** + * @override + */ + init: function (parent, model, renderer, params) { + var context = renderer.state.getContext(); + this.inventory_id = context.active_id; + return this._super.apply(this, arguments); + }, + + // ------------------------------------------------------------------------- + // Public + // ------------------------------------------------------------------------- + + /** + * @override + */ + renderButtons: function ($node) { + this._super.apply(this, arguments); + var $validationButton = $(qweb.render('InventoryLines.Buttons')); + $validationButton.prependTo($node.find('.o_list_buttons')); + }, + + // ------------------------------------------------------------------------- + // Handlers + // ------------------------------------------------------------------------- + + /** + * Handler called when user click on validation button in inventory lines + * view. Makes an rpc to try to validate the inventory, then will go back on + * the inventory view form if it was validated. + * This method could also open a wizard in case something was missing. + * + * @private + */ + _onValidateInventory: function () { + var self = this; + var prom = Promise.resolve(); + var recordID = this.renderer.getEditableRecordID(); + if (recordID) { + // If user's editing a record, we wait to save it before to try to + // validate the inventory. + prom = this.saveRecord(recordID); + } + + prom.then(function () { + self._rpc({ + model: 'stock.inventory', + method: 'action_validate', + args: [self.inventory_id] + }).then(function (res) { + var exitCallback = function (infos) { + // In case we discarded a wizard, we do nothing to stay on + // the same view... + if (infos === 'special') { + return; + } + // ... but in any other cases, we go back on the inventory form. + self.do_notify( + _t("Success"), + _t("The inventory has been validated")); + self.do_action({ + type: 'ir.actions.act_window', + res_model: 'stock.inventory', + res_id: self.inventory_id, + views: [[false, 'form']], + target: 'main' + }); + }; + + if (_.isObject(res)) { + self.do_action(res, { on_close: exitCallback }); + } else { + return exitCallback(); + } + }); + }); + }, +}); + +return InventoryValidationController; + +}); |
