23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/models/shipment/audit_form.rb', line 23
def execute
updated_count = 0
if attributes.present?
shipments = Shipment.ransack(attributes).result
Shipment.transaction do
shipments.find_each do |shp|
if shp.run_audit
updated_count += 1
shp.update_columns(audited: true,
audit_result: shp.audit_result,
issues_count: shp.issues_count,
updated_at: Time.current)
end
end
end
return Result.new(success: true, updated_count: updated_count, message: "Audit was performed on #{updated_count} shipment(s)")
else
return Result.new(success: false, updated_count: 0, message: "No criteria to apply, cannot run audit")
end
end
|