~therp-nl/openupgrade-server/6.0-include_recursive_deps

« back to all changes in this revision

Viewing changes to bin/osv/fields.py

  • Committer: Stefan Rijnhart
  • Date: 2012-05-09 12:52:49 UTC
  • mfrom: (3475.1.142 openobject-server)
  • Revision ID: stefan@therp.nl-20120509125249-llcqw330h6u9xls0
[MRG] Merged with main

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
import xmlrpclib
39
39
from psycopg2 import Binary
40
40
 
 
41
import osv
41
42
import netsvc
42
43
import tools
43
44
from tools.translate import _
148
149
 
149
150
class reference(_column):
150
151
    _type = 'reference'
 
152
    _classic_read = False 
151
153
    def __init__(self, string, selection, size, **args):
152
154
        _column.__init__(self, string=string, size=size, selection=selection, **args)
153
155
 
 
156
    def get(self, cr, obj, ids, name, uid=None, context=None, values=None):
 
157
        result = {}
 
158
        # copy initial values fetched previously.
 
159
        for value in values:
 
160
            result[value['id']] = value[name]
 
161
            if value[name]:
 
162
                model, res_id = value[name].split(',')
 
163
                if not obj.pool.get(model).exists(cr, uid, [int(res_id)], context=context):
 
164
                    result[value['id']] = False
 
165
        return result
 
166
 
154
167
 
155
168
class char(_column):
156
169
    _type = 'char'
630
643
                if not cr.fetchone():
631
644
                    cr.execute('insert into '+self._rel+' ('+self._id1+','+self._id2+') values (%s,%s)', (id, act[1]))
632
645
            elif act[0] == 5:
633
 
                cr.execute('update '+self._rel+' set '+self._id2+'=null where '+self._id2+'=%s', (id,))
 
646
                cr.execute('delete from '+self._rel+' where ' + self._id1 + ' = %s', (id,))
634
647
            elif act[0] == 6:
635
648
 
636
649
                d1, d2,tables = obj.pool.get('ir.rule').domain_get(cr, user, obj._name, context=context)
1030
1043
            cr.execute('DELETE FROM ir_property WHERE id IN %s', (tuple(nids),))
1031
1044
 
1032
1045
        default_val = self._get_default(obj, cr, uid, prop_name, context)
 
1046
        property_create = False
 
1047
        if isinstance(default_val, osv.orm.browse_record):
 
1048
            if default_val.id != id_val:
 
1049
                property_create = True
 
1050
        elif default_val != id_val:
 
1051
            property_create = True
1033
1052
 
1034
 
        if id_val is not default_val:
 
1053
        if property_create:
1035
1054
            def_id = self._field_get(cr, uid, obj._name, prop_name)
1036
1055
            company = obj.pool.get('res.company')
1037
1056
            cid = company._company_default_get(cr, uid, obj._name, def_id,
1104
1123
        self.field_id = {}
1105
1124
 
1106
1125
 
 
1126
class column_info(object):
 
1127
    """Struct containing details about an osv column, either one local to
 
1128
       its model, or one inherited via _inherits.
 
1129
 
 
1130
       :attr name: name of the column
 
1131
       :attr column: column instance, subclass of osv.fields._column
 
1132
       :attr parent_model: if the column is inherited, name of the model
 
1133
                           that contains it, None for local columns.
 
1134
       :attr parent_column: the name of the column containing the m2o
 
1135
                            relationship to the parent model that contains
 
1136
                            this column, None for local columns.
 
1137
       :attr original_parent: if the column is inherited, name of the original
 
1138
                            parent model that contains it i.e in case of multilevel
 
1139
                            inheritence, None for local columns.
 
1140
    """
 
1141
    def __init__(self, name, column, parent_model=None, parent_column=None, original_parent=None):
 
1142
        self.name = name
 
1143
        self.column = column
 
1144
        self.parent_model = parent_model
 
1145
        self.parent_column = parent_column
 
1146
        self.original_parent = original_parent
 
1147
 
1107
1148
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
1108
1149