3
0
Fork 0

[FIX] web_export_view: Remove newlines from fields having many2many_tags

12.0
SimoRubi 2021-09-09 12:54:49 +02:00
parent c420cfb554
commit 682e5aaf7e
3 changed files with 134 additions and 1 deletions

View File

@ -88,7 +88,14 @@ odoo.define('web_export_view', function (require) {
? _t("True") : _t("False") ? _t("True") : _t("False")
); );
} else { } else {
var text = $cell.text().trim(); var is_m2m = $cell.hasClass('o_many2many_tags_cell');
if (is_m2m) {
var tags = $cell.find('span.o_badge_text');
var tags_text_list = tags.map((i, el) => el.innerText.trim()).get();
var text = tags_text_list.join('\n');
} else {
var text = $cell.text().trim();
}
var is_number = var is_number =
$cell.hasClass('o_list_number') && $cell.hasClass('o_list_number') &&
!$cell.hasClass('o_float_time_cell'); !$cell.hasClass('o_float_time_cell');

View File

@ -0,0 +1,121 @@
odoo.define('web_export_view.data_export_tests', function (require) {
"use strict";
var ListView = require('web.ListView');
var testUtils = require('web.test_utils');
var createView = testUtils.createView;
QUnit.module('web_export_view', {
beforeEach: function () {
this.data = {
user: {
fields: {
name: {
string: "Name",
type: "char",
},
company_ids: {
string: "Companies",
type: "one2many",
relation: "company",
},
},
records: [
{
id: 1,
name: "User in all companies",
company_ids: [1, 2],
},
{
id: 2,
name: "User in company 1",
company_ids: [1],
},
{
id: 3,
name: "User in company 2",
company_ids: [2],
},
{
id: 4,
name: "User in no company",
company_ids: [],
},
]
},
company: {
fields: {
name: {
string: "Name",
type: "char",
},
},
records: [
{
id: 1,
name: "Company 1",
display_name: "Display company 1",
},
{
id: 2,
name: "Company 2",
display_name: "Display company 2",
},
]
},
};
}
}, function () {
QUnit.test('Exporting many2many_tags widget', function (assert) {
var data_companies = this.data.company.records;
assert.expect(1 + data_companies.length);
var list = createView({
View: ListView,
model: 'user',
data: this.data,
arch:
'<tree>' +
'<field name="name"/>' +
'<field name="company_ids" widget="many2many_tags"/>' +
'</tree>',
viewOptions: {
hasSidebar: true,
},
session: {
get_file: function (params) {
// Find line for user in all companies
var rows = JSON.parse(params.data.data).rows;
var file_companies_text = rows.find(r => r[0] === "User in all companies")[1];
var file_companies = file_companies_text.split('\n');
// Check that there is exactly one line per company
assert.equal(
file_companies.length,
data_companies.length,
"Companies field in file has as many lines as defined companies"
);
for (let data_company of data_companies) {
assert.ok(
file_companies.includes(data_company.display_name),
"Company " + data_company.id + " is exported"
);
}
params.complete();
},
},
});
// Select all lines and export
list.$('thead th.o_list_record_selector input').click();
list.sidebar.$("button.export_treeview_xls").click();
// Cleanup
list.destroy();
});
});
});

View File

@ -6,4 +6,9 @@
<script type="text/javascript" src="/web_export_view/static/src/js/web_export_view.js"></script> <script type="text/javascript" src="/web_export_view/static/src/js/web_export_view.js"></script>
</xpath> </xpath>
</template> </template>
<template id="qunit_suite" name="web_export_view tests" inherit_id="web.qunit_suite">
<xpath expr="//t[@t-set='head']" position="inside">
<script type="text/javascript" src="/web_export_view/static/tests/web_export_view_tests.js"/>
</xpath>
</template>
</odoo> </odoo>