credativ team mailing list archive
-
credativ team
-
Mailing list archive
-
Message #05889
[Merge] lp:~credativ/openobject-server/trunk-csv-import-domain into lp:openobject-server
Craig Gowing (credativ) has proposed merging lp:~credativ/openobject-server/trunk-csv-import-domain into lp:openobject-server.
Requested reviews:
OpenERP Core Team (openerp)
For more details, see:
https://code.launchpad.net/~credativ/openobject-server/trunk-csv-import-domain/+merge/216989
When importing CSV files, allow a domain to be specified so that unique matches to records can be made when either name search is not accurate enough (too many matches) or the external XML ID does not exist or is unknown.
The field is similar to /id and /.id, it is defined as /.domain
The domain is safe_eval'ed and a standard search is run on the object using the domain, so correct security limitations will be in effect.
https://blueprints.launchpad.net/openobject-addons/+spec/csv-import-domain
--
https://code.launchpad.net/~credativ/openobject-server/trunk-csv-import-domain/+merge/216989
Your team credativ is subscribed to branch lp:~credativ/openobject-server/trunk-csv-import-domain.
=== modified file 'openerp/addons/base/ir/ir_fields.py'
--- openerp/addons/base/ir/ir_fields.py 2014-02-06 11:04:23 +0000
+++ openerp/addons/base/ir/ir_fields.py 2014-04-24 07:39:42 +0000
@@ -14,8 +14,9 @@
from openerp.tools.misc import DEFAULT_SERVER_DATE_FORMAT,\
DEFAULT_SERVER_DATETIME_FORMAT
from openerp.tools import html_sanitize
+from openerp.tools.safe_eval import safe_eval as eval
-REFERENCING_FIELDS = set([None, 'id', '.id'])
+REFERENCING_FIELDS = set([None, 'id', '.id', '.domain'])
def only_ref_fields(record):
return dict((k, v) for k, v in record.iteritems()
if k in REFERENCING_FIELDS)
@@ -338,6 +339,15 @@
_(u"Found multiple matches for field '%%(field)s' (%d matches)")
% (len(ids))))
id, _name = ids[0]
+ elif subfield == '.domain':
+ field_type = _(u"domain")
+ try:
+ ids = RelatedModel.search(cr, uid, eval(value), context=context)
+ if ids:
+ id = ids[0]
+ except ValueError:
+ raise ValueError(
+ _(u"Invalid domain '%s'") % value, {'moreinfo': action})
else:
raise Exception(_(u"Unknown sub-field '%s'") % subfield)
=== modified file 'openerp/osv/orm.py'
--- openerp/osv/orm.py 2014-04-16 14:34:31 +0000
+++ openerp/osv/orm.py 2014-04-24 07:39:42 +0000
@@ -1420,12 +1420,14 @@
* None is the name_get for the record (to use with name_create/name_search)
* "id" is the External ID for the record
* ".id" is the Database ID for the record
+ * ".domain" is a domain expression for the record
"""
columns = dict((k, v.column) for k, v in self._all_columns.iteritems())
# Fake columns to avoid special cases in extractor
columns[None] = fields.char('rec_name')
columns['id'] = fields.char('External ID')
columns['.id'] = fields.integer('Database ID')
+ columns['.domain'] = fields.char('Domain')
# m2o fields can't be on multiple lines so exclude them from the
# is_relational field rows filter, but special-case it later on to
@@ -1537,6 +1539,23 @@
field='.id',
message=_(u"Unknown database identifier '%s'") % dbid))
dbid = False
+ if '.domain' in record:
+ try:
+ dbids = self.search(cr, uid, eval(record['.domain']), context=context)
+ if not dbids:
+ log(dict(extras,
+ type='error',
+ record=stream.index,
+ field='.domain',
+ message=_(u"Domain did not match record '%s'") % record['.domain']))
+ else:
+ dbid = dbids[0]
+ except ValueError:
+ log(dict(extras,
+ type='error',
+ record=stream.index,
+ field='.domain',
+ message=_(u"Domain could not be parsed '%s'") % record['.domain']))
converted = convert(record, lambda field, err:\
_log(dict(extras, record=stream.index, field=field_names[field]), field, err))