Validation is intended to create additional checks for changes to orders/customers/corporate customers/tasks that the user makes in the system. Checks are applied not only when editing a card of order/customer/corporate customer/task, but also in group operations.
The condition specifies a Boolean expression, if true, the action will be canceled, and the user will receive an error message.
In a condition, you can work with the object being acted upon (they are order
, customer
, customercorporate
, task
), as well as with the changeSet
object (type Change\EntityChangeSet
), which contains information about mutable fields.
changeSet.isUpdate() and changeSet.hasChangedField('payments.status')
In some cases, validation requires checking some attributes of the user who changes data in the order/customer/corporate customer/task. For example, checking that a user belongs to a specific group. You can get the user who changes the data via the user() function.
- Prohibition of completing a task without the “Description” field filled in
changeSet.isUpdate()
and changeSet.hasChangedField("complete")
and changeSet.getNewValue("complete") == true
and task.commentary == null
- Prohibition on creating a task without a due date
changeSet.isCreate() and task.getDatetime() == null
- Only task completion is allowed, editing is not allowed
changeSet.isUpdate()
and changeSet.hasChangesExcluding(["complete", "completed_at"])
- Prohibition to change the payment status of the order
changeSet.isUpdate() and changeSet.hasChangedField('payments.status')
- Delivery date must be today or later
order.deliveryDate < date('now 00:00:00') and (
(changeSet.isCreate() and order.deliveryDate) or
(changeSet.isUpdate() and changeSet.hasChangedField('delivery_date'))
)
- Only the user of the "Logistician" group can carry out the shipment.
Note
By default, there is no "Logistician" group in the system, but you can create the user groups you need.
changeSet.hasChangedField('shipped') and not user().hasGroup('logist')
- User can change only certain fields
changeSet.hasChangesExcluding(['status', 'first_name', 'last_name'])