source: trunk/grails-app/domain/CostCode.groovy @ 734

Last change on this file since 734 was 633, checked in by gav, 14 years ago

Domain change: Add PurchasingGroup?.
Logic and views to suite.

File size: 840 bytes
Line 
1class CostCode {
2
3    PurchasingGroup purchasingGroup
4
5    String name
6    String description = ""
7    boolean isActive = true
8
9    static hasMany = [inventoryItemPurchases: InventoryItemPurchase]
10
11    static constraints = {
12        name(blank:false, maxSize:50, validator: {val, obj ->
13            // Name must be unique for a purchasingGroup.
14            def list = CostCode.withCriteria {
15                eq('purchasingGroup', obj.purchasingGroup)
16                eq('name', obj.name)
17                if(obj.id)
18                    notEqual('id', obj.id)
19            }
20            if(list.size() > 0)
21                return 'not.unique.for.purchasing.group'
22            // Success.
23            return true
24        })
25        description(maxSize:100)
26    }
27
28    String toString() {
29        "${this.name}.${this.purchasingGroup}"
30    }
31
32}
Note: See TracBrowser for help on using the repository browser.