diff --git a/include/class.dept.php b/include/class.dept.php
index 1f14bcb15e41ac4100b8db2670afb0b8b01a7eff..36ffd2ffb00f07258426aa1c9b3f819bc949f297 100644
--- a/include/class.dept.php
+++ b/include/class.dept.php
@@ -469,7 +469,7 @@ implements TemplateVariable {
     }
 
     /*----Static functions-------*/
-	static function getIdByName($name, $pid=null) {
+    static function getIdByName($name, $pid=null) {
         $row = static::objects()
             ->filter(array(
                         'name' => $name,
@@ -579,9 +579,12 @@ implements TemplateVariable {
 
     static function __create($vars, &$errors) {
         $dept = self::create($vars);
-        $dept->update($vars, $errors);
+        if (!$dept->update($vars, $errors))
+          return false;
+
+       $dept->save();
 
-        return isset($dept->id) ? $dept : null;
+       return $dept;
     }
 
     function save($refetch=false) {