Changeset 191 for trunk/grails-app/services
- Timestamp:
- Nov 19, 2009, 9:16:21 PM (15 years ago)
- Location:
- trunk/grails-app/services
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/InventoryMovementService.groovy
r177 r191 6 6 InventoryMovement.withTransaction { status -> 7 7 def result = [:] 8 definventoryMovementInstance = InventoryMovement.lock(params.id)9 if( inventoryMovementInstance) {10 def inventoryItem = InventoryItem.lock( inventoryMovementInstance.inventoryItem.id)11 result.taskId = inventoryMovementInstance.task.id8 result.inventoryMovementInstance = InventoryMovement.lock(params.id) 9 if(result.inventoryMovementInstance) { 10 def inventoryItem = InventoryItem.lock(result.inventoryMovementInstance.inventoryItem.id) 11 result.taskId = result.inventoryMovementInstance.task.id 12 12 13 13 if(!inventoryItem) { 14 14 status.setRollbackOnly() 15 inventoryMovementInstance.errors.rejectValue('inventoryItem', "inventoryMovement.inventoryItem.notFound") 16 result.inventoryMovementInstance = inventoryMovementInstance 15 result.inventoryMovementInstance.errors.rejectValue('inventoryItem', "inventoryMovement.inventoryItem.notFound") 17 16 result.error = true 18 17 return result 19 18 } 20 19 20 if(result.inventoryMovementInstance.task.taskStatus.id == 3) { 21 status.setRollbackOnly() 22 result.inventoryMovementInstance.errors.rejectValue('task', "task.operationNotPermittedOnCompleteTask") 23 result.error = true 24 return result 25 } 26 21 27 // Reverse the movement of inventory. 22 if(! inventoryMovementInstance.inventoryMovementType.incrementsInventory) {23 inventoryItem.unitsInStock += inventoryMovementInstance.quantity28 if(!result.inventoryMovementInstance.inventoryMovementType.incrementsInventory) { 29 inventoryItem.unitsInStock += result.inventoryMovementInstance.quantity 24 30 } 25 31 else { 26 if(inventoryItem.unitsInStock >= inventoryMovementInstance.quantity) {27 inventoryItem.unitsInStock -= inventoryMovementInstance.quantity32 if(inventoryItem.unitsInStock >= result.inventoryMovementInstance.quantity) { 33 inventoryItem.unitsInStock -= result.inventoryMovementInstance.quantity 28 34 } 29 35 else { 30 36 status.setRollbackOnly() 31 inventoryMovementInstance.errors.rejectValue('quantity', "inventoryMovement.quantity.insufficientItemsInStock") 32 result.inventoryMovementInstance = inventoryMovementInstance 37 result.inventoryMovementInstance.errors.rejectValue('quantity', "inventoryMovement.quantity.insufficientItemsInStock") 33 38 result.error = true 34 39 return result … … 37 42 38 43 if(inventoryItem.save() ) { 39 inventoryMovementInstance.delete() 44 // All went well if we get to this point. 45 result.inventoryMovementInstance.delete() 40 46 return result 41 47 } … … 58 64 InventoryMovement.withTransaction { status -> 59 65 def result = [:] 60 definventoryMovementInstance = new InventoryMovement(params)66 result.inventoryMovementInstance = new InventoryMovement(params) 61 67 62 if( inventoryMovementInstance.validate()) {63 def inventoryItem = InventoryItem.lock( inventoryMovementInstance.inventoryItem.id)64 result.taskId = inventoryMovementInstance.task.id68 if(result.inventoryMovementInstance.validate()) { 69 def inventoryItem = InventoryItem.lock(result.inventoryMovementInstance.inventoryItem.id) 70 result.taskId = result.inventoryMovementInstance.task.id 65 71 66 72 if(!inventoryItem) { 67 status.setRollbackOnly() 68 inventoryMovementInstance.errors.rejectValue('inventoryItem', "inventoryMovement.inventoryItem.notFound") 69 result.inventoryMovementInstance = inventoryMovementInstance 70 result.error = true 71 return result 73 status.setRollbackOnly() 74 result.inventoryMovementInstance.errors.rejectValue('inventoryItem', "inventoryMovement.inventoryItem.notFound") 75 result.error = true 76 return result 77 } 78 79 if(result.inventoryMovementInstance.task.taskStatus.id == 3) { 80 status.setRollbackOnly() 81 result.inventoryMovementInstance.errors.rejectValue('task', "task.operationNotPermittedOnCompleteTask") 82 result.error = true 83 return result 72 84 } 73 85 74 86 // Perform the movement of inventory. 75 if( inventoryMovementInstance.inventoryMovementType.incrementsInventory) {76 inventoryItem.unitsInStock += inventoryMovementInstance.quantity87 if(result.inventoryMovementInstance.inventoryMovementType.incrementsInventory) { 88 inventoryItem.unitsInStock += result.inventoryMovementInstance.quantity 77 89 } 78 90 else { 79 if(inventoryItem.unitsInStock >= inventoryMovementInstance.quantity) {80 inventoryItem.unitsInStock -= inventoryMovementInstance.quantity91 if(inventoryItem.unitsInStock >= result.inventoryMovementInstance.quantity) { 92 inventoryItem.unitsInStock -= result.inventoryMovementInstance.quantity 81 93 } 82 94 else { 83 95 status.setRollbackOnly() 84 inventoryMovementInstance.errors.rejectValue('quantity', "inventoryMovement.quantity.insufficientItemsInStock") 85 result.inventoryMovementInstance = inventoryMovementInstance 96 result.inventoryMovementInstance.errors.rejectValue('quantity', "inventoryMovement.quantity.insufficientItemsInStock") 86 97 result.error = true 87 98 return result … … 89 100 } 90 101 91 if(inventoryItem.save() && inventoryMovementInstance.save()) {92 result.inventoryMovementInstance = inventoryMovementInstance102 if(inventoryItem.save() && result.inventoryMovementInstance.save()) { 103 // All went well if we get to this point. 93 104 return result 94 105 } 95 106 else { 96 107 status.setRollbackOnly() 97 result.inventoryMovementInstance = inventoryMovementInstance98 108 result.error = true 99 109 return result … … 102 112 } 103 113 else { 104 result.inventoryMovementInstance = inventoryMovementInstance105 114 result.error = true 106 115 return result -
trunk/grails-app/services/TaskService.groovy
r186 r191 55 55 if(taskInstance.taskStatus.id == 3) { 56 56 status.setRollbackOnly() 57 result.entryInstance.errors.rejectValue('task', " entry.task.taskIsComplete")57 result.entryInstance.errors.rejectValue('task', "task.operationNotPermittedOnCompleteTask") 58 58 result.error = true 59 59 return result
Note: See TracChangeset
for help on using the changeset viewer.