[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>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user