~credativ/openobject-server/trunk-csv-import-domain

« back to all changes in this revision

Viewing changes to openerp/addons/base/ir/ir_fields.py

  • Committer: Craig Gowing (credativ)
  • Date: 2014-04-24 07:10:26 UTC
  • Revision ID: craig.gowing@credativ.co.uk-20140424071026-2m4l7fotojsdkz3e
[IMP] Allow domain searches on CSV import

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
from openerp.tools.misc import DEFAULT_SERVER_DATE_FORMAT,\
15
15
                               DEFAULT_SERVER_DATETIME_FORMAT
16
16
from openerp.tools import html_sanitize
 
17
from openerp.tools.safe_eval import safe_eval as eval
17
18
 
18
 
REFERENCING_FIELDS = set([None, 'id', '.id'])
 
19
REFERENCING_FIELDS = set([None, 'id', '.id', '.domain'])
19
20
def only_ref_fields(record):
20
21
    return dict((k, v) for k, v in record.iteritems()
21
22
                if k in REFERENCING_FIELDS)
338
339
                        _(u"Found multiple matches for field '%%(field)s' (%d matches)")
339
340
                        % (len(ids))))
340
341
                id, _name = ids[0]
 
342
        elif subfield == '.domain':
 
343
            field_type = _(u"domain")
 
344
            try:
 
345
                ids = RelatedModel.search(cr, uid, eval(value), context=context)
 
346
                if ids:
 
347
                    id = ids[0]
 
348
            except ValueError:
 
349
                raise ValueError(
 
350
                    _(u"Invalid domain '%s'") % value, {'moreinfo': action})
341
351
        else:
342
352
            raise Exception(_(u"Unknown sub-field '%s'") % subfield)
343
353