- Timestamp:
- Nov 25, 2010, 9:08:43 AM (14 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/InventoryItemDetailedController.groovy
r719 r720 430 430 431 431 if(!result.error) { 432 def possibleAlternateItems = inventoryItemService.getPossibleAlternateItems(result.inventoryItemInstance)433 432 def suppliers = Supplier.findAllByIsActive(true).sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } 434 433 435 434 return [ inventoryItemInstance : result.inventoryItemInstance, 436 possibleAlternateItems: possibleAlternateItems,437 435 suppliers: suppliers] 438 436 } … … 457 455 } 458 456 459 def possibleAlternateItems = inventoryItemService.getPossibleAlternateItems(result.inventoryItemInstance)460 457 def suppliers = Supplier.findAllByIsActive(true).sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } 461 458 render(view:'edit', model:[inventoryItemInstance: result.inventoryItemInstance.attach(), 462 possibleAlternateItems: possibleAlternateItems,463 459 suppliers: suppliers]) 464 460 } -
trunk/grails-app/domain/InventoryItem.groovy
r719 r720 23 23 } 24 24 25 static hasMany = [alternateItems: InventoryItem, 26 spareFor: Asset, 25 static hasMany = [spareFor: Asset, 27 26 inventoryMovements: InventoryMovement, 28 27 alternateSuppliers: Supplier] … … 60 59 } 61 60 62 def afterInsert = {63 addReverseAlternateItems()64 }65 66 /**67 * Add reverse alternateItem references.68 */69 def addReverseAlternateItems() {70 this.alternateItems.each() {71 if( !it.alternateItems?.contains(this) )72 it.addToAlternateItems(this)73 }74 }75 76 /**77 * Remove all reverse alternateItem references.78 * On update: reverse alternateItem handling must be done in the79 * service class since the before assignment alternateItems are required.80 */81 def removeReverseAlternateItems(alternateItems = this.alternateItems) {82 alternateItems.each() {83 it.removeFromAlternateItems(this)84 }85 }86 87 61 } -
trunk/grails-app/services/CreateDataService.groovy
r703 r720 1297 1297 estimatedUnitPriceAmount: 2.50, 1298 1298 estimatedUnitPriceCurrency: currency, 1299 alternateItems: InventoryItem.get(1),1300 1299 unitsInStock: 2, 1301 1300 reorderPoint: 0) -
trunk/grails-app/services/InventoryCsvService.groovy
r719 r720 59 59 "inventoryGroup", "inventoryType", 60 60 "suppliersPartNumber", "preferredSupplier", "alternateSuppliers", 61 " alternateItems", "spareFor"]61 "spareFor"] 62 62 63 63 def siteInstance … … 67 67 def supplierTypeUnknown = SupplierType.get(1) 68 68 def spareForInstance 69 def alternateItemInstance70 69 def inventoryTypeInstance 71 70 def unitOfMeasureInstance … … 85 84 86 85 def tempSpareFor = [] 87 def tempAlternateItems = []88 86 89 87 def nextLine = { … … 289 287 290 288 inventoryParams.alternateSuppliers.add(alternateSupplierInstance) 291 }292 293 // AlternateItems.294 tempAlternateItems = parseInputList(inventoryParams.alternateItems)295 inventoryParams.alternateItems = []296 297 for(tempAlternateItem in tempAlternateItems) {298 tempAlternateItem = WordUtils.capitalize(tempAlternateItem)299 alternateItemInstance = InventoryItem.findByName(tempAlternateItem)300 if(!alternateItemInstance) {301 alternateItemInstance = new InventoryItem(name: tempAlternateItem,302 description: "Generated from alternateItems during import, details may not be correct.",303 reorderPoint: 0,304 inventoryGroup: inventoryGroupInstance,305 inventoryType: inventoryTypeInstance,306 unitOfMeasure: unitOfMeasureInstance,307 inventoryLocation: inventoryLocationInstance)308 if(!alternateItemInstance.save()) {309 log.error "Failed to create alternateItems on line: " + lineNumber310 return fail(code: "inventory.import.failure", args: [lineNumber, logFileLink])311 }312 }313 314 inventoryParams.alternateItems.add(alternateItemInstance)315 289 } 316 290 -
trunk/grails-app/services/InventoryItemService.groovy
r636 r720 13 13 def sessionFactory 14 14 def propertyInstanceMap = org.codehaus.groovy.grails.plugins.DomainClassGrailsPlugin.PROPERTY_INSTANCE_MAP 15 16 /**17 * Prepare a sorted list of possible alternateItems.18 */19 def getPossibleAlternateItems(inventoryItemInstance) {20 def criteria = inventoryItemInstance.createCriteria()21 def possibleAlternateItems = criteria {22 and {23 eq('isActive', true)24 notEqual('id', inventoryItemInstance.id)25 }26 }.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }27 }28 15 29 16 /** … … 129 116 return fail(code:"inventoryMovement.still.associated") 130 117 131 result.inventoryItemInstance.removeReverseAlternateItems()132 133 118 try { 134 119 result.inventoryItemInstance.delete(flush:true) … … 181 166 } 182 167 183 def previousAlternateItems = new ArrayList(result.inventoryItemInstance.alternateItems)184 185 168 result.inventoryItemInstance.properties = params 186 169 187 170 if(result.inventoryItemInstance.hasErrors() || !result.inventoryItemInstance.save()) 188 171 return fail(code:"default.update.failure") 189 190 result.inventoryItemInstance.removeReverseAlternateItems(previousAlternateItems)191 result.inventoryItemInstance.addReverseAlternateItems()192 172 193 173 // Success. -
trunk/grails-app/views/inventoryItemDetailed/edit.gsp
r719 r720 220 220 <tr class="prop"> 221 221 <td valign="top" class="name"> 222 <label for="alternateItems">Alternate Items:</label>223 </td>224 <td valign="top" class="value ${hasErrors(bean:inventoryItemInstance,field:'alternateItems','errors')}">225 <g:select name="alternateItems"226 from="${possibleAlternateItems}"227 size="5" multiple="yes" optionKey="id"228 value="${inventoryItemInstance?.alternateItems.id}" noSelection="['':'--None--']"/>229 230 </td>231 </tr>232 233 <tr class="prop">234 <td valign="top" class="name">235 222 <label for="inventoryGroup">Inventory Group:</label> 236 223 </td> -
trunk/grails-app/views/inventoryItemDetailed/show.gsp
r719 r720 180 180 181 181 <tr class="prop"> 182 <td valign="top" class="name">Alternate Items:</td>183 184 <td valign="top" style="text-align:left;" class="value">185 <ul>186 <g:each var="a" in="${ inventoryItemInstance.alternateItems.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } }">187 <li><g:link controller="inventoryItemDetailed" action="show" id="${a.id}">${a?.encodeAsHTML()}</g:link></li>188 </g:each>189 </ul>190 </td>191 </tr>192 193 <tr class="prop">194 182 <td valign="top" class="name">Spare For:</td> 195 183
Note: See TracChangeset
for help on using the changeset viewer.