/usr/lib/python2.7/dist-packages/gnucash/gnucash_business.py is in python-gnucash 1:2.6.12-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | # gnucash_business.py -- High level python wrapper classes for the business
# parts of GnuCash
#
# Copyright (C) 2008,2010 ParIT Worker Co-operative <paritinfo@parit.ca>
# 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, contact:
# Free Software Foundation Voice: +1-617-542-5942
# 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
# Boston, MA 02110-1301, USA gnu@gnu.org
#
# @author Mark Jenkins, ParIT Worker Co-operative <mark@parit.ca>
# @author Jeff Green, ParIT Worker Co-operative <jeff@parit.ca>
## @file
# @brief High level python wrapper classes for the business parts of GnuCash
# @author Mark Jenkins, ParIT Worker Co-operative <mark@parit.ca>
# @author Jeff Green, ParIT Worker Co-operative <jeff@parit.ca>
# @ingroup python_bindings
import gnucash_core_c
from function_class import \
ClassFromFunctions, extract_attributes_with_prefix, \
default_arguments_decorator, method_function_returns_instance, \
methods_return_instance, methods_return_instance_lists
from gnucash_core import \
GnuCashCoreClass, GncNumeric, GncCommodity, Transaction, \
Split, Book, GncLot, Account
from gnucash_core_c import GNC_OWNER_CUSTOMER, GNC_OWNER_JOB, \
GNC_OWNER_EMPLOYEE, GNC_OWNER_VENDOR, \
GNC_PAYMENT_CASH, GNC_PAYMENT_CARD, \
GNC_DISC_PRETAX, GNC_DISC_SAMETIME, GNC_DISC_POSTTAX, \
GNC_TAXINCLUDED_YES, GNC_TAXINCLUDED_NO, GNC_TAXINCLUDED_USEGLOBAL, \
GNC_AMT_TYPE_VALUE, GNC_AMT_TYPE_PERCENT, GNC_ID_INVOICE
import datetime
class GnuCashBusinessEntity(GnuCashCoreClass):
def __init__(self, book=None, id=None, currency=None, name=None,
instance=None):
if instance == None:
if book==None or id==None or currency==None:
raise Exception(
"you must call GnuCashBusinessEntity.__init__ "
"with either a book, id, and currency, or an existing "
"low level swig proxy in the argument instance")
GnuCashCoreClass.__init__(self, book)
self.BeginEdit()
self.SetID(id)
self.SetCurrency(currency)
if name != None:
self.SetName(name)
self.CommitEdit()
else:
GnuCashCoreClass.__init__(self, instance=instance)
class Customer(GnuCashBusinessEntity): pass
class Employee(GnuCashBusinessEntity): pass
class Vendor(GnuCashBusinessEntity): pass
class Job(GnuCashBusinessEntity):
# override the superclass contructor, as Job doesn't require
# a currency but it does require an owner
def __init__(self, book=None, id=None, owner=None, name=None,
instance=None):
if instance == None:
if book==None or id==None or owner==None:
raise Exception(
"you must call Job.__init__ "
"with either a book, id, and owner or an existing "
"low level swig proxy in the argument instance")
GnuCashCoreClass.__init__(self, book)
self.SetID(id)
self.SetOwner(owner)
if name != None:
self.SetName(name)
else:
GnuCashCoreClass.__init__(self, instance=instance)
class Address(GnuCashCoreClass): pass
class BillTerm(GnuCashCoreClass): pass
class TaxTable(GnuCashCoreClass):
def __init__(self, book=None, name=None, first_entry=None, instance=None):
if instance == None:
if book==None or name==None or first_entry==None:
raise Exception(
"you must call TaxTable.__init__ with either a "
"book, name, and first_entry, or an existing "
"low level swig proxy in the argument instance")
GnuCashCoreClass.__init__(self, book)
self.SetName(name)
self.AddEntry(first_entry)
else:
GnuCashCoreClass.__init__(self, instance=instance)
class TaxTableEntry(GnuCashCoreClass):
def __init__(self, account=None, percent=True, amount=None, instance=None):
"""TaxTableEntry constructor
You must provide an account, or be initizing this with an existing
swig proxy object via the instance keyword argument.
You may also optionally set the percent keyword argument to False to get
a fixed value instead of percentage based tax (which is the default, or
when percent=True).
The tax will be zero percent or zero unless you set the amount keyword
argument to a GncNumeric value as well.
"""
if instance == None:
if account==None:
raise Exception(
"you must call TaxTableEntry.__init__ with either a "
"account or an existing "
"low level swig proxy in the argument instance")
GnuCashCoreClass.__init__(self)
self.SetAccount(account)
if percent:
self.SetType(GNC_AMT_TYPE_PERCENT)
else:
self.SetType(GNC_AMT_TYPE_VALUE)
if amount != None:
self.SetAmount(amount)
else:
GnuCashCoreClass.__init__(self, instance=instance)
class Invoice(GnuCashCoreClass):
def __init__(self, book=None, id=None, currency=None, owner=None,
date_opened=None, instance=None):
"""Invoice Contstructor
You must provide a book, id, currency and owner
(Customer, Job, Employee, Vendor) or an existing swig proxy object
in the keyword argument instance.
Optionally, you may provide a date the invoice is opened on
(datetime.date or datetime.datetime), otherwise today's date is used.
"""
if instance == None:
if book==None or id==None or currency==None or owner==None:
raise Exception(
"you must call Invoice.__init__ "
"with either a book, id, currency and owner, or an existing"
"low level swig proxy in the argument instance")
GnuCashCoreClass.__init__(self, book)
self.BeginEdit()
self.SetID(id)
self.SetCurrency(currency)
self.SetOwner(owner)
if date_opened == None:
date_opened = datetime.date.today()
self.SetDateOpened(date_opened)
self.CommitEdit()
else:
GnuCashCoreClass.__init__(self, instance=instance)
class Bill(Invoice):
pass
def decorate_to_return_instance_instead_of_owner(dec_function):
def new_get_owner_function(self):
(owner_type, instance) = dec_function(self)
if owner_type == GNC_OWNER_CUSTOMER:
return Customer(instance=instance)
elif owner_type == GNC_OWNER_JOB:
return Job(instance=instance)
elif owner_type == GNC_OWNER_EMPLOYEE:
return Employee(instance=instance)
elif owner_type == GNC_OWNER_VENDOR:
return Vendor(instance=instance)
else:
return None
return new_get_owner_function
class Entry(GnuCashCoreClass):
def __init__(self, book=None, invoice=None, date=None, instance=None):
"""Invoice Entry constructor
You must provide a book or be initizing this with an existing
swig proxy object via the instance keyword argument.
The optional invoice argument can be set to a Bill or Invoice
that you would like to associate the entry with. You might as well
assign one now, as an Entry can't exist without one, but you can
always use Invoice.AddEntry or Bill.AddEntry later on.
By default, the entry will be set to today's date unless you
override with the date argument.
"""
if instance == None:
if book==None:
raise Exception(
"you must call Entry.__init__ with either a "
"book or an existing "
"low level swig proxy in the argument instance")
GnuCashCoreClass.__init__(self, book)
if date == None:
date = datetime.date.today()
self.SetDate(date)
if invoice != None:
invoice.AddEntry(self)
else:
GnuCashCoreClass.__init__(self, instance=instance)
def test_type(self, invoice):
if invoice.GetTypeString() == "Invoice" and self.GetInvoice() == None:
raise Exception("Entry type error. Check that Entry type matches Invoice.")
if invoice.GetTypeString() == "Bill" and self.GetBill() == None:
raise Exception("Entry type error. Check that Entry type matches Bill.")
# Owner
GnuCashBusinessEntity.add_methods_with_prefix('gncOwner')
owner_dict = {
'GetCustomer' : Customer,
'GetVendor' : Vendor,
'GetEmployee' : Employee,
'GetJob' : Job,
'GetAddr' : Address,
'GetCurrency' : GncCommodity,
'GetEndOwner': GnuCashBusinessEntity,
'GetBalanceInCurrency': GncNumeric,
}
methods_return_instance(GnuCashBusinessEntity, owner_dict)
methods_return_instance_lists(
GnuCashBusinessEntity, {
'GetCommoditiesList': GncCommodity
})
# Customer
Customer.add_constructor_and_methods_with_prefix('gncCustomer', 'Create')
customer_dict = {
'GetAddr' : Address,
'GetShipAddr' : Address,
'GetDiscount' : GncNumeric,
'GetCredit' : GncNumeric,
'GetTerms' : BillTerm,
'GetCurrency' : GncCommodity,
'GetTaxTable': TaxTable,
}
methods_return_instance(Customer, customer_dict)
# Employee
Employee.add_constructor_and_methods_with_prefix('gncEmployee', 'Create')
employee_dict = {
'GetBook' : Book,
'GetAddr' : Address,
'GetWorkday' : GncNumeric,
'GetRate' : GncNumeric,
'GetCurrency' : GncCommodity
}
methods_return_instance(Employee, employee_dict)
# Vendor
Vendor.add_constructor_and_methods_with_prefix('gncVendor', 'Create')
vendor_dict = {
'GetAddr' : Address,
'GetTerms' : BillTerm,
'GetCurrency' : GncCommodity,
'GetTaxTable': TaxTable,
}
methods_return_instance(Vendor, vendor_dict)
# Job
Job.add_constructor_and_methods_with_prefix('gncJob', 'Create')
Job.decorate_functions(
decorate_to_return_instance_instead_of_owner,
'GetOwner')
# Address
Address.add_constructor_and_methods_with_prefix('gncAddress', 'Create')
# BillTerm
BillTerm.add_constructor_and_methods_with_prefix('gncBillTerm', 'Create')
billterm_dict = {
'LookupByName' : BillTerm,
'GetDiscount' : GncNumeric,
'GetParent' : BillTerm,
'ReturnChild' : BillTerm
}
methods_return_instance(BillTerm, billterm_dict)
# TaxTable
TaxTable.add_constructor_and_methods_with_prefix('gncTaxTable', 'Create')
taxtable_dict = {
'GetParent': TaxTable,
}
methods_return_instance(TaxTable, taxtable_dict)
# TaxTableEntry
TaxTableEntry.add_constructor_and_methods_with_prefix(
'gncTaxTableEntry', 'Create')
taxtableentry_dict = {
'GetAccount': Account,
'GetAmount': GncNumeric,
}
# Invoice
Invoice.add_constructor_and_methods_with_prefix('gncInvoice', 'Create')
methods_return_instance_lists(
Invoice, { 'GetEntries': Entry })
# Bill
Bill.add_methods_with_prefix('gncBill')
invoice_dict = {
'GetTerms': BillTerm,
'GetCurrency': GncCommodity,
'GetToChargeAmount': GncNumeric,
'GetPostedLot': GncLot,
'GetPostedTxn': Transaction,
'GetPostedAcc': Account,
'GetTotal': GncNumeric,
'GetTotalOf': GncNumeric,
'GetTotalSubtotal': GncNumeric,
'GetTotalTax': GncNumeric,
'PostToAccount': Transaction,
'GetBook': Book,
}
methods_return_instance(Invoice, invoice_dict)
Invoice.decorate_functions(
decorate_to_return_instance_instead_of_owner,
'GetOwner', 'GetBillTo')
# Entry
Entry.add_constructor_and_methods_with_prefix('gncEntry', 'Create')
entry_dict = {
'GetQuantity': GncNumeric,
'GetInvAccount': Account,
'GetInvPrice': GncNumeric,
'GetInvDiscount': GncNumeric,
'GetInvTaxTable': TaxTable,
'GetBillAccount': Account,
'GetBillPrice': GncNumeric,
'GetBillTaxTable': TaxTable,
'Copy': Entry,
'GetInvoice': Invoice,
'GetBill': Invoice
}
methods_return_instance(Entry, entry_dict)
Entry.decorate_functions(
decorate_to_return_instance_instead_of_owner,
'GetBillTo' )
|