29 import gnucash.gnucash_core_c
as gnucash_core_c
31 from gnucash.function_class
import \
32 ClassFromFunctions, extract_attributes_with_prefix, \
33 default_arguments_decorator, method_function_returns_instance, \
34 methods_return_instance, methods_return_instance_lists
37 GnuCashCoreClass, GncNumeric, GncCommodity, Transaction, \
38 Split, Book, GncLot, Account, GUID
40 from gnucash.gnucash_core_c
import GNC_OWNER_CUSTOMER, GNC_OWNER_JOB, \
41 GNC_OWNER_EMPLOYEE, GNC_OWNER_VENDOR, \
42 GNC_PAYMENT_CASH, GNC_PAYMENT_CARD, \
43 GNC_DISC_PRETAX, GNC_DISC_SAMETIME, GNC_DISC_POSTTAX, \
44 GNC_TAXINCLUDED_YES, GNC_TAXINCLUDED_NO, GNC_TAXINCLUDED_USEGLOBAL, \
45 GNC_AMT_TYPE_VALUE, GNC_AMT_TYPE_PERCENT, GNC_ID_INVOICE
50 def __init__(self, book=None, id=None, currency=None, name=None,
53 if book==
None or id==
None or currency==
None:
55 "you must call GnuCashBusinessEntity.__init__ " 56 "with either a book, id, and currency, or an existing " 57 "low level swig proxy in the argument instance")
58 GnuCashCoreClass.__init__(self, book)
61 self.SetCurrency(currency)
66 GnuCashCoreClass.__init__(self, instance=instance)
77 def __init__(self, book=None, id=None, owner=None, name=None,
80 if book==
None or id==
None or owner==
None:
82 "you must call Job.__init__ " 83 "with either a book, id, and owner or an existing " 84 "low level swig proxy in the argument instance")
85 GnuCashCoreClass.__init__(self, book)
91 GnuCashCoreClass.__init__(self, instance=instance)
98 def __init__(self, book=None, name=None, first_entry=None, instance=None):
100 if book==
None or name==
None or first_entry==
None:
102 "you must call TaxTable.__init__ with either a " 103 "book, name, and first_entry, or an existing " 104 "low level swig proxy in the argument instance")
105 GnuCashCoreClass.__init__(self, book)
107 self.AddEntry(first_entry)
109 GnuCashCoreClass.__init__(self, instance=instance)
112 def __init__(self, account=None, percent=True, amount=None, instance=None):
113 """TaxTableEntry constructor 115 You must provide an account, or be initizing this with an existing 116 swig proxy object via the instance keyword argument. 118 You may also optionally set the percent keyword argument to False to get 119 a fixed value instead of percentage based tax (which is the default, or 122 The tax will be zero percent or zero unless you set the amount keyword 123 argument to a GncNumeric value as well. 129 "you must call TaxTableEntry.__init__ with either a " 130 "account or an existing " 131 "low level swig proxy in the argument instance")
132 GnuCashCoreClass.__init__(self)
133 self.SetAccount(account)
135 self.SetType(GNC_AMT_TYPE_PERCENT)
137 self.SetType(GNC_AMT_TYPE_VALUE)
139 self.SetAmount(amount)
141 GnuCashCoreClass.__init__(self, instance=instance)
144 def __init__(self, book=None, id=None, currency=None, owner=None,
145 date_opened=None, instance=None):
146 """Invoice Constructor 148 You must provide a book, id, currency and owner 149 (Customer, Job, Employee, Vendor) or an existing swig proxy object 150 in the keyword argument instance. 152 Optionally, you may provide a date the invoice is opened on 153 (datetime.date or datetime.datetime), otherwise today's date is used. 156 if book==
None or id==
None or currency==
None or owner==
None:
158 "you must call Invoice.__init__ " 159 "with either a book, id, currency and owner, or an existing" 160 "low level swig proxy in the argument instance")
161 GnuCashCoreClass.__init__(self, book)
164 self.SetCurrency(currency)
166 if date_opened ==
None:
167 date_opened = datetime.date.today()
168 self.SetDateOpened(date_opened)
171 GnuCashCoreClass.__init__(self, instance=instance)
176 def decorate_to_return_instance_instead_of_owner(dec_function):
177 def new_get_owner_function(self):
178 (owner_type, instance) = dec_function(self)
179 if owner_type == GNC_OWNER_CUSTOMER:
180 return Customer(instance=instance)
181 elif owner_type == GNC_OWNER_JOB:
182 return Job(instance=instance)
183 elif owner_type == GNC_OWNER_EMPLOYEE:
184 return Employee(instance=instance)
185 elif owner_type == GNC_OWNER_VENDOR:
186 return Vendor(instance=instance)
189 return new_get_owner_function
192 def __init__(self, book=None, invoice=None, date=None, instance=None):
193 """Invoice Entry constructor 195 You must provide a book or be initizing this with an existing 196 swig proxy object via the instance keyword argument. 198 The optional invoice argument can be set to a Bill or Invoice 199 that you would like to associate the entry with. You might as well 200 assign one now, as an Entry can't exist without one, but you can 201 always use Invoice.AddEntry or Bill.AddEntry later on. 203 By default, the entry will be set to today's date unless you 204 override with the date argument. 209 "you must call Entry.__init__ with either a " 210 "book or an existing " 211 "low level swig proxy in the argument instance")
212 GnuCashCoreClass.__init__(self, book)
215 date = datetime.date.today()
218 invoice.AddEntry(self)
220 GnuCashCoreClass.__init__(self, instance=instance)
222 def test_type(self, invoice):
223 if invoice.GetTypeString() ==
"Invoice" and self.GetInvoice() ==
None:
224 raise Exception(
"Entry type error. Check that Entry type matches Invoice.")
225 if invoice.GetTypeString() ==
"Bill" and self.GetBill() ==
None:
226 raise Exception(
"Entry type error. Check that Entry type matches Bill.")
229 GnuCashBusinessEntity.add_methods_with_prefix(
'gncOwner')
233 'GetCustomer' : Customer,
234 'GetVendor' : Vendor,
235 'GetEmployee' : Employee,
238 'GetCurrency' : GncCommodity,
239 'GetEndOwner': GnuCashBusinessEntity,
240 'GetBalanceInCurrency': GncNumeric,
242 methods_return_instance(GnuCashBusinessEntity, owner_dict)
244 methods_return_instance_lists(
245 GnuCashBusinessEntity, {
246 'GetCommoditiesList': GncCommodity
250 Customer.add_constructor_and_methods_with_prefix(
'gncCustomer',
'Create')
251 Customer.add_method(
'gncOwnerApplyPaymentSecs',
'ApplyPayment')
255 'GetShipAddr' : Address,
256 'GetDiscount' : GncNumeric,
257 'GetCredit' : GncNumeric,
258 'GetTerms' : BillTerm,
259 'GetCurrency' : GncCommodity,
260 'GetTaxTable': TaxTable,
262 methods_return_instance(Customer, customer_dict)
265 Employee.add_constructor_and_methods_with_prefix(
'gncEmployee',
'Create')
270 'GetWorkday' : GncNumeric,
271 'GetRate' : GncNumeric,
272 'GetCurrency' : GncCommodity
274 methods_return_instance(Employee, employee_dict)
277 Vendor.add_constructor_and_methods_with_prefix(
'gncVendor',
'Create')
281 'GetTerms' : BillTerm,
282 'GetCurrency' : GncCommodity,
283 'GetTaxTable': TaxTable,
285 methods_return_instance(Vendor, vendor_dict)
288 Job.add_constructor_and_methods_with_prefix(
'gncJob',
'Create')
289 Job.decorate_functions(
290 decorate_to_return_instance_instead_of_owner,
294 Address.add_constructor_and_methods_with_prefix(
'gncAddress',
'Create')
297 BillTerm.add_constructor_and_methods_with_prefix(
'gncBillTerm',
'Create')
300 'LookupByName' : BillTerm,
301 'GetDiscount' : GncNumeric,
302 'GetParent' : BillTerm,
303 'ReturnChild' : BillTerm
305 methods_return_instance(BillTerm, billterm_dict)
308 TaxTable.add_constructor_and_methods_with_prefix(
'gncTaxTable',
'Create')
311 'GetParent': TaxTable,
313 methods_return_instance(TaxTable, taxtable_dict)
316 TaxTableEntry.add_constructor_and_methods_with_prefix(
317 'gncTaxTableEntry',
'Create')
319 taxtableentry_dict = {
320 'GetAccount': Account,
321 'GetAmount': GncNumeric,
325 Invoice.add_constructor_and_methods_with_prefix(
'gncInvoice',
'Create')
326 methods_return_instance_lists(
327 Invoice, {
'GetEntries': Entry })
329 Invoice.add_method(
'gncInvoiceRemoveEntry',
'RemoveEntry')
330 Invoice.add_method(
'gncInvoiceUnpost',
'Unpost')
333 Bill.add_methods_with_prefix(
'gncBill')
336 'GetTerms': BillTerm,
337 'GetCurrency': GncCommodity,
338 'GetToChargeAmount': GncNumeric,
339 'GetPostedLot': GncLot,
340 'GetPostedTxn': Transaction,
341 'GetPostedAcc': Account,
342 'GetTotal': GncNumeric,
343 'GetTotalOf': GncNumeric,
344 'GetTotalSubtotal': GncNumeric,
345 'GetTotalTax': GncNumeric,
346 'PostToAccount': Transaction,
349 methods_return_instance(Invoice, invoice_dict)
350 Invoice.decorate_functions(
351 decorate_to_return_instance_instead_of_owner,
352 'GetOwner',
'GetBillTo')
355 Entry.add_constructor_and_methods_with_prefix(
'gncEntry',
'Create')
357 Entry.add_method(
'gncEntryGetGUID',
'GetGUID')
358 Entry.add_method(
'gncEntryDestroy',
'Destroy')
362 'GetQuantity': GncNumeric,
363 'GetInvAccount': Account,
364 'GetInvPrice': GncNumeric,
365 'GetInvDiscount': GncNumeric,
366 'GetInvTaxTable': TaxTable,
367 'GetBillAccount': Account,
368 'GetBillPrice': GncNumeric,
369 'GetBillTaxTable': TaxTable,
371 'GetInvoice': Invoice,
374 methods_return_instance(Entry, entry_dict)
375 Entry.decorate_functions(
376 decorate_to_return_instance_instead_of_owner,
380 Entry.decorate_functions(decorate_monetary_list_returning_function,
'GetBalTaxValues')
def __init__(self, book=None, id=None, currency=None, owner=None, date_opened=None, instance=None)
def __init__(self, account=None, percent=True, amount=None, instance=None)
def __init__(self, book=None, invoice=None, date=None, instance=None)