[IMP] warning and error reporting during import

bzr revid: xmo@openerp.com-20120926165052-7eq4ne62h63zbqqm
This commit is contained in:
Xavier Morel 2012-09-26 18:50:52 +02:00
parent f6f37632ce
commit 27aeae974a
3 changed files with 58 additions and 15 deletions

View File

@ -10,7 +10,8 @@
.oe_import .oe_import_grid,
.oe_import .oe_import_error_report,
.oe_import .oe_import_with_file,
.oe_import .oe_import_noheaders {
.oe_import .oe_import_noheaders,
.oe_import .oe_import_report_more {
display: none;
}
@ -19,7 +20,8 @@
}
.oe_import.oe_import_error .oe_import_error_report,
.oe_import.oe_import_with_file .oe_import_with_file,
.oe_import.oe_import_noheaders .oe_import_noheaders {
.oe_import.oe_import_noheaders .oe_import_noheaders,
.oe_import .oe_import_report_showmore .oe_import_report_more {
display: block;
}

View File

@ -79,6 +79,10 @@ openerp.base_import = function (instance) {
? $el.next()
: $el.parent().next())
.toggle();
},
'click .oe_import_report a.oe_import_report_count': function (e) {
e.preventDefault();
$(e.target).parent().toggleClass('oe_import_report_showmore');
}
},
init: function (parent, dataset) {
@ -262,31 +266,50 @@ openerp.base_import = function (instance) {
},
import_dryrun: function () {
return this.call_import({ dryrun: true })
.then(this.proxy('render_import_errors'));
.then(this.proxy('render_import_result'));
},
do_import: function () {
var self = this;
return this.call_import({ dryrun: false }).then(function (errors) {
if (_.isEmpty(errors)) {
return this.call_import({ dryrun: false }).then(function (message) {
if (!_.any(message, function (message) {
return message.type === 'error' })) {
if (self.getParent().reload_content) {
self.getParent().reload_content();
}
self.close();
return;
}
self.render_import_errors(errors);
self.render_import_result(message);
});
},
render_import_errors: function (errors) {
if (_.isEmpty(errors)) {
render_import_result: function (message) {
if (_.isEmpty(message)) {
this.$el.removeClass('oe_import_error');
return;
}
// import failed (or maybe just warnings, if we ever get
// warnings?)
// row indexes come back 0-indexed, spreadsheets
// display 1-indexed.
var offset = 1;
// offset more if header
if (this.import_options().header) { offset += 1; }
this.$el.addClass('oe_import_error');
this.$('.oe_import_error_report').html(
QWeb.render('ImportView.error', {errors: errors}));
QWeb.render('ImportView.error', {
errors: _(message).groupBy('message'),
at: function (rows) {
var from = rows.from + offset;
var to = rows.to + offset;
if (from === to) {
return _.str.sprintf(_t("at row %d"), from);
}
return _.str.sprintf(_t("between rows %d and %d"),
from, to);
},
more: function (n) {
return _.str.sprintf(_t("(%d times more)"), n);
},
}));
},
});
};

View File

@ -86,12 +86,30 @@
<pre><t t-esc="preview"/></pre>
</t>
<ul t-name="ImportView.error">
<li t-foreach="errors" t-as="error" t-attf-class="oe_import_report_#{error.type}">
<!-- can also have error.record, but may be *huge* if
e.g. has image fields -->
<t t-esc="error.message"/>
<li t-foreach="errors" t-as="error"
t-attf-class="oe_import_report oe_import_report_#{error_value[0].type}">
<t t-call="ImportView.error.each">
<t t-set="error" t-value="error_value[0]"/>
</t>
<a href="#" class="oe_import_report_count" t-if="error_value.length gt 1">
<t t-esc="more(error_value.length - 1)"/>
</a>
<ul class="oe_import_report_more" t-if="error_value.length gt 1">
<li t-foreach="error_value.length - 1" t-as="index">
<t t-call="ImportView.error.each">
<t t-set="error" t-value="error_value[index + 1]"/>
</t>
</li>
</ul>
</li>
</ul>
<t t-name="ImportView.error.each">
<span class="oe_import_report_message">
<t t-esc="error.message"/>
</span>
<t t-if="error.rows"><t t-esc="at(error.rows)"/></t>
</t>
<t t-extend="ListView.buttons">
<t t-jquery="span.oe_alternative">
this.attr('t-if', 'widget.options.import_enabled');