diff --git a/addons/stock/__manifest__.py b/addons/stock/__manifest__.py index 25299e86ad9..7dd76344c4a 100644 --- a/addons/stock/__manifest__.py +++ b/addons/stock/__manifest__.py @@ -78,6 +78,7 @@ 'data/stock_sequence_data.xml', ], 'qweb': [ + 'static/src/xml/inventory_report.xml', 'static/src/xml/inventory_lines.xml', 'static/src/xml/stock_traceability_report_backend.xml', ], diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index a896d63374d..4c229a89304 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -163,6 +163,31 @@ class StockQuant(models.Model): ] return action + @api.model + def action_view_quants(self): + self = self.with_context(search_default_internal_loc=1) + if self.user_has_groups('stock.group_production_lot,stock.group_stock_multi_locations'): + # fixme: erase the following condition when it'll be possible to create a new record + # from a empty grouped editable list without go through the form view. + if self.search_count([ + ('company_id', '=', self.env.user.company_id.id), + ('location_id.usage', 'in', ['internal', 'transit']) + ]): + self = self.with_context( + search_default_productgroup=1, + search_default_locationgroup=1 + ) + if not self.user_has_groups('stock.group_stock_multi_locations'): + company_user = self.env.user.company_id + warehouse = self.env['stock.warehouse'].search([('company_id', '=', company_user.id)], limit=1) + if warehouse: + self = self.with_context(default_location_id=warehouse.lot_stock_id.id) + + # If user have rights to write on quant, we set quants in inventory mode. + if self.user_has_groups('stock.group_stock_manager'): + self = self.with_context(inventory_mode=True) + return self._get_quants_action(extend=True) + @api.constrains('product_id') def check_product_id(self): if any(elem.product_id.type != 'product' for elem in self): diff --git a/addons/stock/static/src/js/inventory_report_list_controller.js b/addons/stock/static/src/js/inventory_report_list_controller.js new file mode 100644 index 00000000000..09bb54d0eed --- /dev/null +++ b/addons/stock/static/src/js/inventory_report_list_controller.js @@ -0,0 +1,51 @@ +odoo.define('stock.InventoryReportListController', function (require) { +"use strict"; + +var core = require('web.core'); +var ListController = require('web.ListController'); + +var qweb = core.qweb; + + +var InventoryReportListController = ListController.extend({ + + // ------------------------------------------------------------------------- + // Public + // ------------------------------------------------------------------------- + + /** + * @override + */ + renderButtons: function ($node) { + this._super.apply(this, arguments); + var $buttonToDate = $(qweb.render('InventoryReport.Buttons')); + $buttonToDate.on('click', this._onOpenWizard.bind(this)); + + $buttonToDate.prependTo($node.find('.o_list_buttons')); + }, + + // ------------------------------------------------------------------------- + // Handlers + // ------------------------------------------------------------------------- + + /** + * Handler called when the user clicked on the 'Inventory at Date' button. + * Opens wizard to display, at choice, the products inventory or a computed + * inventory at a given date. + */ + _onOpenWizard: function () { + this.do_action({ + res_model: 'stock.quantity.history', + views: [[false, 'form']], + target: 'new', + type: 'ir.actions.act_window', + context: { + active_model: this.modelName, + } + }); + }, +}); + +return InventoryReportListController; + +}); diff --git a/addons/stock/static/src/js/inventory_report_list_view.js b/addons/stock/static/src/js/inventory_report_list_view.js new file mode 100644 index 00000000000..494dd838b73 --- /dev/null +++ b/addons/stock/static/src/js/inventory_report_list_view.js @@ -0,0 +1,19 @@ +odoo.define('stock.InventoryReportListView', function (require) { +"use strict"; + +var ListView = require('web.ListView'); +var InventoryReportListController = require('stock.InventoryReportListController'); +var viewRegistry = require('web.view_registry'); + + +var InventoryReportListView = ListView.extend({ + config: _.extend({}, ListView.prototype.config, { + Controller: InventoryReportListController, + }), +}); + +viewRegistry.add('inventory_report_list', InventoryReportListView); + +return InventoryReportListView; + +}); diff --git a/addons/stock/static/src/js/inventory_singleton_list_controller.js b/addons/stock/static/src/js/inventory_singleton_list_controller.js index b71f2d6ae39..9e5bd4db850 100644 --- a/addons/stock/static/src/js/inventory_singleton_list_controller.js +++ b/addons/stock/static/src/js/inventory_singleton_list_controller.js @@ -2,7 +2,7 @@ odoo.define('stock.SingletonListController', function (require) { "use strict"; var core = require('web.core'); -var ListController = require('web.ListController'); +var InventoryReportListController = require('stock.InventoryReportListController'); var _t = core._t; @@ -16,7 +16,7 @@ var _t = core._t; * in the list view, so we refresh it. */ -var SingletonListController = ListController.extend({ +var SingletonListController = InventoryReportListController.extend({ /** * @override * @return {Promise} rejected when update the list because we don't want diff --git a/addons/stock/static/src/js/inventory_singleton_list_view.js b/addons/stock/static/src/js/inventory_singleton_list_view.js index 1f6fc30e483..53faf5b801e 100644 --- a/addons/stock/static/src/js/inventory_singleton_list_view.js +++ b/addons/stock/static/src/js/inventory_singleton_list_view.js @@ -1,12 +1,12 @@ odoo.define('stock.SingletonListView', function (require) { 'use strict'; -var ListView = require('web.ListView'); +var InventoryReportListView = require('stock.InventoryReportListView'); var SingletonListController = require('stock.SingletonListController'); var viewRegistry = require('web.view_registry'); -var SingletonListView = ListView.extend({ - config: _.extend({}, ListView.prototype.config, { +var SingletonListView = InventoryReportListView.extend({ + config: _.extend({}, InventoryReportListView.prototype.config, { Controller: SingletonListController, }), }); diff --git a/addons/stock/static/src/xml/inventory_report.xml b/addons/stock/static/src/xml/inventory_report.xml new file mode 100644 index 00000000000..f33d72979ec --- /dev/null +++ b/addons/stock/static/src/xml/inventory_report.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/addons/stock/views/stock_quant_views.xml b/addons/stock/views/stock_quant_views.xml index 5458e4e66ff..06bd6eea960 100644 --- a/addons/stock/views/stock_quant_views.xml +++ b/addons/stock/views/stock_quant_views.xml @@ -114,13 +114,14 @@ stock.quant - + - + @@ -128,7 +129,6 @@ - stock.quant.pivot stock.quant @@ -152,23 +152,19 @@ - + Inventory - stock.quant - tree,form,pivot,graph - { - 'search_default_internal_loc': 1, - 'search_default_productgroup': 1, - 'search_default_locationgroup': 1 - } - -

- No inventory found -

- This analysis gives you a fast overview on the current stock level of your products and their current inventory value. -

+ + code + + action = model.with_context( + search_default_internal_loc=1, + search_default_productgroup=1, + search_default_locationgroup=1, + ).action_view_quants()
+ Stock On Hand {'search_default_internal_loc': 1, 'search_default_productgroup':1, 'search_default_locationgroup':1} @@ -287,5 +283,7 @@ - + diff --git a/addons/stock/views/stock_template.xml b/addons/stock/views/stock_template.xml index dfc841d132d..dc31923b65e 100644 --- a/addons/stock/views/stock_template.xml +++ b/addons/stock/views/stock_template.xml @@ -3,6 +3,8 @@