diff --git a/app/lib/BundlableLabelableBaseModelWithAttributes.php b/app/lib/BundlableLabelableBaseModelWithAttributes.php index 0ac64c320a..e995cfd00d 100644 --- a/app/lib/BundlableLabelableBaseModelWithAttributes.php +++ b/app/lib/BundlableLabelableBaseModelWithAttributes.php @@ -4191,7 +4191,7 @@ public function saveBundlesForScreen($pm_screen, $po_request, &$pa_options) { if(!(bool)$this->getAppConfig()->get($this->tableName().'_dont_allow_editing_of_codes_when_in_use') || !$this->getPrimaryKey()) { if ($this->opo_idno_plugin_instance) { $this->opo_idno_plugin_instance->setDb($this->getDb()); - if (isset($va_fields_by_type['intrinsic']['mandatory_type_id'])) { + if (isset($va_fields_by_type['intrinsic']['mandatory_type_id']) && !$this->get('type_id')) { $this->set('type_id', $_REQUEST['type_id']); } $this->set($vs_f, $vs_tmp = $this->opo_idno_plugin_instance->htmlFormValue($vs_idno_field)); @@ -4208,7 +4208,9 @@ public function saveBundlesForScreen($pm_screen, $po_request, &$pa_options) { // fall back to simple field name intrinsic spec - still used for "mandatory" fields such as type_id and parent_id $vs_v = $po_request->parameterExists("{$vs_f}") ? $po_request->getParameter("{$vs_f}", pString) : null; } - if(!is_null($vs_v)) { + if(($vs_f === 'type_id') && $this->get('type_id')) { + // already set via code — don't overwrite + } elseif(!is_null($vs_v)) { $this->set($vs_f, $vs_v); } break; diff --git a/app/models/ca_storage_locations.php b/app/models/ca_storage_locations.php index 16ebf62148..09ee26f10f 100644 --- a/app/models/ca_storage_locations.php +++ b/app/models/ca_storage_locations.php @@ -527,26 +527,27 @@ public function saveBundlesForScreen($screen, $request, &$options) { $we_set_transaction = true; } if (($rc = parent::saveBundlesForScreen($screen, $request, $options)) && $parent_changed) { - $new_parent_id = (int)$this->get('ca_storage_locations.parent_id'); - - if ($old_parent_id === $new_parent_id) { return $rc; } // don't track if there's no actual movement - + $new_parent_id = $old_parent_id; // safe default if no movement form is found below + unset($options['ui_instance']); - + // Get list of policies that involve movements – we'll need to generate movement records for these policies if they are so configured. if (!is_array($policies = ca_movements::getDependentHistoryTrackingCurrentValuePolicies('ca_movements'))) { return $rc; } - + // Look for incoming movement form attached to hierarcy_location bundle $movement_form_name = $movemenr_form_screen = null; foreach($_REQUEST as $key => $val) { if (preg_match('!^(.*)_movement_form_name$!', $key, $matches)) { $movement_form_name = $request->getParameter($matches[1].'_movement_form_name', pString); - $movement_form_screen = $request->getParameter($matches[1].'_movement_screen', pString); - + $movement_form_screen = $request->getParameter($matches[1].'_movement_screen', pString); + $new_parent_id = $request->getParameter($matches[1].'_new_parent_id', pInteger); + break; } } - + + if ($old_parent_id === $new_parent_id) { return $rc; } // don't track if there's no actual movement + if ($movement_form_name && $movement_form_screen) { foreach($policies as $policy_code => $policy) { if (!is_array($policy_elements = caGetOption('elements', $policy, null))) { continue; }