Пример #1
0
    def process_parameter(self, vals):
        if self.model in ('ir.model.fields'):
            return

        if 'default' in vals:
            self.env['ir.default'].set(self.model, vals['name'],
                                       vals['default'])

        if vals['ttype'] == 'float' or vals['ttype'] == 'integer' or vals[
                'ttype'] == 'arraynumeric':
            if vals['ttype'] == 'arraynumeric':
                tname = 'all ("%s")' % vals['name']
            else:
                tname = '"%s"' % vals['name']

            if 'max' in vals and 'min' in vals:
                definition = 'CHECK(%s <= %s AND %s >= %s)' % (
                    vals['min'], tname, vals['max'], tname)
                msg = "%s must be in the range of %s to %s" % (
                    vals['name'][2:], vals['min'], vals['max'])
            elif 'max' in vals:
                definition = 'CHECK(%s >= %s)' % (vals['max'], tname)
                msg = "%s must be less than or equal to %s" % (
                    vals['name'][2:], vals['max'])
            elif 'min' in vals:
                definition = 'CHECK(%s <= %s)' % (vals['min'], tname)
                msg = "%s must be greater than or equal to %s" % (
                    vals['name'][2:], vals['min'])
            else:
                definition = None

            obj = self.env[self.model]
            cr = self._cr
            conname = '%s_%s' % (obj._table, vals['name'])

            current_definition = tools.constraint_definition(cr, conname)
            if definition:
                if not current_definition:
                    tools.add_constraint(cr, obj._table, conname, definition)
                elif current_definition != definition:
                    tools.drop_constraint(cr, obj._table, conname)
                    tools.add_constraint(cr, obj._table, conname, definition)

                for index, item in enumerate(obj._sql_constraints):
                    if item[0] == vals['name']:
                        obj._sql_constraints[index] = (vals['name'],
                                                       definition, msg)
                        break
                else:
                    obj._sql_constraints.append(
                        (vals['name'], definition, msg))

                self.env['ir.model.constraint']._reflect_constraint(
                    obj, conname, 'u', definition, obj._module, msg)
            else:
                if current_definition:
                    tools.drop_constraint(cr, obj._table, conname)
Пример #2
0
    def process(key, definition):
        conname = "%s_%s" % (el_self._table, key)
        current_definition = tools.constraint_definition(
            cr, el_self._table, conname)
        if not current_definition:
            # constraint does not exists
            return add_constraint(cr, el_self._table, conname, definition)
        elif current_definition != definition:
            # constraint exists but its definition may have changed
            drop_constraint(cr, el_self._table, conname)
            return add_constraint(cr, el_self._table, conname, definition)

        else:
            return True
Пример #3
0
 def _add_sql_constraints(self):
     # we replace the sql constraint by a python one
     # to include the organizations
     constraints = []
     for (key, definition, msg) in self._sql_constraints:
         if key == 'jira_binding_uniq':
             conname = '%s_%s' % (self._table, key)
             has_definition = tools.constraint_definition(
                 self.env.cr, self._table, conname)
             if has_definition:
                 tools.drop_constraint(self.env.cr, self._table, conname)
         else:
             constraints.append((key, definition, msg))
     self._sql_constraints = constraints
     super()._add_sql_constraints()