mirror of
https://github.com/Gnucash/gnucash.git
synced 2026-09-03 20:53:02 -05:00
A plugin to import CSV data as a new invoice or bill. Based on code written by Sebastian Held.
Also includes a python script to massage a downloaded order form into the correct format for import. See contrib/rapid2gnucash.py This works with Rapid Electronics (UK) and can be used as a basis for other vendors. Users need to add a line in their ~/.gnucash/config.user for the module to be loaded: (gnc:module-load "gnucash/plugins/bi_import" 0) See bug #624911 for more details. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20034 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Executable
+74
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env python
|
||||
'''
|
||||
# rapid2gnucash.py
|
||||
#
|
||||
# Copyright 2010 Mike Evans <mikee@millstreamcomputing.co.uk>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301, USA.
|
||||
|
||||
Convert a CSV file exported from Rapid Electronics (UK) to a form importable by GnuCash
|
||||
Line format is:
|
||||
line number,product code,quantity,availability,product description,unit price,discounts,line total,delivery,sub total,vat,grand total
|
||||
|
||||
Useage: rapid2gnucash.py DOWNLOADED_BASKET.csv "ORDER_NUMBER" <"Expense account"> > output.csv
|
||||
|
||||
We need to remove first line and totals
|
||||
|
||||
Format needs to be:
|
||||
#id,date_opened,vendor_id,billing_id,notes,date,desc,action,account,quantity,price,disc_type,disc_how,discount,taxable,taxincluded,tax_table,date_posted,due_date,account_posted,memo_posted,accu_splits,
|
||||
Not all fields need to have values but the delimiters (,) do.
|
||||
Some fields are compulsory: id, vendor_id, action, quantity, price, taxable
|
||||
'''
|
||||
import sys
|
||||
import csv
|
||||
|
||||
VENDOR_ID="000013" # Obviously this needs to match your vendor ID
|
||||
try:
|
||||
INFILE=sys.argv[1]
|
||||
except:
|
||||
print "No input files specified."
|
||||
print "Useage: Useage: rapid2gnucash.py DOWNLOADED_BASKET.csv \"ORDER_NUMBER\""
|
||||
quit(1)
|
||||
try:
|
||||
INV_ID=sys.argv[2]
|
||||
except:
|
||||
print "No order number specified."
|
||||
print "Useage: Useage: rapid2gnucash.py DOWNLOADED_BASKET.csv \"ORDER_NUMBER\""
|
||||
quit(1)
|
||||
try:
|
||||
ACCOUNT=sys.argv[3]
|
||||
except:
|
||||
ACCOUNT="Expenses:Materials General" # Default if absent on the command line. Edit to suit your account tree
|
||||
|
||||
Reader = csv.reader(open(INFILE), delimiter=',')
|
||||
|
||||
# Need to ignore 1st and last rows.
|
||||
#Last row contains delivery, subtotal, VAT, total so these should be read too
|
||||
|
||||
for row in Reader:
|
||||
if row[0].isdigit(): # We only use numbered lines
|
||||
outline=(INV_ID + ",," + VENDOR_ID + ",,,," + row[1] + " > " + row[4] + ",ea," +
|
||||
ACCOUNT + "," + row[2] + "," + row[5].replace("GBP", "") + ",,,,no,,,,,,,,")
|
||||
print outline
|
||||
elif not row[0]: # Last row? Has empty first element
|
||||
delivery = row[8].replace("GBP", "")
|
||||
vat = row[10].replace("GBP", "")
|
||||
outline=(INV_ID + ",," + VENDOR_ID + ",,,," + "DELIVERY" + ",ea," +
|
||||
"Expenses:Postage and Delivery" + "," + "1" + "," + delivery + ",,,,no,,,,,,,,")
|
||||
print outline # pipe to file for GnuCash import
|
||||
outline=(INV_ID + ",," + VENDOR_ID + ",,,," + "VAT" + ",tax," +
|
||||
"Expenses:VAT" + "," + "1" + "," + vat + ",,,,no,,,,,,,,")
|
||||
print outline # pipe to file for GnuCash import
|
||||
Reference in New Issue
Block a user