[FIX] import: Avoid empty error message

This commit is contained in:
jbm-odoo
2019-08-23 08:43:12 +00:00
parent 57aa34490d
commit e1e63d018e
5 changed files with 20 additions and 13 deletions
+5
View File
@@ -918,6 +918,11 @@ class Import(models.TransientModel):
'column_name': column_name,
'field_name': fields[index]
})
if 'name' in import_fields:
index_of_name = import_fields.index('name')
import_result['name'] = [x[index_of_name] for x in data]
else:
import_result['name'] = []
return import_result
@@ -104,6 +104,10 @@ var DataImport = AbstractAction.extend({
e.preventDefault();
$(e.target).parent().parent().toggleClass('oe_import_report_showmore');
},
'click .oe_import_report_see_possible_value': function (e) {
e.preventDefault();
$(e.target).parent().toggleClass('oe_import_report_showmore');
},
'click .oe_import_moreinfo_action a': function (e) {
e.preventDefault();
// #data will parse the attribute on its own, we don't like
@@ -140,7 +144,6 @@ var DataImport = AbstractAction.extend({
this.session = session;
this._title = _t('Import a File'); // Displayed in the breadcrumbs
this.do_not_change_match = false;
this.preview = [[]];
},
/**
* @override
@@ -375,8 +378,6 @@ var DataImport = AbstractAction.extend({
this.$('input.oe_import_advanced_mode').prop('checked', result.advanced_mode);
this.$('.oe_import_grid').html(QWeb.render('ImportView.preview', result));
this.preview = result.preview;
if (result.headers.length === 1) {
this.$('.oe_import_options').show();
this.onresults(null, null, null, {'messages': [{
@@ -457,6 +458,7 @@ var DataImport = AbstractAction.extend({
});
},
generate_fields_completion: function (root, index) {
var self = this;
var basic = [];
var regulars = [];
var o2m = [];
@@ -628,11 +630,9 @@ var DataImport = AbstractAction.extend({
this.trigger_up('history_back');
},
onresults: function (event, from, to, results) {
var self = this;
var fields = this.$('.oe_import_fields input.oe_import_match_field').map(function (index, el) {
return $(el).select2('val') || false;
}).get();
var nameIndex = _.indexOf(fields, 'name');
var message = results.messages;
var no_messages = _.isEmpty(message);
@@ -664,8 +664,8 @@ var DataImport = AbstractAction.extend({
var from = rows.from + offset;
var to = rows.to + offset;
var rowName = '';
if (nameIndex !== -1) {
rowName = _.str.sprintf(' (%s)', self.preview[rows.from][nameIndex]);
if (results.name.length > rows.from && results.name[rows.from] !== '') {
rowName = _.str.sprintf(' (%s)', results.name[rows.from]);
}
if (from === to) {
return _.str.sprintf(_t("at row %d%s"), from, rowName);
@@ -677,8 +677,8 @@ var DataImport = AbstractAction.extend({
var from = rows.from + offset;
var to = rows.to + offset;
var rowName = '';
if (nameIndex !== -1) {
rowName = _.str.sprintf(' (%s)', self.preview[rows.from][nameIndex]);
if (results.name.length > rows.from && results.name[rows.from] !== '') {
rowName = _.str.sprintf(' (%s)', results.name[rows.from]);
}
if (from === to) {
return _.str.sprintf(_t("Row %d%s"), from, rowName);
@@ -701,7 +701,7 @@ var DataImport = AbstractAction.extend({
}
if (msg instanceof Array) {
return _.str.sprintf(
'<div class="oe_import_moreinfo oe_import_moreinfo_choices"><a href="#" class="oe_import_report_count oe_import_see_all"><i class="fa fa-arrow-right"/> %s </a><ul class="oe_import_report_more">%s</ul></div>',
'<div class="oe_import_moreinfo oe_import_moreinfo_choices"><a href="#" class="oe_import_report_see_possible_value oe_import_see_all"><i class="fa fa-arrow-right"/> %s </a><ul class="oe_import_report_more">%s</ul></div>',
_.str.escapeHTML(_t("See possible values")),
_(msg).map(function (msg) {
return '<li>'
+3 -1
View File
@@ -73,7 +73,9 @@
display: table;
}
&.oe_import_error .oe_import_error_report,
&.oe_import_noheaders .oe_import_noheaders,
&.oe_import_noheaders .oe_import_noheaders{
display: block;
}
.oe_import_report_showmore .oe_import_report_more {
display: list-item;
}
+1 -1
View File
@@ -221,7 +221,7 @@ class Partner(models.Model):
self = fields.Many2one(comodel_name=_name, compute='_compute_get_ids')
_sql_constraints = [
('check_name', "CHECK( (type='contact' AND name IS NOT NULL) or (type!='contact') )", 'Contacts require a name.'),
('check_name', "CHECK( (type='contact' AND name IS NOT NULL) or (type!='contact') )", 'Contacts require a name'),
]
def init(self):
+1 -1
View File
@@ -5967,7 +5967,7 @@ def convert_pgerror_unique(model, fields, info, e):
def convert_pgerror_constraint(model, fields, info, e):
sql_constraints = dict([(('%s_%s') % (e.diag.table_name, x[0]), x) for x in model._sql_constraints])
if e.diag.constraint_name in sql_constraints.keys():
return {'message': sql_constraints[e.diag.constraint_name][2]}
return {'message': "'%s'" % sql_constraints[e.diag.constraint_name][2]}
return {'message': tools.ustr(e)}
PGERROR_TO_OE = defaultdict(