Ignore:
Timestamp:
Jul 19, 2010, 8:47:38 AM (14 years ago)
Author:
gav
Message:

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

Location:
trunk/grails-app/services
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/CreateDataService.groovy

    r622 r633  
    115115
    116116        // Person and Utils
    117         createDemoPersons()
    118117        createDemoSites()
    119118        createDemoDepartments()
     
    121120        createDemoManufacturers()
    122121        createDemoProductionReference()
     122        createDemoPurchasingGroups()  /// @todo: Perhaps a 'createQuickStartData' method?
    123123        createDemoCostCodes()
     124        createDemoPersons()
    124125
    125126        // Assets
     
    307308        personInstance.addToAuthorities(Authority.get(2)) // ROLE_Manager.
    308309        personInstance.addToAuthorities(Authority.get(3)) // ROLE_AppUser.
     310        personInstance.addToPersonGroups(PersonGroup.get(1))
     311        personInstance.addToPurchasingGroups(PurchasingGroup.get(1))
     312        personInstance.addToPurchasingGroups(PurchasingGroup.get(2))
    309313
    310314        //Person #4
     
    697701    }
    698702
     703    void createDemoPurchasingGroups() {
     704
     705        // PurchasingGroup
     706        def purchasingGroupInstance
     707
     708        purchasingGroupInstance = new PurchasingGroup(name:"R&M")
     709        saveAndTest(purchasingGroupInstance)
     710
     711        purchasingGroupInstance = new PurchasingGroup(name:"Raw Materials")
     712        saveAndTest(purchasingGroupInstance)
     713
     714        purchasingGroupInstance = new PurchasingGroup(name:"Safety")
     715        saveAndTest(purchasingGroupInstance)
     716    }
     717
    699718    def createDemoCostCodes() {
    700719
     
    703722
    704723        // CostCode #1
    705         costCodeInstance = new CostCode(name: "RM Reelstand")
     724        costCodeInstance = new CostCode(name: "Reelstand.172",
     725                                                                    purchasingGroup: PurchasingGroup.get(1))
    706726        saveAndTest(costCodeInstance)
    707727
    708728        // CostCode #2
    709         costCodeInstance = new CostCode(name: "CAPEX Reelstand")
     729        costCodeInstance = new CostCode(name: "Reelstand.CAPEX",
     730                                                                    purchasingGroup: PurchasingGroup.get(1))
     731        saveAndTest(costCodeInstance)
     732
     733        // CostCode #2
     734        costCodeInstance = new CostCode(name: "PrintUnit.123",
     735                                                                    purchasingGroup: PurchasingGroup.get(3))
    710736        saveAndTest(costCodeInstance)
    711737    }
  • trunk/grails-app/services/InventoryPurchaseService.groovy

    r610 r633  
    8989    }
    9090
     91    /**
     92    * Get costCodes by person and the purchasingGroups they have been assigned.
     93    * @param person A Person, defaults to currentUser.
     94    * @returns A list of CostCodes.
     95    */
     96    def getCostCodesByPerson(person = authService.currentUser) {
     97        if(person.purchasingGroups) {
     98            CostCode.withCriteria {
     99                    eq('isActive', true)
     100                    or {
     101                        person.purchasingGroups.each() { purchasingGroup ->
     102                            eq('purchasingGroup', purchasingGroup)
     103                        }
     104                    }
     105            }.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } // withCriteria
     106        }
     107        else
     108            []
     109    } // getCostCodesByPerson
     110
     111    /**
     112    * Check if a person is in a purchasing group.
     113    * @param person A PurchasingGroup to check for.
     114    * @param person A Person, defaults to currentUser.
     115    * @returns True if person is in group.
     116    */
     117    def isPersonInPurchasingGroup(purchasingGroup, person = authService.currentUser) {
     118        for(pg in person.purchasingGroups) {
     119            if(pg.id == purchasingGroup.id)
     120                return true
     121        }
     122    } // isPersonInPurchasingGroup
     123
    91124    def delete(params) {
    92125        InventoryItemPurchase.withTransaction { status ->
Note: See TracChangeset for help on using the changeset viewer.