Changeset 719 for trunk/grails-app/services
- Timestamp:
- Nov 25, 2010, 8:47:00 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/InventoryCsvService.groovy
r718 r719 52 52 def line = [] 53 53 def lineNumber = 0 54 def maxNumberOfColumns = 2 354 def maxNumberOfColumns = 20 55 55 def inventoryParams = [:] 56 56 def inventoryProperties = ["name", "description", "comment", "unitsInStock", "reorderPoint", "reorderQuantity", … … 59 59 "inventoryGroup", "inventoryType", 60 60 "suppliersPartNumber", "preferredSupplier", "alternateSuppliers", 61 "manufacturersPartNumber", "preferredManufacturer", "alternateManufacturers",62 61 "alternateItems", "spareFor"] 63 62 … … 69 68 def spareForInstance 70 69 def alternateItemInstance 71 def preferredManufacturerInstance72 def alternateManufacturerInstance73 def manufacturerTypeInstance74 def manufacturerTypeUnknown = ManufacturerType.get(1)75 70 def inventoryTypeInstance 76 71 def unitOfMeasureInstance … … 88 83 def tempSupplierType = '' 89 84 def tempSupplierItemAndType = [] 90 91 def tempPreferredManufacturerItemAndType = ''92 def tempPreferredManufacturerItem = ''93 def tempPreferredManufacturerType = ''94 95 def tempAlternateManufacturers = []96 def tempManufacturerItem = ''97 def tempManufacturerType = ''98 def tempManufacturerItemAndType = []99 85 100 86 def tempSpareFor = [] … … 238 224 return fail(code: "inventory.import.failure", args: [lineNumber, logFileLink]) 239 225 } 240 }241 242 // Preferred Manufacturer243 if(inventoryParams.preferredManufacturer) {244 tempPreferredManufacturerItemAndType = parseItemAndType(inventoryParams.preferredManufacturer)245 tempPreferredManufacturerItem = WordUtils.capitalize(tempPreferredManufacturerItemAndType[0])246 247 preferredManufacturerInstance = Manufacturer.findByName(tempPreferredManufacturerItem)248 if(!preferredManufacturerInstance) {249 250 // Manufacturer Type.251 if(tempPreferredManufacturerItemAndType.size == 2) {252 tempPreferredManufacturerType = WordUtils.capitalize(tempPreferredManufacturerItemAndType[1])253 manufacturerTypeInstance = ManufacturerType.findByName(tempPreferredManufacturerType)254 }255 else256 manufacturerTypeInstance = manufacturerTypeUnknown257 if(!manufacturerTypeInstance) {258 log.error "Failed to find preferred manufacturer type on line: " + lineNumber259 return fail(code: "inventory.import.failure", args: [lineNumber, logFileLink])260 }261 262 preferredManufacturerInstance = new Manufacturer(name: tempPreferredManufacturerItem,263 manufacturerType: manufacturerTypeInstance)264 if(!preferredManufacturerInstance.save()) {265 log.error "Failed to create preferred manufacturer on line: " + lineNumber266 return fail(code: "inventory.import.failure", args: [lineNumber, logFileLink])267 }268 }269 }270 else271 preferredManufacturerInstance = null272 273 // Alternate Manufacturers.274 tempAlternateManufacturers = parseInputList(inventoryParams.alternateManufacturers)275 inventoryParams.alternateManufacturers = []276 277 for(tempManufacturer in tempAlternateManufacturers) {278 tempManufacturerItemAndType = parseItemAndType(tempManufacturer)279 tempManufacturerItem = WordUtils.capitalizeFully(tempManufacturerItemAndType[0])280 281 alternateManufacturerInstance = Manufacturer.findByName(tempManufacturerItem)282 if(!alternateManufacturerInstance) {283 284 // ManufacturerType.285 if(tempManufacturerItemAndType.size == 2) {286 tempManufacturerType = WordUtils.capitalize(tempManufacturerItemAndType[1])287 manufacturerTypeInstance = ManufacturerType.findByName(tempManufacturerType)288 }289 else290 manufacturerTypeInstance = manufacturerTypeUnknown291 if(!manufacturerTypeInstance) {292 log.error "Failed to find manufacturer type on line: " + lineNumber293 return fail(code: "inventory.import.failure", args: [lineNumber, logFileLink])294 }295 296 alternateManufacturerInstance = new Manufacturer(name: tempManufacturerItem,297 manufacturerType: manufacturerTypeInstance)298 if(!alternateManufacturerInstance.save()) {299 log.error "Failed to create manufacturers on line: " + lineNumber300 return fail(code: "inventory.import.failure", args: [lineNumber, logFileLink])301 }302 }303 304 inventoryParams.alternateManufacturers.add(alternateManufacturerInstance)305 226 } 306 227 … … 417 338 inventoryParams.unitOfMeasure = unitOfMeasureInstance 418 339 inventoryParams.preferredSupplier = preferredSupplierInstance 419 inventoryParams.preferredManufacturer = preferredManufacturerInstance420 340 421 341 // Name. … … 485 405 writer.writeNext("Comment: Required columns are marked with a (*) in the header line.") 486 406 writer.writeNext("Comment: Lists of items in a column must be separated by a semicolon (;), not a comma.") 487 writer.writeNext("Comment: The at symbol (@) is reserved for indicating supplier and manufacturertypes.")407 writer.writeNext("Comment: The at symbol (@) is reserved for indicating supplier types.") 488 408 writer.writeNext("Comment: Identical and existing names will be considered as the same item.") 489 409 writer.writeNext("Comment: Lines containing 'comment' will be ignored.") … … 515 435 "123", "Multi Supplier@Local", 516 436 "Multi Distributors1@OEM; Multi Distributors2@Local", 517 "321", "Master Manufacturer@OEM",518 "Mega Manufacturer1@OEM;Mega Manufacturer2@Alternate",519 437 "2204E-2RS", "" 520 438 ] as String[]) … … 530 448 "456KL", "Multi Supplier", 531 449 "Multi Distributors1; Multi Distributors2", 532 "654OP", "Master Manufacturer",533 "Mega Manufacturer1;Mega Manufacturer2",534 450 "", "" 535 451 ] as String[]) … … 582 498 }.collect { it.name + "@" + it.supplierType }.join(';') ) 583 499 584 row.add(inventoryItem.manufacturersPartNumber)585 586 if(inventoryItem.preferredManufacturer)587 row.add( inventoryItem.preferredManufacturer.name + "@" + inventoryItem.preferredManufacturer.manufacturerType )588 else589 row.add('')590 591 row.add(inventoryItem.alternateManufacturers.sort { p1, p2 ->592 p1.name.compareToIgnoreCase(p2.name)593 }.collect { it.name + "@" + it.manufacturerType }.join(';'))594 595 row.add(inventoryItem.alternateItems.sort { p1, p2 ->596 p1.name.compareToIgnoreCase(p2.name)597 }.collect { it.name }.join(';') )598 599 500 row.add(inventoryItem.spareFor.sort { p1, p2 -> 600 501 p1.name.compareToIgnoreCase(p2.name) … … 813 714 "Estimated Unit Price", "Currency", "Enable Reorder", "Location*", "Store*", "Site*", "Group*", "Type*", 814 715 "Supplier's Part Number", "Preferred Supplier", "Alternate Suppliers", 815 " Manufacturer's Part Number", "Preferred Manufacturer", "Alternate Manufacturers", "Alternate Item", "Spare For"]716 "Alternate Item", "Spare For"] 816 717 } 817 718
Note: See TracChangeset
for help on using the changeset viewer.