Preorder save() now handles OAID of changeing Wohneinheit

This commit is contained in:
Frank Schubert
2024-10-09 17:20:08 +02:00
parent a64dc497e0
commit 50bfe05443
+11
View File
@@ -60,7 +60,9 @@ class Preorder extends mfBaseModel {
$this->setOrCreateOaid(); $this->setOrCreateOaid();
if($this->oaid != $old_oaid) { if($this->oaid != $old_oaid) {
$this->resetSaveNesting();
$this->save(); $this->save();
return true;
} }
//TODO: history start //TODO: history start
@@ -334,11 +336,16 @@ class Preorder extends mfBaseModel {
} }
if(!$this->adb_wohneinheit_id) { if(!$this->adb_wohneinheit_id) {
$this->oaid = null;
return false; return false;
} }
$wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id); $wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id);
if(!$wohneinheit) {
return true;
}
if($this->oaid) { if($this->oaid) {
// If current OAID is from correct Origin then do nothing // If current OAID is from correct Origin then do nothing
if($campaign->oaid_origin == "thetool") { if($campaign->oaid_origin == "thetool") {
@@ -358,6 +365,10 @@ class Preorder extends mfBaseModel {
if(!$wohneinheit->oaid) { if(!$wohneinheit->oaid) {
$wohneinheit->oaid = $current_oaid->oaid; $wohneinheit->oaid = $current_oaid->oaid;
$wohneinheit->save(); $wohneinheit->save();
} elseif($wohneinheit->oaid != $this->oaid) {
// also check if wohneinheit has a different OAID and set it in the Preorder
// No need to update OAID object, it should be correct already, because Wohneinheit is the source of oaid data,
$this->oaid = $wohneinheit->oaid;
} }
return true; return true;
} }