GnuCash c935c2f+
Loading...
Searching...
No Matches
Functions | Variables
simple_invoice_insert.py File Reference

Add an invoice to a set of books. More...

Go to the source code of this file.

Functions

 simple_invoice_insert.gnc_numeric_from_decimal (decimal_value)
 

Variables

 simple_invoice_insert.s = Session(argv[1], SessionOpenMode.SESSION_NORMAL_OPEN)
 
 simple_invoice_insert.book = s.book
 
 simple_invoice_insert.root = book.get_root_account()
 
 simple_invoice_insert.commod_table = book.get_table()
 
 simple_invoice_insert.CAD = commod_table.lookup('CURRENCY', 'CAD')
 
 simple_invoice_insert.my_customer = book.CustomerLookupByID(argv[2])
 
 simple_invoice_insert.assets = root.lookup_by_name("Assets")
 
 simple_invoice_insert.receivables = assets.lookup_by_name("Receivables")
 
 simple_invoice_insert.income = root.lookup_by_name("Income")
 
 simple_invoice_insert.invoice = Invoice(book, argv[3], CAD, my_customer )
 
 simple_invoice_insert.description = argv[4]
 
 simple_invoice_insert.invoice_value = gnc_numeric_from_decimal(Decimal(argv[5]))
 
 simple_invoice_insert.tax_table = book.TaxTableLookupByName('good tax')
 
 simple_invoice_insert.invoice_entry = Entry(book, invoice)
 

Detailed Description

Add an invoice to a set of books.

Author
Mark Jenkins, ParIT Worker Co-operative mark@.nosp@m.pari.nosp@m.t.ca

Definition in file simple_invoice_insert.py.

Function Documentation

◆ gnc_numeric_from_decimal()

simple_invoice_insert.gnc_numeric_from_decimal (   decimal_value)

Definition at line 57 of file simple_invoice_insert.py.

57def gnc_numeric_from_decimal(decimal_value):
58 sign, digits, exponent = decimal_value.as_tuple()
59
60 # convert decimal digits to a fractional numerator
61 # equivalent to
62 # numerator = int(''.join(digits))
63 # but without the wated conversion to string and back,
64 # this is probably the same algorithm int() uses
65 numerator = 0
66 TEN = int(Decimal(0).radix()) # this is always 10
67 numerator_place_value = 1
68 # add each digit to the final value multiplied by the place value
69 # from least significant to most significant
70 for i in range(len(digits)-1,-1,-1):
71 numerator += digits[i] * numerator_place_value
72 numerator_place_value *= TEN
73
74 if decimal_value.is_signed():
75 numerator = -numerator
76
77 # if the exponent is negative, we use it to set the denominator
78 if exponent < 0 :
79 denominator = TEN ** (-exponent)
80 # if the exponent isn't negative, we bump up the numerator
81 # and set the denominator to 1
82 else:
83 numerator *= TEN ** exponent
84 denominator = 1
85
86 return GncNumeric(numerator, denominator)
87
88
The primary numeric class for representing amounts and values.

Variable Documentation

◆ assets

simple_invoice_insert.assets = root.lookup_by_name("Assets")

Definition at line 100 of file simple_invoice_insert.py.

◆ book

simple_invoice_insert.book = s.book

Definition at line 91 of file simple_invoice_insert.py.

◆ CAD

simple_invoice_insert.CAD = commod_table.lookup('CURRENCY', 'CAD')

Definition at line 94 of file simple_invoice_insert.py.

◆ commod_table

simple_invoice_insert.commod_table = book.get_table()

Definition at line 93 of file simple_invoice_insert.py.

◆ description

simple_invoice_insert.description = argv[4]

Definition at line 105 of file simple_invoice_insert.py.

◆ income

simple_invoice_insert.income = root.lookup_by_name("Income")

Definition at line 102 of file simple_invoice_insert.py.

◆ invoice

simple_invoice_insert.invoice = Invoice(book, argv[3], CAD, my_customer )

Definition at line 104 of file simple_invoice_insert.py.

◆ invoice_entry

simple_invoice_insert.invoice_entry = Entry(book, invoice)

Definition at line 108 of file simple_invoice_insert.py.

◆ invoice_value

simple_invoice_insert.invoice_value = gnc_numeric_from_decimal(Decimal(argv[5]))

Definition at line 106 of file simple_invoice_insert.py.

◆ my_customer

simple_invoice_insert.my_customer = book.CustomerLookupByID(argv[2])

Definition at line 96 of file simple_invoice_insert.py.

◆ receivables

simple_invoice_insert.receivables = assets.lookup_by_name("Receivables")

Definition at line 101 of file simple_invoice_insert.py.

◆ root

simple_invoice_insert.root = book.get_root_account()

Definition at line 92 of file simple_invoice_insert.py.

◆ s

simple_invoice_insert.s = Session(argv[1], SessionOpenMode.SESSION_NORMAL_OPEN)

Definition at line 89 of file simple_invoice_insert.py.

◆ tax_table

simple_invoice_insert.tax_table = book.TaxTableLookupByName('good tax')

Definition at line 107 of file simple_invoice_insert.py.