Add str methods to financial objects so that.
More...
Go to the source code of this file.
|
|
def | str_methods.setflag (self, name, value) |
| |
|
def | str_methods.getflag (self, name) |
| |
| def | str_methods.register_optionflag (self, name) |
| |
| def | str_methods.ya_add_method (_class, function, method_name=None, clsmethod=False, noinstance=False) |
| |
|
def | str_methods.infect (_class, function, method_name) |
| |
| def | str_methods.all_as_classwithcutting__format__ (args) |
| |
| def | str_methods.all_as_classwithcutting__format__keys (encoding=None, error=None, keys) |
| |
| def | str_methods.__split__str__ (self, encoding=None, error=None) |
| |
| def | str_methods.__transaction__str__ (self) |
| |
| def | str_methods.__invoice__str__ (self) |
| |
| def | str_methods.__entry__str__ (self) |
| |
|
|
string | str_methods.DEFAULT_ENCODING = "UTF-8" |
| |
|
string | str_methods.DEFAULT_ERROR = "ignore" |
| |
Add str methods to financial objects so that.
leads to human readable results
Definition in file str_methods.py.
◆ __entry__str__()
| def str_methods.__entry__str__ |
( |
|
self | ) |
|
__str__ method for Entry
Definition at line 324 of file str_methods.py.
324 def __entry__str__(self):
325 """__str__ method for Entry""" 327 from gnucash.gnucash_business
import Entry
328 self=Entry(instance=self)
333 "date_value":str(self.GetDate()),
334 "description_name":
"Description:",
335 "description_value":self.GetDescription(),
336 "notes_name":
"Notes:",
337 "notes_value":self.GetNotes(),
338 "quant_name":
"Quantity:",
339 "quant_value":str(self.GetQuantity()),
340 "invprice_name":
"InvPrice:",
341 "invprice_value":str(self.GetInvPrice())}
343 return (
"{date_name:6}{date_value:15} {description_name:13}{description_value:20} {notes_name:7}{notes_value:20}"+
344 "{quant_name:12}{quant_value:7} {invprice_name:10}{invprice_value:7}").\
345 format(**all_as_classwithcutting__format__keys(**fmt_dict))
◆ __invoice__str__()
| def str_methods.__invoice__str__ |
( |
|
self | ) |
|
__str__ method for Invoice
Definition at line 284 of file str_methods.py.
284 def __invoice__str__(self):
285 """__str__ method for Invoice""" 287 from gnucash.gnucash_business
import Invoice
288 self=Invoice(instance=self)
294 "id_value":self.GetID(),
295 "notes_name":
"Notes:",
296 "notes_value":self.GetNotes(),
297 "active_name":
"Active:",
298 "active_value":str(self.GetActive()),
299 "owner_name":
"Owner Name:",
300 "owner_value":self.GetOwner().GetName(),
301 "total_name":
"Total:",
302 "total_value":str(self.GetTotal()),
303 "currency_mnemonic":self.GetCurrency().get_mnemonic()}
305 ret_invoice= (
"{id_name:4}{id_value:10} {notes_name:7}{notes_value:20} {active_name:8}{active_value:7} {owner_name:12}{owner_value:20}"+
306 "{total_name:8}{total_value:10}{currency_mnemonic:3}").\
307 format(**all_as_classwithcutting__format__keys(**fmt_dict))
310 entry_list = self.GetEntries()
311 for entry
in entry_list:
312 if not(type(entry)==Entry):
313 entry=Entry(instance=entry)
314 ret_entries +=
" "+str(entry)+
"\n" 316 return ret_invoice+
"\n"+ret_entries
◆ __split__str__()
| def str_methods.__split__str__ |
( |
|
self, |
|
|
|
encoding = None, |
|
|
|
error = None |
|
) |
| |
__str__(self, encoding=None, error=None) -> object
Serialize the Split object and return as a new Unicode object.
Keyword arguments:
encoding -- defaults to str_methods.default_encoding
error -- defaults to str_methods.default_error
See help(unicode) for more details or http://docs.python.org/howto/unicode.html.
Definition at line 199 of file str_methods.py.
199 def __split__str__(self, encoding=None, error=None):
200 """__str__(self, encoding=None, error=None) -> object 202 Serialize the Split object and return as a new Unicode object. 205 encoding -- defaults to str_methods.default_encoding 206 error -- defaults to str_methods.default_error 207 See help(unicode) for more details or http://docs.python.org/howto/unicode.html. 211 from gnucash
import Split
217 lot_str=lot.get_title()
221 transaction=self.GetParent()
225 "account":self.GetAccount().name,
226 "value":self.GetValue(),
227 "memo":self.GetMemo(),
230 fmt_str= (
"Account: {account:20} "+
231 "Value: {value:>10} "+
234 if self.optionflags & self.OPTIONFLAGS_BY_NAME[
"PRINT_TRANSACTION"]:
236 "transaction_time":time.ctime(transaction.GetDate()),
237 "transaction2":transaction.GetDescription()}
239 "Transaction: {transaction_time:30} "+
240 "- {transaction2:30} "+
242 fmt_dict.update(fmt_t_dict)
245 return fmt_str.format(**all_as_classwithcutting__format__keys(encoding,error,**fmt_dict))
249 infect(gnucash.Split,__split__str__,
"__str__")
250 gnucash.Split.register_optionflag(
"PRINT_TRANSACTION")
251 gnucash.Split.setflag(
"PRINT_TRANSACTION",
True)
◆ __transaction__str__()
| def str_methods.__transaction__str__ |
( |
|
self | ) |
|
__str__ method for Transaction class
Definition at line 253 of file str_methods.py.
253 def __transaction__str__(self):
254 """__str__ method for Transaction class""" 255 from gnucash
import Transaction
257 self=Transaction(instance=self)
259 fmt_tuple=(
'Date:',time.ctime(self.GetDate()),
260 'Description:',self.GetDescription(),
261 'Notes:',self.GetNotes())
263 transaction_str =
"{0:6}{1:25} {2:14}{3:40} {4:7}{5:40}".format(
264 *all_as_classwithcutting__format__(*fmt_tuple))
265 transaction_str +=
"\n" 268 for n,split
in enumerate(self.GetSplitList()):
269 if not (type(split)==gnucash.Split):
270 split=gnucash.Split(instance=split)
272 transaction_flag = split.getflag(
"PRINT_TRANSACTION")
273 split.setflag(
"PRINT_TRANSACTION",
False)
274 splits_str +=
"[{0:>2}] ".format(str(n))
275 splits_str += str(split)
277 split.setflag(
"PRINT_TRANSACTION",transaction_flag)
279 return transaction_str + splits_str
281 gnucash.gnucash_core_c.__transaction__str__=__transaction__str__
282 gnucash.Transaction.add_method(
"__transaction__str__",
"__str__")
◆ all_as_classwithcutting__format__()
| def str_methods.all_as_classwithcutting__format__ |
( |
|
args | ) |
|
Converts every argument to instance of ClassWithCutting__format__
Definition at line 168 of file str_methods.py.
168 def all_as_classwithcutting__format__(*args):
169 """Converts every argument to instance of ClassWithCutting__format__""" 176 l.append(ClassWithCutting__format__(a))
◆ all_as_classwithcutting__format__keys()
| def str_methods.all_as_classwithcutting__format__keys |
( |
|
encoding = None, |
|
|
|
error = None, |
|
|
|
keys |
|
) |
| |
Converts every argument to instance of ClassWithCutting__format__
Definition at line 180 of file str_methods.py.
180 def all_as_classwithcutting__format__keys(encoding=None, error=None, **keys):
181 """Converts every argument to instance of ClassWithCutting__format__""" 186 encoding=DEFAULT_ENCODING
192 d[a]=ClassWithCutting__format__(keys[a])
◆ register_optionflag()
| def str_methods.register_optionflag |
( |
|
self, |
|
|
|
name |
|
) |
| |
Taken from doctest.py
Definition at line 53 of file str_methods.py.
53 def register_optionflag(self,name):
54 """Taken from doctest.py""" 56 return self.OPTIONFLAGS_BY_NAME.setdefault(name, 1 << len(self.OPTIONFLAGS_BY_NAME))
◆ ya_add_method()
| def str_methods.ya_add_method |
( |
|
_class, |
|
|
|
function, |
|
|
|
method_name = None, |
|
|
|
clsmethod = False, |
|
|
|
noinstance = False |
|
) |
| |
Calls add_method from function_methods.py but makes it
possible to use functions in this module. Also keeps the
docstring
Definition at line 58 of file str_methods.py.
58 def ya_add_method(_class, function, method_name=None, clsmethod=False, noinstance=False):
59 """Calls add_method from function_methods.py but makes it 60 possible to use functions in this module. Also keeps the 63 if method_name ==
None:
64 method_name = function.__name__
66 setattr(gnucash.gnucash_core_c,function.__name__,function)
68 mf=_class.ya_add_classmethod(function.__name__,method_name)
70 mf=_class.add_method(function.__name__,method_name)
72 mf=_class.ya_add_method(function.__name__,method_name)
73 if function.__doc__ !=
None:
74 setattr(mf,
"__doc__", function.__doc__)