source: trunk/grails-app/controllers/InventoryMovementDetailedController.groovy @ 191

Last change on this file since 191 was 191, checked in by gav, 10 years ago

Improve entry creation so that entryType is passed in with the associated submitButton.
Refactor InventoryMovementService and prevent create/delete of invenotryMovements on complete task.

File size: 2.7 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class InventoryMovementDetailedController extends BaseController {
4
5    def inventoryMovementService
6
7    def index = { redirect(action:list,params:params) }
8
9    // the delete, save and update actions only accept POST requests
10    static allowedMethods = [delete:'POST', save:'POST']
11
12    def list = {
13        flash.message = flash.message
14        redirect(controller:"taskDetailed", action:"search")
15    }
16
17    def show = {
18        def inventoryMovementInstance = InventoryMovement.get( params.id )
19
20        if(!inventoryMovementInstance) {
21            flash.message = "InventoryMovement not found with id ${params.id}"
22            redirect(action:list)
23        }
24        else { return [ inventoryMovementInstance : inventoryMovementInstance ] }
25    }
26
27    def delete = {
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)
33        }
34        else {
35            if(result.inventoryMovementInstance) {
36                // For some reason we have to call refresh() here to get a hibernate session
37                // and avoid a lazy initialisation error.
38                render(view:'show',model:[inventoryMovementInstance:result.inventoryMovementInstance.refresh()])
39            }
40            else {
41                flash.message = "Could not delete inventory movement."
42                redirect(controller:"taskDetailed", action:"search")
43            }
44        }
45    }
46
47    def create = {
48        if(!params.task?.id) {
49            flash.message = "Please select a task, then the Inventory tab."
50            redirect(controller:"taskDetailed", action:"search")
51        }
52        def inventoryMovementInstance = new InventoryMovement()
53        inventoryMovementInstance.properties = params
54        return ['inventoryMovementInstance':inventoryMovementInstance]
55    }
56
57    def save = {
58        def result = inventoryMovementService.move(params)
59
60        if(!result.error) {
61            flash.message = "Inventory Movement for ${result.inventoryMovementInstance.inventoryItem.name} created."
62            redirect(controller:"taskDetailed", action:"show", id: result.taskId)
63        }
64        else {
65            if(result.inventoryMovementInstance) {
66                render(view:'create',model:[inventoryMovementInstance:result.inventoryMovementInstance])
67            }
68            else {
69                flash.message = "Could not create inventory movement."
70                redirect(controller:"taskDetailed", action:"search", id:result.taskId)
71            }
72
73        }
74    }
75
76}
Note: See TracBrowser for help on using the repository browser.