Changeset 405
- Timestamp:
- Feb 23, 2010, 10:14:19 PM (15 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/InventoryItemDetailedController.groovy
r403 r405 126 126 params.action='show' 127 127 128 if(!InventoryItem.exists(params.id)) { 129 flash.message = "InventoryItem not found with id ${params.id}" 128 def result = inventoryItemService.show(params) 129 130 if(!result.error) { 131 132 def model = [ inventoryItemInstance: result.inventoryItemInstance, 133 inventoryMovementList: result.inventoryMovementList, 134 inventoryMovementListTotal: result.inventoryMovementListTotal, 135 inventoryMovementListMax: result.inventoryMovementListMax, 136 showTab: result.showTab] 137 138 if(session.inventoryMovementTaskId) { 139 model.inventoryMovementInstance = new InventoryMovement() 140 model.inventoryMovementInstance.task = Task.get(session.inventoryMovementTaskId) 141 model.inventoryMovementInstance.quantity = 1 142 } 143 144 // Success. 145 return model 146 } 147 148 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 149 redirect(action:search) 150 return 151 } 152 153 def delete = { 154 def result = inventoryItemService.delete(params) 155 156 if(!result.error) { 157 flash.message = g.message(code: "default.delete.success", args: ["InventoryItem", params.id]) 158 redirect(action:list) 159 return 160 } 161 162 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 163 164 if(result.error.code == "default.not.found") { 130 165 redirect(action:search) 131 166 return 132 167 } 133 168 134 def result = inventoryItemService.prepareShowData(params) 135 136 if(result.error) { 137 flash.message = "Could not to prepare the data to show item with id: ${params.id}." 138 redirect(action:search) 139 return 140 } 141 142 def model = [ inventoryItemInstance: result.inventoryItemInstance, 143 inventoryMovementList: result.inventoryMovementList, 144 inventoryMovementListTotal: result.inventoryMovementListTotal, 145 inventoryMovementListMax: result.inventoryMovementListMax, 146 showTab: result.showTab] 147 148 if(session.inventoryMovementTaskId) { 149 model.inventoryMovementInstance = new InventoryMovement() 150 model.inventoryMovementInstance.task = Task.get(session.inventoryMovementTaskId) 151 model.inventoryMovementInstance.quantity = 1 152 } 153 154 return model 155 } 156 157 def delete = { 158 def inventoryItemInstance = InventoryItem.get( params.id ) 159 if(inventoryItemInstance) { 160 try { 161 inventoryItemInstance.delete(flush:true) 162 flash.message = "InventoryItem ${params.id} deleted" 163 redirect(action:search) 164 } 165 catch(org.springframework.dao.DataIntegrityViolationException e) { 166 flash.message = "InventoryItem ${params.id} could not be deleted" 167 redirect(action:show,id:params.id) 168 } 169 } 170 else { 171 flash.message = "InventoryItem not found with id ${params.id}" 172 redirect(action:search) 173 } 169 redirect(action:show, id: params.id) 174 170 } 175 171 … … 180 176 params.action='edit' 181 177 182 def inventoryItemInstance = InventoryItem.get( params.id ) 183 184 if(!inventoryItemInstance) { 185 flash.message = "InventoryItem not found with id ${params.id}" 178 def result = inventoryItemService.edit(params) 179 180 if(!result.error) 181 return [ inventoryItemInstance : result.inventoryItemInstance ] 182 183 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 184 redirect(action:search) 185 } 186 187 def update = { 188 def result = inventoryItemService.update(params) 189 190 if(!result.error) { 191 flash.message = g.message(code: "default.update.success", args: ["InventoryItem", params.id]) 192 redirect(action:show, id: params.id) 193 return 194 } 195 196 if(result.error.code == "default.not.found") { 197 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 186 198 redirect(action:search) 187 } 188 else { 189 return [ inventoryItemInstance : inventoryItemInstance ] 190 } 191 } 192 193 def update = { 194 def inventoryItemInstance = InventoryItem.get( params.id ) 195 if(inventoryItemInstance) { 196 if(params.version) { 197 def version = params.version.toLong() 198 if(inventoryItemInstance.version > version) { 199 200 inventoryItemInstance.errors.rejectValue("version", "default.optimistic.locking.failure") 201 render(view:'edit',model:[inventoryItemInstance:inventoryItemInstance]) 202 return 203 } 204 } 205 inventoryItemInstance.properties = params 206 if(!inventoryItemInstance.hasErrors() && inventoryItemInstance.save(flush: true)) { 207 flash.message = "InventoryItem ${params.id} updated" 208 redirect(action:show,id:inventoryItemInstance.id) 209 } 210 else { 211 render(view:'edit',model:[inventoryItemInstance:inventoryItemInstance]) 212 } 213 } 214 else { 215 flash.message = "InventoryItem not found with id ${params.id}" 216 redirect(action:search) 217 } 199 return 200 } 201 202 render(view:'edit', model:[inventoryItemInstance: result.inventoryItemInstance.attach()]) 218 203 } 219 204 220 205 def create = { 221 def inventoryItemInstance = new InventoryItem() 222 inventoryItemInstance.properties = params 223 return ['inventoryItemInstance':inventoryItemInstance] 206 def result = inventoryItemService.create(params) 207 208 if(!result.error) 209 return [inventoryItemInstance: result.inventoryItemInstance] 210 211 //flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 212 redirect(action: search) 224 213 } 225 214 226 215 def save = { 227 def inventoryItemInstance = new InventoryItem(params) 228 if(!inventoryItemInstance.hasErrors() && inventoryItemInstance.save(flush: true)) { 229 flash.message = "InventoryItem ${inventoryItemInstance.id} created" 230 redirect(action:show,id:inventoryItemInstance.id) 231 } 232 else { 233 render(view:'create',model:[inventoryItemInstance:inventoryItemInstance]) 234 } 216 def result = inventoryItemService.save(params) 217 218 if(!result.error) { 219 flash.message = g.message(code: "default.create.success", args: ["InventoryItem", result.inventoryItemInstance.id]) 220 redirect(action:show, id: result.inventoryItemInstance.id) 221 return 222 } 223 224 //flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 225 render(view:'create', model:[inventoryItemInstance: result.inventoryItemInstance]) 235 226 } 236 227 … … 252 243 def p = [:] 253 244 p.id = result.inventoryMovementInstance.inventoryItem?.id 254 def r = inventoryItemService. prepareShowData(p)245 def r = inventoryItemService.show(p) 255 246 256 247 def model = [ inventoryItemInstance: r.inventoryItemInstance, -
trunk/grails-app/domain/InventoryItem.groovy
r182 r405 9 9 String description = "" 10 10 String manufacturersPartNumber 11 BigDecimal estimatedUnitPriceAmount 12 Currency estimatedUnitPriceCurrency 11 13 String suppliersPartNumber 12 14 Integer unitsInStock = 0 … … 36 38 unitsInStock(min:0) 37 39 unitOfMeasure() 40 estimatedUnitPriceAmount(nullable:true, max: new BigDecimal(999999999999)) 41 estimatedUnitPriceCurrency(nullable:true) 38 42 reorderPoint() 39 43 enableReorder() -
trunk/grails-app/i18n/messages.properties
r402 r405 119 119 task.associatedAssets=Associated Assets 120 120 task.associatedAssets.help=These assets are to be associated with this task, but costs will not be assigned. 121 122 123 inventoryItem.notFound=Could not complete operation, inventory item not found.124 121 125 122 inventoryMovement.quantity.insufficientItemsInStock=Could not complete operation, insufficient items in stock. -
trunk/grails-app/services/InventoryItemService.groovy
r226 r405 11 11 * @param params The incoming params as normally passed to the show view 12 12 * primarily including the id of the inventoryItem. 13 * @returns A map containing result.error=true (if any error) and result.inventoryItemInstance (if available) 14 * and 13 * @returns A map containing result.error, if any error, otherwise result.inventoryItemInstance. 15 14 */ 16 def prepareShowData(params) {15 def show(params) { 17 16 def result = [:] 18 19 def fail = { Object[] args -> 20 if(args.size() == 2) result.errors = [args[0], args[1]] 21 result.error = true 17 def fail = { Map m -> 18 result.error = [ code: m.code, args: ["InventoryItem", params.id] ] 22 19 return result 23 20 } 21 22 result.inventoryItemInstance = InventoryItem.get( params.id ) 23 24 if(!result.inventoryItemInstance) 25 return fail(code:"default.not.found") 24 26 25 27 result.showTab = [:] … … 35 37 } 36 38 37 result.inventoryItemInstance = InventoryItem.get( params.id )38 39 if(!result.inventoryItemInstance)40 return fail("inventoryItem", "inventoryItem.notFound")41 42 39 def p = [:] 43 40 p.max = result.inventoryMovementListMax = 10 … … 47 44 result.inventoryMovementListTotal = InventoryMovement.countByInventoryItem(result.inventoryItemInstance) 48 45 49 // Success 46 // Success. 50 47 return result 51 48 52 } // end prepareShowData() 49 } // end show() 50 51 def delete(params) { 52 def result = [:] 53 def fail = { Map m -> 54 result.error = [ code: m.code, args: ["InventoryItem", params.id] ] 55 return result 56 } 57 58 result.inventoryItemInstance = InventoryItem.get(params.id) 59 60 if(!result.inventoryItemInstance) 61 return fail(code:"default.not.found") 62 63 try { 64 result.inventoryItemInstance.delete(flush:true) 65 return result //Success. 66 } 67 catch(org.springframework.dao.DataIntegrityViolationException e) { 68 return fail(code:"default.delete.failure") 69 } 70 71 } 72 73 def edit(params) { 74 def result = [:] 75 def fail = { Map m -> 76 result.error = [ code: m.code, args: ["InventoryItem", params.id] ] 77 return result 78 } 79 80 result.inventoryItemInstance = InventoryItem.get(params.id) 81 82 if(!result.inventoryItemInstance) 83 return fail(code:"default.not.found") 84 85 // Success. 86 return result 87 } 88 89 def update(params) { 90 InventoryItem.withTransaction { status -> 91 def result = [:] 92 93 def fail = { Map m -> 94 status.setRollbackOnly() 95 if(result.inventoryItemInstance && m.field) 96 result.inventoryItemInstance.errors.rejectValue(m.field, m.code) 97 result.error = [ code: m.code, args: ["InventoryItem", params.id] ] 98 return result 99 } 100 101 result.inventoryItemInstance = InventoryItem.get(params.id) 102 103 if(!result.inventoryItemInstance) 104 return fail(code:"default.not.found") 105 106 // Optimistic locking check. 107 if(params.version) { 108 if(result.inventoryItemInstance.version > params.version.toLong()) 109 return fail(field:"version", code:"default.optimistic.locking.failure") 110 } 111 112 result.inventoryItemInstance.properties = params 113 114 if(result.inventoryItemInstance.hasErrors() || !result.inventoryItemInstance.save()) 115 return fail(code:"default.update.failure") 116 117 // Success. 118 return result 119 120 } //end withTransaction 121 } // end update() 122 123 def create(params) { 124 def result = [:] 125 def fail = { Map m -> 126 result.error = [ code: m.code, args: ["InventoryItem", params.id] ] 127 return result 128 } 129 130 result.inventoryItemInstance = new InventoryItem() 131 result.inventoryItemInstance.properties = params 132 133 // success 134 return result 135 } 136 137 def save(params) { 138 InventoryItem.withTransaction { status -> 139 def result = [:] 140 141 def fail = { Map m -> 142 status.setRollbackOnly() 143 if(result.inventoryItemInstance && m.field) 144 result.inventoryItemInstance.errors.rejectValue(m.field, m.code) 145 result.error = [ code: m.code, args: ["InventoryItem", params.id] ] 146 return result 147 } 148 149 result.inventoryItemInstance = new InventoryItem(params) 150 151 if(result.inventoryItemInstance.hasErrors() || !result.inventoryItemInstance.save()) 152 return fail(code:"default.create.failure") 153 154 // success 155 return result 156 157 } //end withTransaction 158 } 159 53 160 54 161 } // end class -
trunk/grails-app/views/inventoryItemDetailed/create.gsp
r392 r405 13 13 </div> 14 14 <div class="body"> 15 <g:if test="${flash.message}"> 16 <div class="message">${flash.message}</div> 17 </g:if> 15 <g:render template="/shared/messages" /> 18 16 <g:hasErrors bean="${inventoryItemInstance}"> 19 17 <div class="errors"> … … 118 116 <tr class="prop"> 119 117 <td valign="top" class="name"> 118 <label for="averageDeliveryTime">Estimated Unit Price:</label> 119 </td> 120 <td valign="top"> 121 <input class="medium ${hasErrors(bean:inventoryItemInstance,field:'estimatedUnitPriceAmount','errors')}" 122 type="text" id="estimatedUnitPriceAmount" name="estimatedUnitPriceAmount" 123 value="${fieldValue(bean:inventoryItemInstance,field:'estimatedUnitPriceAmount')}" /> 124 <g:currencySelect name="estimatedUnitPriceCurrency" 125 value="${inventoryItemInstance.estimatedUnitPriceCurrency}" /> 126 </td> 127 </tr> 128 129 <tr class="prop"> 130 <td valign="top" class="name"> 120 131 <label for="suppliersPartNumber">Suppliers Part Number:</label> 121 132 </td> -
trunk/grails-app/views/inventoryItemDetailed/edit.gsp
r392 r405 14 14 </div> 15 15 <div class="body"> 16 <g:if test="${flash.message}"> 17 <div class="message">${flash.message}</div> 18 </g:if> 16 <g:render template="/shared/messages" /> 19 17 <g:hasErrors bean="${inventoryItemInstance}"> 20 18 <div class="errors"> … … 152 150 noSelection="['null':'--None--']"> 153 151 </g:select> 152 </td> 153 </tr> 154 155 <tr class="prop"> 156 <td valign="top" class="name"> 157 <label for="averageDeliveryTime">Estimated Unit Price:</label> 158 </td> 159 <td valign="top"> 160 <input class="medium ${hasErrors(bean:inventoryItemInstance,field:'estimatedUnitPriceAmount','errors')}" 161 type="text" id="estimatedUnitPriceAmount" name="estimatedUnitPriceAmount" 162 value="${inventoryItemInstance.estimatedUnitPriceAmount}" /> 163 <g:currencySelect name="estimatedUnitPriceCurrency" 164 value="${inventoryItemInstance.estimatedUnitPriceCurrency}" /> 154 165 </td> 155 166 </tr> -
trunk/grails-app/views/inventoryItemDetailed/search.gsp
r392 r405 16 16 </div> 17 17 <div class="body"> 18 <g:if test="${flash.message}"> 19 <div class="message">${flash.message}</div> 20 </g:if> 18 <g:render template="/shared/messages" /> 21 19 <filterpane:currentCriteria domainBean="InventoryItem" 22 20 action="search" -
trunk/grails-app/views/inventoryItemDetailed/show.gsp
r392 r405 15 15 </div> 16 16 <div class="body"> 17 <g:render template="/shared/messages" /> 17 18 <g:hasErrors bean="${inventoryMovementInstance}"> 18 <div class="errors">19 <g:renderErrors bean="${inventoryMovementInstance}" as="list" />20 </div>19 <div class="errors"> 20 <g:renderErrors bean="${inventoryMovementInstance}" as="list" /> 21 </div> 21 22 </g:hasErrors> 22 <g:if test="${flash.message}">23 <div class="message">${flash.message}</div>24 </g:if>25 23 26 24 <g:hasErrors bean="${inventoryItemInstance}"> 27 <div class="errors">28 <g:renderErrors bean="${inventoryItemInstance}" as="list" />29 </div>25 <div class="errors"> 26 <g:renderErrors bean="${inventoryItemInstance}" as="list" /> 27 </div> 30 28 </g:hasErrors> 31 29 … … 223 221 <td valign="top" class="name">Recommended Reorder Point:</td> 224 222 <td valign="top" class="value">${fieldValue(bean:inventoryItemInstance, field:'recommendedReorderPoint')}</td> 223 </tr> 224 225 <tr class="prop"> 226 <td valign="top" class="name">Estimated Unit Price:</td> 227 228 <td valign="top" class="value"> 229 <g:if test="${inventoryItemInstance.estimatedUnitPriceAmount}"> 230 ${inventoryItemInstance.estimatedUnitPriceAmount.encodeAsHTML()} 231 ${inventoryItemInstance.estimatedUnitPriceCurrency.encodeAsHTML()} 232 </g:if> 233 </td> 225 234 </tr> 226 235
Note: See TracChangeset
for help on using the changeset viewer.