Xavier ALT (OpenERP) has proposed merging
lp:~openerp-dev/openerp-web/6.1-opw-574895-xal into lp:openerp-web/6.1.
Requested reviews:
Olivier Dony (OpenERP) (odo-openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/6.1-opw-574895-xal/+merge/107950
Hi,
This branch fix two problem with data import from web client:
1. Field matching have to be done first on exact "field name", then only on
"field string" attribute.
Steps:
- Export a product list (all required fields)
- Import it again
(fields_get() returns a list with "name_template" field before "name" field,
as both have the same string "name_template" will be matched first - which is
wrong.
Current: show error that "name" field is not provided
Expected: should not show any error as "name" field is correctly provided
2. If a many2one field is required, user should be able to provided any of
"field name" or "field name/id"
Steps:
- Export a product list (all required fields)
- Import it again
(this.required_fields contains twice the product template field -
["product_tmpl_id", "product_tmpl_id/id"])
Current: show error that "product_tmpl_id" is not provided
Exepect: should not show any error as "product_tmpl_id/id" field is correctly
provided.
--
https://code.launchpad.net/~openerp-dev/openerp-web/6.1-opw-574895-xal/+merge/107950
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openerp-web/6.1-opw-574895-xal.
=== modified file 'addons/web/static/src/js/data_import.js'
--- addons/web/static/src/js/data_import.js 2012-05-25 07:08:59 +0000
+++ addons/web/static/src/js/data_import.js 2012-05-30 10:27:27 +0000
@@ -55,7 +55,8 @@
.filter(function (field) {
return field.required &&
!_.include(self.fields_with_defaults, field.id); })
- .pluck('name')
+ .pluck('id')
+ .uniq()
.value();
convert_fields(self);
self.all_fields.sort();
@@ -267,8 +268,13 @@
f = _(fields).detect(function (field) {
// TODO: levenshtein between header and field.string
return field.name === name
- || field.string.toLowerCase() === name.toLowerCase();
});
+ if (!f) {
+ f = _(fields).detect(function (field) {
+ // TODO: levenshtein between header and field.string
+ return field.string.toLowerCase() === name.toLowerCase();
+ });
+ }
if (f) { return f.name; }
// if ``name`` is a path (o2m), we need to recurse through its .fields
@@ -279,8 +285,13 @@
f = _(fields).detect(function (field) {
// field.name for o2m is $foo/id, so we want to match on id
return field.id === column_name
- || field.string.toLowerCase() === column_name.toLowerCase()
});
+ if (!f) {
+ f = _(fields).detect(function (field) {
+ // field.name for o2m is $foo/id, so we want to match on id
+ return field.string.toLowerCase() === column_name.toLowerCase()
+ });
+ }
if (!f) { return undefined; }
// if we found a matching field for the first path section, recurse in
@@ -350,9 +361,24 @@
check_required: function() {
if (!this.required_fields.length) { return true; }
+ // get real field name (stripping the trailing "/id" for many2one field).
+ // For many2one fields, user can use any of the two fields:
+ // - base field name for name_search() import
+ // - with the "/id" for direct referencing
+ // In both case we must check if field is required only based on his
+ // real name.
+ var get_field_real_id = _.bind(function(field_name) {
+ var f = _.detect(this.fields, function(field) {
+ return field.name === field_name
+ });
+ if (!f) { return field_name };
+ return f.id;
+ }, this);
+
var selected_fields = _(this.$element.find('.sel_fields').get()).chain()
.pluck('value')
.compact()
+ .map(get_field_real_id)
.value();
var missing_fields = _.difference(this.required_fields, selected_fields);
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp