N°3495 WorkOrder: on closure set end_date only if empty

This commit is contained in:
vdumas
2021-02-12 11:05:39 +01:00
parent c8dd19c22f
commit a8c834b1e9
3 changed files with 41 additions and 1 deletions

View File

@@ -253,6 +253,22 @@
</argument>
</arguments>
</method>
<method id="SetCurrentDateIfNull">
<arguments>
<argument id="1">
<type>attcode</type>
<mandatory>true</mandatory>
<type_restrictions>
<operation>allow</operation>
<types>
<type id="AttributeDate"/>
<type id="AttributeDateTime"/>
<type id="AttributeString"/>
</types>
</type_restrictions>
</argument>
</arguments>
</method>
<method id="SetCurrentUser">
<arguments>
<argument id="1">

View File

@@ -3982,6 +3982,30 @@ abstract class DBObject implements iDisplay
return true;
}
/**
* Helper to set a value only if it is currently undefined
*
* Call SetCurrentDate() only of the internal representation of the attribute is null.
*
* @api
* @see SetCurrentDate()
*
* @param string $sAttCode
*
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @since 3.0.0
*/
public function SetCurrentDateIfNull($sAttCode)
{
$oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
$oCurrentValue = $this->Get($sAttCode);
if ($oAttDef->IsNull($oCurrentValue))
{
$this->SetCurrentDate($sAttCode);
}
}
/**
* Helper to set the current logged in user for the given attribute
* Suitable for use as a lifecycle action

View File

@@ -604,7 +604,7 @@
<target>closed</target>
<actions>
<action>
<verb>SetCurrentDate</verb>
<verb>SetCurrentDateIfNull</verb>
<params>
<param xsi:type="attcode">end_date</param>
</params>