Last active
September 11, 2017 02:15
-
-
Save DanielOaks/10687964 to your computer and use it in GitHub Desktop.
Adds barcodes to Reckon item IIF lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
# Reckon IIF item list barcode adder | |
# written by Daniel Oaks <daniel@danieloaks.net> | |
# licensed under the BSD 2-clause license | |
# Caution: DO NOT USE IIF. IT CAN BORK YOUR SYSTEM EASILY. | |
# This basically reads through each item in your item IIF, to see if it has a barcode | |
# if it doesn't have a barcode and the item name contains a digit, it makes the barcode the same | |
# as the name to stop you from having to rescan 9000 items because of a silly missing barcod | |
# CAUTION: THIS CAN VERY WELL BREAK YOUR EVERYTHING | |
# I RECOMMEND DIFFS AFTER USING, TO MAKE SURE NOTHING ELSE IS BROKEN | |
# Workflow: | |
# From Reckon: File -> Utilities -> Export IIF -> Item List | |
# Save as items.iif in script dir | |
# Run tool | |
# diff and make sure nothing. NOTHING but the barcode changed in lines | |
# Reckon: File -> Utilities -> Import IIF -> 'items with barcodes.iif' | |
print 'add.barcodes.py' | |
print ' Written by Daniel Oaks <danneh@danneh.net>' | |
print ' Licensed under the BSD 2-clause license\n' | |
original_filename = 'items.iif' # assumptions! | |
converted_filename = 'items with barcodes.iif' | |
print 'Assuming input iif file is named:', original_filename | |
print 'Assuming output iif file is named:', converted_filename | |
print '' | |
# we only convert names that contain numbers! | |
import re | |
_digits = re.compile('\d') | |
def contains_digits(d): | |
return bool(_digits.search(d)) | |
current_columns = [] | |
total_rows = 0 | |
modified_rows = 0 | |
with open(original_filename, 'r') as orig: | |
with open(converted_filename, 'w') as conv: | |
for line in orig: | |
# header line | |
if line[0] == '!': | |
conv.write(line) | |
if line[1:8] == 'INVITEM': | |
current_columns = line[9:].split() | |
parse = True | |
else: | |
parse = False | |
# other lines | |
elif parse: | |
if line[:7] == 'INVITEM': | |
orig_row_values = line.lstrip('INVITEM').split('\t')[1:] | |
row = {} | |
for i in range(0, len(current_columns)): | |
row[current_columns[i]] = orig_row_values[i] | |
# if it's not stock, just write original | |
if row['INVITEMTYPE'] != 'STOCK': | |
conv.write(line) | |
# otherwise, write our modified version | |
else: | |
total_rows += 1 | |
# modify! | |
if row['BARCODE'] == '': | |
if contains_digits(row['NAME']): | |
# barcode is blank and name contains a number, change it over | |
modified_rows += 1 | |
row['BARCODE'] = row['NAME'] | |
# read values into new list | |
new_row_values = ['INVITEM'] | |
for i in range(0, len(current_columns)): | |
new_row_values.append(row[current_columns[i]]) | |
# and write out | |
conv.write('\t'.join(new_row_values)) | |
else: | |
conv.write(line) | |
else: | |
conv.write(line) | |
print 'Barcodes added to', modified_rows, 'of', total_rows, 'stock item rows.' | |
print 'WARNING: DIFF "items.iif" and "items with barcodes.iif" BEFORE IMPORTING.' | |
print 'Import it into a TEST Reckon file before you do anything else.' | |
print '\nThis can seriously bork your system, and Reckon recommends NEVER using IIF files.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment