49 from gnucash
import Session, GUID, GncNumeric, SessionOpenMode
50 from gnucash.gnucash_business
import Customer, Invoice, Entry
51 from gnucash.gnucash_core_c
import string_to_guid
52 from os.path
import abspath
54 from decimal
import Decimal
57 def gnc_numeric_from_decimal(decimal_value):
58 sign, digits, exponent = decimal_value.as_tuple()
66 TEN = int(Decimal(0).radix())
67 numerator_place_value = 1
70 for i
in range(len(digits)-1,-1,-1):
71 numerator += digits[i] * numerator_place_value
72 numerator_place_value *= TEN
74 if decimal_value.is_signed():
75 numerator = -numerator
79 denominator = TEN ** (-exponent)
83 numerator *= TEN ** exponent
89 s = Session(argv[1], SessionOpenMode.SESSION_NORMAL_OPEN)
92 root = book.get_root_account()
93 commod_table = book.get_table()
94 CAD = commod_table.lookup(
'CURRENCY',
'CAD')
96 my_customer = book.CustomerLookupByID(argv[2])
97 assert( my_customer !=
None )
98 assert( isinstance(my_customer, Customer) )
100 assets = root.lookup_by_name(
"Assets")
101 receivables = assets.lookup_by_name(
"Receivables")
102 income = root.lookup_by_name(
"Income")
104 invoice = Invoice(book, argv[3], CAD, my_customer )
105 description = argv[4]
106 invoice_value = gnc_numeric_from_decimal(Decimal(argv[5]))
107 tax_table = book.TaxTableLookupByName(
'good tax')
108 invoice_entry = Entry(book, invoice)
109 invoice_entry.SetInvTaxTable(tax_table)
110 invoice_entry.SetInvTaxIncluded(
False)
111 invoice_entry.SetDescription(description)
113 invoice_entry.SetInvAccount(income)
114 invoice_entry.SetInvPrice(invoice_value)
116 invoice.PostToAccount(receivables, datetime.date.today(), datetime.date.today(),
The primary numeric class for representing amounts and values.