diff options
3 files changed, 87 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(); + }); + }); +}); diff --git a/addons/stock/views/stock_template.xml b/addons/stock/views/stock_template.xml index 9c7e7f8407a..dd9f333379c 100644 --- a/addons/stock/views/stock_template.xml +++ b/addons/stock/views/stock_template.xml @@ -21,6 +21,7 @@ <xpath expr="//t[@t-set='head']" position="inside"> <script type="text/javascript" src="/stock/static/tests/singleton_list_tests.js"/> <script type="text/javascript" src="/stock/static/tests/popover_widget_tests.js"/> + <script type="text/javascript" src="/stock/static/tests/stock_traceability_report_backend_tests.js"/> </xpath> </template> |
