Last change
on this file since 896 was
891,
checked in by gav, 14 years ago
|
Purchase Order first draft as per ticket #30, by John Yesberg.
|
File size:
1.3 KB
|
Line | |
---|
1 | class PurchaseOrderService { |
---|
2 | |
---|
3 | boolean transactional = false |
---|
4 | |
---|
5 | def serviceMethod() { |
---|
6 | |
---|
7 | } |
---|
8 | |
---|
9 | PurchaseOrderNumber findNextUnusedPurchaseOrderNumber() { |
---|
10 | def empty = PurchaseOrderNumber.list().find{it.purchaseOrder==null} |
---|
11 | return empty |
---|
12 | } |
---|
13 | |
---|
14 | PurchaseOrder getOrCreatePurchaseOrder(params) { |
---|
15 | def id = params.purchaseOrderNumber.id |
---|
16 | if (params.purchaseOrderNumber.id instanceof Long) { |
---|
17 | id = params.purchaseOrderNumber.id |
---|
18 | } else { |
---|
19 | id = params.purchaseOrderNumber.id.toString().toLong() |
---|
20 | } |
---|
21 | def pon = PurchaseOrderNumber.get(id) |
---|
22 | def po = pon?.purchaseOrder |
---|
23 | if (!po) { |
---|
24 | po = createPurchaseOrder(pon,params) |
---|
25 | } |
---|
26 | return po |
---|
27 | } |
---|
28 | |
---|
29 | PurchaseOrder createPurchaseOrder(pon,params) { |
---|
30 | def supplier = Supplier.get(params.supplier.id) |
---|
31 | def po = new PurchaseOrder(supplier:supplier) |
---|
32 | pon.purchaseOrder = po |
---|
33 | po.purchaseOrderNumber = pon |
---|
34 | pon.save(failOnError:true) // should cascade to save the PO as well. I wonder why it doesn't. |
---|
35 | po.save(failOnError:true) |
---|
36 | return po |
---|
37 | } |
---|
38 | |
---|
39 | List<PurchaseOrder> findDraftPurchaseOrderNumbers() { |
---|
40 | def drafts = PurchaseOrder.list().findAll{it.ordered == null}.collect{it.purchaseOrderNumber} |
---|
41 | return drafts |
---|
42 | } |
---|
43 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.