diff options
| author | Julien Mougenot <jum@odoo.com> | 2020-03-17 15:32:42 +0000 |
|---|---|---|
| committer | Julien Mougenot <jum@odoo.com> | 2020-03-19 10:24:54 +0000 |
| commit | 22e583a8825c514f47fbb4b3e2a4a019aad611c4 (patch) | |
| tree | 54fc2a644c82919f4281d0065099b161ca491874 /addons/stock/static | |
| parent | eb724d9add2c2752c7f9ded245aae7ba6bb2aca5 (diff) | |
[FIX] stock: fix traceability action traceback
Before this commit, the control panel of the stock traceability report actions was
updated before being instantiated.
Now, only the props of the control panel are updated before its first rendering.
Added a test asserting that the action is properly working.
closes odoo/odoo#47823
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Diffstat (limited to 'addons/stock/static')
| -rw-r--r-- | addons/stock/static/src/js/stock_traceability_report_backend.js | 39 | ||||
| -rw-r--r-- | addons/stock/static/tests/stock_traceability_report_backend_tests.js | 71 |
2 files changed, 86 insertions, 24 deletions
diff --git a/addons/stock/static/src/js/stock_traceability_report_backend.js b/addons/stock/static/src/js/stock_traceability_report_backend.js index 9a3b7872947..f723ade6961 100644 --- a/addons/stock/static/src/js/stock_traceability_report_backend.js +++ b/addons/stock/static/src/js/stock_traceability_report_backend.js @@ -16,7 +16,7 @@ var stock_report_generic = AbstractAction.extend({ init: function(parent, action) { this._super.apply(this, arguments); this.actionManager = parent; - this.given_context = session.user_context; + this.given_context = Object.assign({}, session.user_context); this.controller_url = action.context.url; if (action.context.context) { this.given_context = action.context.context; @@ -47,37 +47,28 @@ var stock_report_generic = AbstractAction.extend({ } }); }, - start: function() { - var self = this; - return this._super.apply(this, arguments).then(function () { - self.set_html(); - }); + start: async function() { + this.controlPanelProps.cp_content = { $buttons: this.$buttons }; + await this._super(...arguments); + this.set_html(); }, // Fetches the html and is previous report.context if any, else create it - get_html: function() { - var self = this; - var defs = []; - return this._rpc({ - model: 'stock.traceability.report', - method: 'get_html', - args: [self.given_context], - }) - .then(function (result) { - self.html = result.html; - self.renderButtons(); - defs.push(self.update_cp()); - return Promise.all(defs); - }); + get_html: async function() { + const { html } = await this._rpc({ + args: [this.given_context], + method: 'get_html', + model: 'stock.traceability.report', + }); + this.html = html; + this.renderButtons(); }, // Updates the control panel and render the elements that have yet to be rendered update_cp: function() { if (!this.$buttons) { this.renderButtons(); } - var status = { - cp_content: {$buttons: this.$buttons}, - }; - return this.updateControlPanel(status); + this.controlPanelProps.cp_content = { $buttons: this.$buttons }; + return this.updateControlPanel(); }, renderButtons: function() { var self = this; diff --git a/addons/stock/static/tests/stock_traceability_report_backend_tests.js b/addons/stock/static/tests/stock_traceability_report_backend_tests.js new file mode 100644 index 00000000000..feba8f0f9e5 --- /dev/null +++ b/addons/stock/static/tests/stock_traceability_report_backend_tests.js @@ -0,0 +1,71 @@ +odoo.define('stock.stock_traceability_report_backend_tests', function (require) { + "use strict"; + + const dom = require('web.dom'); + const StockReportGeneric = require('stock.stock_report_generic'); + const testUtils = require('web.test_utils'); + + /** + * Helper function to instantiate a stock report action. + * @param {Object} params + * @param {Object} params.action + * @param {boolean} [params.debug] + * @returns {Promise<StockReportGeneric>} + */ + async function createStockReportAction(params) { + const parent = testUtils.createParent(params); + const report = new StockReportGeneric(parent, params.action); + const target = testUtils.prepareTarget(params.debug); + + const _destroy = report.destroy; + report.destroy = function () { + report.destroy = _destroy; + parent.destroy(); + }; + const fragment = document.createDocumentFragment(); + await report.appendTo(fragment); + dom.prepend(target, fragment, { + callbacks: [{ widget: report }], + in_DOM: true, + }); + // Wait for the ReportWidget to be appended + await testUtils.nextTick(); + + return report; + } + + QUnit.module('Stock', {}, function () { + QUnit.module('Traceability report'); + + QUnit.test("Rendering with no lines", async function (assert) { + assert.expect(1); + + const template = ` + <div class="container-fluid o_stock_reports_page o_stock_reports_no_print"> + <div class="o_stock_reports_table table-responsive"> + <span class="text-center"> + <h1>No operation made on this lot.</h1> + </span> + </div> + </div>`; + const report = await createStockReportAction({ + action: { + context: {}, + params: {}, + }, + data: { + 'stock.traceability.report': { + fields: {}, + get_html: () => ({ html: template }), + }, + }, + }); + + // HTML content is nested in a div inside of the content + assert.strictEqual(report.el.querySelector('.o_content > div').innerHTML, template, + "Displayed template should match"); + + report.destroy(); + }); + }); +}); |
