52 from os.path
import abspath
53 from sys
import argv, exit
55 from datetime
import timedelta
56 from gnucash
import Session, Account, GncNumeric, SessionOpenMode
57 from gnucash.gnucash_business
import Customer, Employee, Vendor, Job, \
58 Address, Invoice, Entry, TaxTable, TaxTableEntry, GNC_AMT_TYPE_PERCENT, \
60 from gnucash.gnucash_core_c
import \
61 ACCT_TYPE_ASSET, ACCT_TYPE_RECEIVABLE, ACCT_TYPE_INCOME, \
62 GNC_OWNER_CUSTOMER, ACCT_TYPE_LIABILITY
65 print(
'not enough parameters')
66 print(
'usage: simple_business_create.py {new_book_url}')
68 print(
"python3 simple_business_create.py sqlite3:///home/blah/blah.gnucash")
73 s = Session(argv[1], SessionOpenMode.SESSION_NEW_OVERWRITE)
76 root = book.get_root_account()
77 commod_table = book.get_table()
78 CAD = commod_table.lookup(
'CURRENCY',
'CAD')
83 a.SetType(ACCT_TYPE_ASSET)
88 a2.SetName(
'Receivables')
89 a2.SetType(ACCT_TYPE_RECEIVABLE)
95 a3.SetType(ACCT_TYPE_INCOME)
100 a4.SetName(
'Liabilities')
101 a4.SetType(ACCT_TYPE_LIABILITY)
106 a5.SetName(
'Tax payable')
107 a5.SetType(ACCT_TYPE_LIABILITY)
113 a6.SetType(ACCT_TYPE_ASSET)
117 new_customer = Customer(book,
"1", CAD,
"Bill & Bob Industries")
120 address = new_customer.GetAddr()
121 address.SetName(
"Bill & Bob")
122 address.SetAddr1(
"201 Nowhere street")
124 new_employee = Employee(book,
"2", CAD,
"Reliable employee")
126 new_vendor = Vendor(book,
"3", CAD,
"Dependable vendor")
128 new_job = Job(book,
"4", new_vendor,
"Good clean, fun")
131 tax_table = TaxTable(book,
"good tax",
132 TaxTableEntry(a5,
True,
GncNumeric(700000, 100000) ) )
135 invoice_customer = Invoice(book,
"5", CAD, new_customer)
136 customer_extract = invoice_customer.GetOwner()
137 assert( isinstance(customer_extract, Customer) )
138 assert( customer_extract.GetName() == new_customer.GetName() )
140 invoice_employee = Invoice(book,
"6", CAD, new_employee)
141 employee_extract = invoice_employee.GetOwner()
142 assert( isinstance(employee_extract, Employee) )
143 assert( employee_extract.GetName() == new_employee.GetName() )
145 invoice_vendor = Invoice(book,
"7", CAD, new_vendor)
146 vendor_extract = invoice_vendor.GetOwner()
147 assert( isinstance(vendor_extract, Vendor) )
148 assert( vendor_extract.GetName() == new_vendor.GetName() )
150 invoice_job = Invoice(book,
"8", CAD, new_job)
151 job_extract = invoice_job.GetOwner()
152 assert( isinstance(job_extract, Job) )
153 assert( job_extract.GetName() == new_job.GetName() )
156 invoice_entry = Entry(book, invoice_customer)
157 invoice_entry.SetInvTaxTable(tax_table)
158 invoice_entry.SetInvTaxIncluded(
False)
159 invoice_entry.SetDescription(
"excellent product")
161 invoice_entry.SetInvAccount(a3)
163 invoice_entry.SetDateEntered(datetime.datetime.now())
165 invoice_customer.PostToAccount(a2, datetime.date.today(), datetime.date.today(),
166 "the memo",
True,
False)
168 new_customer.ApplyPayment(
None,
None, a2, a6,
GncNumeric(100,100),
169 GncNumeric(1), datetime.date.today(),
"",
"",
True)
171 invoice_customer.ApplyPayment(
None, a6,
GncNumeric(7,100),
174 vendor_bill_returns = book.BillLookupByID(
"7")
175 assert( vendor_bill_returns.GetID() ==
"7" )
176 vendor_extract = vendor_bill_returns.GetOwner()
177 assert( vendor_extract.GetName() == new_vendor.GetName() )
178 customer_invoice_returns = book.InvoiceLookupByID(
"5")
179 assert( customer_invoice_returns.GetID() ==
"5" )
180 customer_returns = book.CustomerLookupByID(
"1")
181 assert( customer_returns.GetName() == new_customer.GetName() )
The primary numeric class for representing amounts and values.