Ignore:
Timestamp:
Nov 2, 2009, 1:17:03 PM (15 years ago)
Author:
gav
Message:

Inventory movement quantity adjustments now done in a service.
InventoryMovementType now has an incrementsInventory flag, so not dependant on the text name.

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

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/InventoryMovementDetailedController.groovy

    r175 r177  
    22
    33class InventoryMovementDetailedController extends BaseController {
     4
     5    def inventoryMovementService
    46
    57    def index = { redirect(action:list,params:params) }
     
    2426
    2527    def delete = {
    26         def inventoryMovementInstance = InventoryMovement.get( params.id )
    27         if(inventoryMovementInstance) {
    28             try {
    29                 def taskId = inventoryMovementInstance.task?.id
    30                 inventoryMovementInstance.delete(flush:true)
    31                 flash.message = "InventoryMovement ${params.id} deleted"
    32                 redirect(controller:"taskDetailed", action:"show", id:taskId)
    33             }
    34             catch(org.springframework.dao.DataIntegrityViolationException e) {
    35                 flash.message = "InventoryMovement ${params.id} could not be deleted"
    36                 redirect(action:show,id:params.id)
    37             }
     28        def result = inventoryMovementService.reverseMove(params)
     29
     30        if(!result.error) {
     31            flash.message = "InventoryMovement ${params.id} deleted"
     32            redirect(controller:"taskDetailed", action:"show", id:result.taskId)
    3833        }
    3934        else {
    40             flash.message = "InventoryMovement not found with id ${params.id}"
    41             redirect(action:list)
     35            if(result.inventoryMovementInstance) {
     36                render(view:'show',model:[inventoryMovementInstance:result.inventoryMovementInstance])
     37            }
     38            else {
     39                flash.message = "Could not delete inventory movement."
     40                redirect(controller:"taskDetailed", action:"search", id:result.taskId)
     41            }
    4242        }
    4343    }
     
    5454
    5555    def save = {
    56         def inventoryMovementInstance = new InventoryMovement(params)
    57         if(!inventoryMovementInstance.hasErrors() && inventoryMovementInstance.save()) {
    58             flash.message = "Inventory Movement for ${inventoryMovementInstance.inventoryItem.name} created."
    59             redirect(controller:"taskDetailed", action:"show", id: params.task.id)
     56        def result = inventoryMovementService.move(params)
     57
     58        if(!result.error) {
     59            flash.message = "Inventory Movement for ${result.inventoryMovementInstance.inventoryItem.name} created."
     60            redirect(controller:"taskDetailed", action:"show", id: result.taskId)
    6061        }
    6162        else {
    62             render(view:'create',model:[inventoryMovementInstance:inventoryMovementInstance])
     63            if(result.inventoryMovementInstance) {
     64                render(view:'create',model:[inventoryMovementInstance:result.inventoryMovementInstance])
     65            }
     66            else {
     67                flash.message = "Could not create inventory movement."
     68                redirect(controller:"taskDetailed", action:"search", id:result.taskId)
     69            }
     70
    6371        }
    6472    }
     73
    6574}
  • trunk/grails-app/controllers/InventoryMovementTypeController.groovy

    r116 r177  
    2727        if(inventoryMovementTypeInstance) {
    2828            try {
    29                 inventoryMovementTypeInstance.delete()
     29                inventoryMovementTypeInstance.delete(flush:true)
    3030                flash.message = "InventoryMovementType ${params.id} deleted"
    3131                redirect(action:list)
     
    7777        else {
    7878            flash.message = "InventoryMovementType not found with id ${params.id}"
    79             redirect(action:edit,id:params.id)
     79            redirect(action:list)
    8080        }
    8181    }
Note: See TracChangeset for help on using the changeset viewer.