gnucash maint: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Sun Apr 14 17:29:05 EDT 2019
Updated via https://github.com/Gnucash/gnucash/commit/fc355958 (commit)
via https://github.com/Gnucash/gnucash/commit/b2f25408 (commit)
via https://github.com/Gnucash/gnucash/commit/8823f728 (commit)
via https://github.com/Gnucash/gnucash/commit/f772b505 (commit)
via https://github.com/Gnucash/gnucash/commit/0c028669 (commit)
via https://github.com/Gnucash/gnucash/commit/18a26884 (commit)
via https://github.com/Gnucash/gnucash/commit/db9e98a8 (commit)
via https://github.com/Gnucash/gnucash/commit/3884e6ab (commit)
via https://github.com/Gnucash/gnucash/commit/8ba5e552 (commit)
via https://github.com/Gnucash/gnucash/commit/dafdd702 (commit)
via https://github.com/Gnucash/gnucash/commit/79decfb7 (commit)
via https://github.com/Gnucash/gnucash/commit/445ff7e6 (commit)
via https://github.com/Gnucash/gnucash/commit/c779bcb7 (commit)
via https://github.com/Gnucash/gnucash/commit/6925ee31 (commit)
via https://github.com/Gnucash/gnucash/commit/876079f8 (commit)
via https://github.com/Gnucash/gnucash/commit/6eae4405 (commit)
via https://github.com/Gnucash/gnucash/commit/b73be1b5 (commit)
via https://github.com/Gnucash/gnucash/commit/b0680118 (commit)
via https://github.com/Gnucash/gnucash/commit/e7d940ac (commit)
via https://github.com/Gnucash/gnucash/commit/77727ffc (commit)
via https://github.com/Gnucash/gnucash/commit/64a01f30 (commit)
via https://github.com/Gnucash/gnucash/commit/0068475b (commit)
via https://github.com/Gnucash/gnucash/commit/298797a9 (commit)
via https://github.com/Gnucash/gnucash/commit/206ed632 (commit)
via https://github.com/Gnucash/gnucash/commit/247d04a5 (commit)
via https://github.com/Gnucash/gnucash/commit/1184e926 (commit)
via https://github.com/Gnucash/gnucash/commit/002595f4 (commit)
via https://github.com/Gnucash/gnucash/commit/61f7613b (commit)
from https://github.com/Gnucash/gnucash/commit/0f6465ca (commit)
commit fc355958b8201e6cd63909654e1ddda4d59befff
Merge: b2f25408d c779bcb72
Author: John Ralls <jralls at ceridwen.us>
Date: Sun Apr 14 14:27:53 2019 -0700
Merge Christoph Holtermann's 'PR-python2to3-rest-api' into maint.
commit b2f25408d7464f35747ab34ea7bfe4fabb9ac1a9
Merge: 8823f7283 0c0286696
Author: John Ralls <jralls at ceridwen.us>
Date: Sun Apr 14 14:26:35 2019 -0700
Merge Christoff Holtermann's 'PR-python-time64-modifications' into maint
commit 8823f7283f78181533988e14f185662012e68853
Merge: f772b5054 b06801185
Author: John Ralls <jralls at ceridwen.us>
Date: Sun Apr 14 14:24:16 2019 -0700
Merge Christoph Holtermann's 'PR-python2to3' into maint.
commit f772b505429f7c416dd534f38906692379c30aff
Merge: 0f6465ca6 298797a9b
Author: John Ralls <jralls at ceridwen.us>
Date: Sun Apr 14 14:23:37 2019 -0700
Merge Christoph Holterman's 'PR-python2to3-str_methods-gnc_jinja' into maint
commit 0c028669642ae4a5937bbb2f3c4344280eec283c
Author: c-holtermann <mail at c-holtermann.net>
Date: Sat Apr 6 17:13:41 2019 +0200
PyDate_Check works for date and datetime
diff --git a/bindings/python/time64.i b/bindings/python/time64.i
index 1840b87c6..295a99a79 100644
--- a/bindings/python/time64.i
+++ b/bindings/python/time64.i
@@ -35,12 +35,12 @@
%typemap(in) time64 {
PyDateTime_IMPORT;
- if (!PyDate_Check($input) && !PyDateTime_Check($input) && !PyInt_Check($input)) {
+ if (!PyDate_Check($input) && !PyInt_Check($input)) {
PyErr_SetString(PyExc_ValueError,"date, datetime or integer expected");
return NULL;
}
- if (PyDateTime_Check($input)) {
+ if (PyDate_Check($input)) {
struct tm time = {PyDateTime_DATE_GET_SECOND($input),
PyDateTime_DATE_GET_MINUTE($input),
PyDateTime_DATE_GET_HOUR($input),
@@ -79,12 +79,12 @@
%typemap(in) time64 * (time64 secs) {
PyDateTime_IMPORT;
- if (!PyDate_Check($input) && !PyDateTime_Check($input) && !PyInt_Check($input)) {
+ if (!PyDate_Check($input) && !PyInt_Check($input)) {
PyErr_SetString(PyExc_ValueError,"date, datetime or integer expected");
return NULL;
}
- if (PyDateTime_Check($input)) {
+ if (PyDate_Check($input)) {
struct tm time = {PyDateTime_DATE_GET_SECOND($input),
PyDateTime_DATE_GET_MINUTE($input),
PyDateTime_DATE_GET_HOUR($input),
commit 18a26884197cc72551a58c77c88f7355bebe01eb
Author: c-holtermann <mail at c-holtermann.net>
Date: Sat Apr 6 16:17:58 2019 +0200
typo
diff --git a/bindings/python/gnucash_business.py b/bindings/python/gnucash_business.py
index 53b8e1b34..b4583377d 100644
--- a/bindings/python/gnucash_business.py
+++ b/bindings/python/gnucash_business.py
@@ -143,7 +143,7 @@ class TaxTableEntry(GnuCashCoreClass):
class Invoice(GnuCashCoreClass):
def __init__(self, book=None, id=None, currency=None, owner=None,
date_opened=None, instance=None):
- """Invoice Contstructor
+ """Invoice Constructor
You must provide a book, id, currency and owner
(Customer, Job, Employee, Vendor) or an existing swig proxy object
commit db9e98a812daf6d293f29c6ed07a50dd28b8f70e
Author: c-holtermann <mail at c-holtermann.net>
Date: Sat Apr 6 16:10:04 2019 +0200
also allow datetime.date
Initialisation of some business objects has been done with
datetime.date.today() and it is also mentioned as a possibility
in the source doc. So leave it possible.
diff --git a/bindings/python/time64.i b/bindings/python/time64.i
index dfedfa635..1840b87c6 100644
--- a/bindings/python/time64.i
+++ b/bindings/python/time64.i
@@ -35,8 +35,8 @@
%typemap(in) time64 {
PyDateTime_IMPORT;
- if (!PyDateTime_Check($input) && !PyInt_Check($input)) {
- PyErr_SetString(PyExc_ValueError,"datetime or integer expected");
+ if (!PyDate_Check($input) && !PyDateTime_Check($input) && !PyInt_Check($input)) {
+ PyErr_SetString(PyExc_ValueError,"date, datetime or integer expected");
return NULL;
}
@@ -79,8 +79,8 @@
%typemap(in) time64 * (time64 secs) {
PyDateTime_IMPORT;
- if (!PyDateTime_Check($input) && !PyInt_Check($input)) {
- PyErr_SetString(PyExc_ValueError,"datetime or integer expected");
+ if (!PyDate_Check($input) && !PyDateTime_Check($input) && !PyInt_Check($input)) {
+ PyErr_SetString(PyExc_ValueError,"date, datetime or integer expected");
return NULL;
}
commit 3884e6abf549ad5c6c8d09604a493d3f9ff88371
Author: c-holtermann <mail at c-holtermann.net>
Date: Sat Apr 6 16:09:01 2019 +0200
unobfuscate get_date method name
diff --git a/bindings/python/gnucash_core.py b/bindings/python/gnucash_core.py
index b268503eb..38415abe8 100644
--- a/bindings/python/gnucash_core.py
+++ b/bindings/python/gnucash_core.py
@@ -812,7 +812,8 @@ class QueryDatePredicate(GnuCashCoreClass):
pass
QueryDatePredicate.add_constructor_and_methods_with_prefix(
- 'qof_query_', 'date_predicate')
+ 'qof_query_', 'date_predicate', exclude=["qof_query_date_predicate_get_date"])
+QueryDatePredicate.add_method('qof_query_date_predicate_get_date', 'get_date')
class QueryGuidPredicate(GnuCashCoreClass):
pass
commit 8ba5e552d92a9c745ba1295d76b3bcfd3408a485
Author: c-holtermann <mail at c-holtermann.net>
Date: Sat Apr 6 14:50:29 2019 +0200
return None object if return value is FALSE
diff --git a/bindings/python/time64.i b/bindings/python/time64.i
index 88d345347..dfedfa635 100644
--- a/bindings/python/time64.i
+++ b/bindings/python/time64.i
@@ -136,12 +136,17 @@
PyDateTime_IMPORT;
PyObject *tp;
struct tm t;
- gnc_localtime_r($1, &t);
- tp = PyDateTime_FromDateAndTime(t.tm_year + 1900, t.tm_mon + 1,
- t.tm_mday, t.tm_hour, t.tm_min,
- t.tm_sec, 0);
- $result = SWIG_Python_AppendOutput($result, tp);
+ // directly access return value (result) of function
+ // only return datetime if TRUE
+ if(result) {
+ gnc_localtime_r($1, &t);
+ tp = PyDateTime_FromDateAndTime(t.tm_year + 1900, t.tm_mon + 1,
+ t.tm_mday, t.tm_hour, t.tm_min,
+ t.tm_sec, 0);
+
+ $result = SWIG_Python_AppendOutput($result, tp);
+ } else $result = SWIG_Python_AppendOutput($result, Py_None);
}
%apply time64 *date { time64 *last_date };
commit dafdd702e6bfffee5fe75f973f8a67320586c7ff
Author: c-holtermann <mail at c-holtermann.net>
Date: Sat Apr 6 14:09:10 2019 +0200
additional author
diff --git a/bindings/python/time64.i b/bindings/python/time64.i
index 41e552cb4..88d345347 100644
--- a/bindings/python/time64.i
+++ b/bindings/python/time64.i
@@ -27,6 +27,7 @@
@brief SWIG interface file for type translation of time64 types
@author Mark Jenkins, ParIT Worker Co-operative <mark at parit.ca>
@author Jeff Green, ParIT Worker Co-operative <jeff at parit.ca>
+ @author Christoph Holtermann, mail at c-holtermann.net - modifications 2019-04
@ingroup python_bindings */
// A typemap for converting python dates to time64 in functions that
commit 79decfb754fb7ff7624357e98cbbe59a66e2ee7c
Author: c-holtermann <mail at c-holtermann.net>
Date: Sat Apr 6 14:08:52 2019 +0200
deal with functions returning values through arguments
diff --git a/bindings/python/time64.i b/bindings/python/time64.i
index e7553b504..41e552cb4 100644
--- a/bindings/python/time64.i
+++ b/bindings/python/time64.i
@@ -69,6 +69,12 @@
// stack. (SWIG will name the variables ts1, ts2, ts3...)
//
// Mark Jenkins <mark at parit.ca>
+//
+// as far as I can see all occurences of pointers to time64 are now covered
+// by the named typemaps below (2019-04)
+//
+// Christoph Holtermann <mail at c-holtermann.net>
+
%typemap(in) time64 * (time64 secs) {
PyDateTime_IMPORT;
@@ -92,8 +98,9 @@
}
}
-// A typemap for converting time64 values returned from functions to
-// python dates. Note that we can't use Python DateTime's fromtimestamp function because it relies upon libc's localtime. Note also that while we create times with timegm we retrieve it with localtime
+/* A typemap for converting time64 values returned from functions to
+ python dates. Note that we can't use Python DateTime's fromtimestamp function because it relies upon libc's
+ localtime. Note also that while we create times with timegm we retrieve it with localtime */
%typemap(out) time64 {
if ($1 == INT64_MAX) {
$result = Py_None;
@@ -106,3 +113,35 @@
t.tm_sec, 0);
}
}
+
+// functions using a pointer to time64 to return data
+// these are named typemaps focussing for
+//
+// gboolean qof_query_date_predicate_get_date (const QofQueryPredData *pd, time64 *date)
+// gboolean xaccAccountGetReconcileLastDate (const Account *acc, time64 *last_date)
+// gboolean xaccAccountGetReconcilePostponeDate (const Account *acc, time64 *postpone_date)
+//
+// python functions return a list where the first item is the boolean return value and
+// the second item is a datetime object. This could be reduced to only returning a date or
+// null
+//
+// the modifiable argument is omitted in python function call
+
+%typemap(in, numinputs=0) time64 *date (time64 secs) {
+ $1 = &secs;
+}
+
+%typemap(argout) time64 *date (time64 secs) {
+ PyDateTime_IMPORT;
+ PyObject *tp;
+ struct tm t;
+ gnc_localtime_r($1, &t);
+ tp = PyDateTime_FromDateAndTime(t.tm_year + 1900, t.tm_mon + 1,
+ t.tm_mday, t.tm_hour, t.tm_min,
+ t.tm_sec, 0);
+
+ $result = SWIG_Python_AppendOutput($result, tp);
+}
+
+%apply time64 *date { time64 *last_date };
+%apply time64 *date { time64 *postpone_date };
commit 445ff7e6c98b9203780b434fa2dbc4dda1340e3c
Author: c-holtermann <mail at c-holtermann.net>
Date: Sat Apr 6 07:51:15 2019 +0200
check for argument type. Also allow int.
diff --git a/bindings/python/time64.i b/bindings/python/time64.i
index 82736186e..e7553b504 100644
--- a/bindings/python/time64.i
+++ b/bindings/python/time64.i
@@ -33,13 +33,23 @@
// require time64 as an argument
%typemap(in) time64 {
PyDateTime_IMPORT;
- struct tm time = {PyDateTime_DATE_GET_SECOND($input),
- PyDateTime_DATE_GET_MINUTE($input),
- PyDateTime_DATE_GET_HOUR($input),
- PyDateTime_GET_DAY($input),
- PyDateTime_GET_MONTH($input) - 1,
- PyDateTime_GET_YEAR($input) - 1900};
- $1 = gnc_mktime(&time);
+
+ if (!PyDateTime_Check($input) && !PyInt_Check($input)) {
+ PyErr_SetString(PyExc_ValueError,"datetime or integer expected");
+ return NULL;
+ }
+
+ if (PyDateTime_Check($input)) {
+ struct tm time = {PyDateTime_DATE_GET_SECOND($input),
+ PyDateTime_DATE_GET_MINUTE($input),
+ PyDateTime_DATE_GET_HOUR($input),
+ PyDateTime_GET_DAY($input),
+ PyDateTime_GET_MONTH($input) - 1,
+ PyDateTime_GET_YEAR($input) - 1900};
+ $1 = gnc_mktime(&time);
+ } else {
+ $1 = PyInt_AsLong($input);
+ }
}
// A typemap for converting python dates to time64 *, for functions that
@@ -61,14 +71,25 @@
// Mark Jenkins <mark at parit.ca>
%typemap(in) time64 * (time64 secs) {
PyDateTime_IMPORT;
- struct tm time = {PyDateTime_DATE_GET_SECOND($input),
- PyDateTime_DATE_GET_MINUTE($input),
- PyDateTime_DATE_GET_HOUR($input),
- PyDateTime_GET_DAY($input),
- PyDateTime_GET_MONTH($input) - 1,
- PyDateTime_GET_YEAR($input) - 1900};
- time64 secs = gnc_mktime(&time);
- $1 = &secs;
+
+ if (!PyDateTime_Check($input) && !PyInt_Check($input)) {
+ PyErr_SetString(PyExc_ValueError,"datetime or integer expected");
+ return NULL;
+ }
+
+ if (PyDateTime_Check($input)) {
+ struct tm time = {PyDateTime_DATE_GET_SECOND($input),
+ PyDateTime_DATE_GET_MINUTE($input),
+ PyDateTime_DATE_GET_HOUR($input),
+ PyDateTime_GET_DAY($input),
+ PyDateTime_GET_MONTH($input) - 1,
+ PyDateTime_GET_YEAR($input) - 1900};
+ time64 secs = gnc_mktime(&time);
+ $1 = &secs;
+ } else {
+ time64 secs = PyInt_AsLong($input);
+ $1 = &secs;
+ }
}
// A typemap for converting time64 values returned from functions to
commit c779bcb72fc6221d206d627dd05a9196db3aa444
Author: c-holtermann <mail at c-holtermann.net>
Date: Thu Apr 4 17:43:19 2019 +0200
GetOwner may return project instead of owner
diff --git a/bindings/python/example_scripts/rest-api/gnucash_simple.py b/bindings/python/example_scripts/rest-api/gnucash_simple.py
index ad132c871..1bc56de02 100644
--- a/bindings/python/example_scripts/rest-api/gnucash_simple.py
+++ b/bindings/python/example_scripts/rest-api/gnucash_simple.py
@@ -171,7 +171,10 @@ def invoiceToDict(invoice):
simple_invoice['notes'] = invoice.GetNotes()
simple_invoice['active'] = invoice.GetActive()
simple_invoice['currency'] = invoice.GetCurrency().get_mnemonic()
- simple_invoice['owner'] = vendorToDict(invoice.GetOwner())
+ owner = invoice.GetOwner()
+ if type(owner) == gnucash.gnucash_business.Job:
+ owner = owner.GetOwner()
+ simple_invoice['owner'] = vendorToDict(owner)
simple_invoice['owner_type'] = invoice.GetOwnerType()
simple_invoice['billing_id'] = invoice.GetBillingID()
simple_invoice['to_charge_amount'] = invoice.GetToChargeAmount().to_double()
commit 6925ee3115b329b1d93639c2275e89fbe788f26d
Author: c-holtermann <mail at c-holtermann.net>
Date: Thu Apr 4 17:42:46 2019 +0200
be prepared for GetDateDue returning null
diff --git a/bindings/python/example_scripts/rest-api/gnucash_simple.py b/bindings/python/example_scripts/rest-api/gnucash_simple.py
index 8f93a7af9..ad132c871 100644
--- a/bindings/python/example_scripts/rest-api/gnucash_simple.py
+++ b/bindings/python/example_scripts/rest-api/gnucash_simple.py
@@ -163,7 +163,7 @@ def invoiceToDict(invoice):
else:
simple_invoice['date_posted'] = invoice.GetDatePosted().strftime(
'%Y-%m-%d')
- if invoice.GetDateDue().strftime('%Y-%m-%d') == '1970-01-01':
+ if not invoice.GetDateDue() or invoice.GetDateDue().strftime('%Y-%m-%d') == '1970-01-01':
simple_invoice['date_due'] = None
else:
simple_invoice['date_due'] = invoice.GetDateDue().strftime(
commit 876079f8d2404b81c14314f524fe3e311337c91d
Author: c-holtermann <mail at c-holtermann.net>
Date: Thu Apr 4 17:42:02 2019 +0200
remove TS suffix
diff --git a/bindings/python/example_scripts/rest-api/gnucash_simple.py b/bindings/python/example_scripts/rest-api/gnucash_simple.py
index 259e244b9..8f93a7af9 100644
--- a/bindings/python/example_scripts/rest-api/gnucash_simple.py
+++ b/bindings/python/example_scripts/rest-api/gnucash_simple.py
@@ -111,12 +111,12 @@ def transactionToDict(transaction, entities):
simple_transaction['imbalance_value'] = transaction.GetImbalanceValue(
).to_double()
simple_transaction['is_balanced'] = transaction.IsBalanced()
- simple_transaction['date_posted'] = transaction.RetDatePostedTS(
simple_transaction['date'] = transaction.GetDate().strftime('%Y-%m-%d')
+ simple_transaction['date_posted'] = transaction.RetDatePosted(
).strftime('%Y-%m-%d')
- simple_transaction['date_entered'] = transaction.RetDateEnteredTS(
+ simple_transaction['date_entered'] = transaction.RetDateEntered(
).strftime('%Y-%m-%d')
- simple_transaction['date_due'] = transaction.RetDateDueTS().strftime(
+ simple_transaction['date_due'] = transaction.RetDateDue().strftime(
'%Y-%m-%d')
simple_transaction['void_status'] = transaction.GetVoidStatus()
simple_transaction['void_time'] = transaction.GetVoidTime().strftime(
commit 6eae440534f85064c7376fb32aa76b90e38f6d4d
Author: c-holtermann <mail at c-holtermann.net>
Date: Thu Apr 4 17:41:28 2019 +0200
GetDate return unserializable datetime object
diff --git a/bindings/python/example_scripts/rest-api/gnucash_simple.py b/bindings/python/example_scripts/rest-api/gnucash_simple.py
index 124c54aa7..259e244b9 100644
--- a/bindings/python/example_scripts/rest-api/gnucash_simple.py
+++ b/bindings/python/example_scripts/rest-api/gnucash_simple.py
@@ -111,8 +111,8 @@ def transactionToDict(transaction, entities):
simple_transaction['imbalance_value'] = transaction.GetImbalanceValue(
).to_double()
simple_transaction['is_balanced'] = transaction.IsBalanced()
- simple_transaction['date'] = transaction.GetDate()
simple_transaction['date_posted'] = transaction.RetDatePostedTS(
+ simple_transaction['date'] = transaction.GetDate().strftime('%Y-%m-%d')
).strftime('%Y-%m-%d')
simple_transaction['date_entered'] = transaction.RetDateEnteredTS(
).strftime('%Y-%m-%d')
commit b73be1b5239181071c0e161d80abe07f67044dc0
Author: c-holtermann <mail at c-holtermann.net>
Date: Thu Apr 4 17:39:18 2019 +0200
GetInvTaxTable returns unserializable object
diff --git a/bindings/python/example_scripts/rest-api/gnucash_simple.py b/bindings/python/example_scripts/rest-api/gnucash_simple.py
index 509d7aca7..124c54aa7 100644
--- a/bindings/python/example_scripts/rest-api/gnucash_simple.py
+++ b/bindings/python/example_scripts/rest-api/gnucash_simple.py
@@ -57,7 +57,7 @@ def vendorToDict(vendor):
simple_vendor['notes'] = vendor.GetNotes()
simple_vendor['active'] = vendor.GetActive()
simple_vendor['currency'] = vendor.GetCurrency().get_mnemonic()
- simple_vendor['tax_table_override'] = vendor.GetTaxTableOverride()
+ #simple_vendor['tax_table_override'] = vendor.GetTaxTableOverride()
simple_vendor['address'] = addressToDict(vendor.GetAddr())
simple_vendor['tax_included'] = vendor.GetTaxIncluded()
@@ -77,7 +77,7 @@ def customerToDict(customer):
simple_customer['discount'] = customer.GetDiscount().to_double()
simple_customer['credit'] = customer.GetCredit().to_double()
simple_customer['currency'] = customer.GetCurrency().get_mnemonic()
- simple_customer['tax_table_override'] = customer.GetTaxTableOverride()
+ # simple_customer['tax_table_override'] = customer.GetTaxTableOverride()
simple_customer['address'] = addressToDict(customer.GetAddr())
simple_customer['shipping_address'] = addressToDict(
customer.GetShipAddr())
@@ -257,7 +257,7 @@ def entryToDict(entry):
simple_entry['discounted_how'] = entry.GetInvDiscountHow()
simple_entry['inv_taxable'] = entry.GetInvTaxable()
simple_entry['inv_tax_included'] = entry.GetInvTaxIncluded()
- simple_entry['inv_tax_table_override'] = entry.GetInvTaxTable()
+ # simple_entry['inv_tax_table_override'] = entry.GetInvTaxTable()
if entry.GetBillAccount() == None:
simple_entry['bill_account'] = {}
else:
commit b06801185c764bca61f05574496d93d95c08396c
Author: c-holtermann <mail at c-holtermann.net>
Date: Thu Apr 4 14:50:05 2019 +0200
shebang should be specific to python version (PEP394)
preferred form is #!/usr/bin/env python3 as gnucash now only works with
python3
diff --git a/bindings/python/example_scripts/gnc_convenience.py b/bindings/python/example_scripts/gnc_convenience.py
index 808ab3886..2d222379a 100644
--- a/bindings/python/example_scripts/gnc_convenience.py
+++ b/bindings/python/example_scripts/gnc_convenience.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
##@file
diff --git a/bindings/python/example_scripts/latex_invoices.py b/bindings/python/example_scripts/latex_invoices.py
index f015261b0..f754bc1d2 100644
--- a/bindings/python/example_scripts/latex_invoices.py
+++ b/bindings/python/example_scripts/latex_invoices.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
##@file
diff --git a/bindings/python/example_scripts/new_book_with_opening_balances.py b/bindings/python/example_scripts/new_book_with_opening_balances.py
index b38960e4d..8e21440a0 100644
--- a/bindings/python/example_scripts/new_book_with_opening_balances.py
+++ b/bindings/python/example_scripts/new_book_with_opening_balances.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# new_book_with_opening_balances.py -- Replicate the account structure of a
# book and apply basis opening balances from the original
diff --git a/bindings/python/example_scripts/priceDB_test.py b/bindings/python/example_scripts/priceDB_test.py
index 7af031072..8ec671500 100644
--- a/bindings/python/example_scripts/priceDB_test.py
+++ b/bindings/python/example_scripts/priceDB_test.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# Test file for price database stuff
# To update the price database call
# $PATH/gnucash --add-price-quotes $PATHTOFILE
diff --git a/bindings/python/example_scripts/price_database_example.py b/bindings/python/example_scripts/price_database_example.py
index 13b0d453a..49c5d28d9 100755
--- a/bindings/python/example_scripts/price_database_example.py
+++ b/bindings/python/example_scripts/price_database_example.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# Another test file for price database stuff
# To update the price database call
# $PATH/gnucash --add-price-quotes $PATHTOFILE
diff --git a/bindings/python/example_scripts/quotes_historic.py b/bindings/python/example_scripts/quotes_historic.py
index c78995abc..16394b189 100644
--- a/bindings/python/example_scripts/quotes_historic.py
+++ b/bindings/python/example_scripts/quotes_historic.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# quotes_historic.py -- Example Script to read historic quote data into gnucash
#
diff --git a/bindings/python/example_scripts/rest-api/gnucash_rest.py b/bindings/python/example_scripts/rest-api/gnucash_rest.py
index 307d3d831..d87a15679 100644
--- a/bindings/python/example_scripts/rest-api/gnucash_rest.py
+++ b/bindings/python/example_scripts/rest-api/gnucash_rest.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
'''
diff --git a/bindings/python/example_scripts/simple_book.py b/bindings/python/example_scripts/simple_book.py
index 4bde60817..9a6040b92 100644
--- a/bindings/python/example_scripts/simple_book.py
+++ b/bindings/python/example_scripts/simple_book.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
## @file
# @brief Simple example for a book
diff --git a/bindings/python/example_scripts/simple_business_create.py b/bindings/python/example_scripts/simple_business_create.py
index 75a00228b..ade0887ad 100644
--- a/bindings/python/example_scripts/simple_business_create.py
+++ b/bindings/python/example_scripts/simple_business_create.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# simple_business_create.py -- Set up a set of books for business feature use
#
diff --git a/bindings/python/example_scripts/simple_invoice_insert.py b/bindings/python/example_scripts/simple_invoice_insert.py
index ad4d7fd0e..63633d72c 100644
--- a/bindings/python/example_scripts/simple_invoice_insert.py
+++ b/bindings/python/example_scripts/simple_invoice_insert.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# simple_invoice_insert.py -- Add an invoice to a set of books
#
diff --git a/bindings/python/example_scripts/simple_session.py b/bindings/python/example_scripts/simple_session.py
index 1a2b424a8..3bd219c9c 100644
--- a/bindings/python/example_scripts/simple_session.py
+++ b/bindings/python/example_scripts/simple_session.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
## @file
# @brief Example Script simple session
# @ingroup python_bindings_examples
diff --git a/bindings/python/example_scripts/simple_sqlite_create.py b/bindings/python/example_scripts/simple_sqlite_create.py
index f3621ec38..7900c9534 100644
--- a/bindings/python/example_scripts/simple_sqlite_create.py
+++ b/bindings/python/example_scripts/simple_sqlite_create.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
## @file
# @brief Example Script simple sqlite create
# @ingroup python_bindings_examples
diff --git a/bindings/python/example_scripts/simple_test.py b/bindings/python/example_scripts/simple_test.py
index 274164168..9bc21789e 100644
--- a/bindings/python/example_scripts/simple_test.py
+++ b/bindings/python/example_scripts/simple_test.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
## @file
# @brief Creates a basic set of accounts and a couple of transactions
# @ingroup python_bindings_examples
commit e7d940ac3f0ec4de3c999e47aac7cc2c80717e3c
Author: c-holtermann <mail at c-holtermann.net>
Date: Thu Apr 4 17:24:40 2019 +0200
iteritems removed in python3
diff --git a/bindings/python/example_scripts/new_book_with_opening_balances.py b/bindings/python/example_scripts/new_book_with_opening_balances.py
index 0ee02c403..b38960e4d 100644
--- a/bindings/python/example_scripts/new_book_with_opening_balances.py
+++ b/bindings/python/example_scripts/new_book_with_opening_balances.py
@@ -334,7 +334,7 @@ def main():
simple_opening_name_used = False
for (namespace, mnemonic), (opening_trans, opening_amount) in \
- opening_balance_per_currency.iteritems() :
+ opening_balance_per_currency.items() :
simple_opening_name_used = create_opening_balance_transaction(
commodtable, namespace, mnemonic,
new_book_root, new_book,
commit 77727ffc49aeaedb9368fe5161d6fab1a108ca0b
Author: c-holtermann <mail at c-holtermann.net>
Date: Thu Apr 4 17:30:44 2019 +0200
python3 does not return list of keys
diff --git a/bindings/python/example_scripts/account_analysis.py b/bindings/python/example_scripts/account_analysis.py
index b7e59966a..bbe6532f7 100644
--- a/bindings/python/example_scripts/account_analysis.py
+++ b/bindings/python/example_scripts/account_analysis.py
@@ -117,7 +117,7 @@ def next_period_start(start_year, start_month, period_type):
def period_end(start_year, start_month, period_type):
if period_type not in PERIODS:
raise Exception("%s is not a valid period, should be %s" % (
- period_type, str(PERIODS.keys()) ) )
+ period_type, str(list(PERIODS.keys())) ) )
end_year, end_month = next_period_start(start_year, start_month,
period_type)
diff --git a/bindings/python/example_scripts/rest-api/gnucash_rest.py b/bindings/python/example_scripts/rest-api/gnucash_rest.py
index a7a54f2b5..307d3d831 100644
--- a/bindings/python/example_scripts/rest-api/gnucash_rest.py
+++ b/bindings/python/example_scripts/rest-api/gnucash_rest.py
@@ -843,7 +843,7 @@ def getSubAccounts(account):
flat_accounts = []
- if 'subaccounts' in account.keys():
+ if 'subaccounts' in list(account.keys()):
for n, subaccount in enumerate(account['subaccounts']):
flat_accounts.append(subaccount)
flat_accounts = flat_accounts + getSubAccounts(subaccount)
commit 64a01f302706007cfbe049a40fd6dae26001ee3e
Author: c-holtermann <mail at c-holtermann.net>
Date: Thu Apr 4 17:32:14 2019 +0200
python3 - 'as' needed in exceptions instead of comma
diff --git a/bindings/python/example_scripts/simple_session.py b/bindings/python/example_scripts/simple_session.py
index ee053123c..1a2b424a8 100644
--- a/bindings/python/example_scripts/simple_session.py
+++ b/bindings/python/example_scripts/simple_session.py
@@ -14,7 +14,7 @@ FILE_2 = "/tmp/example_file.xac"
session = None
try:
session = Session(FILE_1)
-except GnuCashBackendException, backend_exception:
+except GnuCashBackendException as backend_exception:
assert( ERR_FILEIO_FILE_NOT_FOUND in backend_exception.errors)
@@ -28,7 +28,7 @@ session.destroy()
session = Session(FILE_2)
try:
session_2 = Session(FILE_2)
-except GnuCashBackendException, backend_exception:
+except GnuCashBackendException as backend_exception:
assert( ERR_BACKEND_LOCKED in backend_exception.errors )
session.end()
session.destroy()
commit 0068475bb1b1d4e3486b0e3897e7b9d66f75a070
Author: c-holtermann <mail at c-holtermann.net>
Date: Thu Apr 4 17:35:34 2019 +0200
xrange has been dropped in python3
diff --git a/bindings/python/example_scripts/rest-api/gnucash_rest.py b/bindings/python/example_scripts/rest-api/gnucash_rest.py
index 3ee4ad83f..a7a54f2b5 100644
--- a/bindings/python/example_scripts/rest-api/gnucash_rest.py
+++ b/bindings/python/example_scripts/rest-api/gnucash_rest.py
@@ -1824,7 +1824,7 @@ def gnc_numeric_from_decimal(decimal_value):
numerator_place_value = 1
# add each digit to the final value multiplied by the place value
# from least significant to most sigificant
- for i in xrange(len(digits)-1,-1,-1):
+ for i in range(len(digits)-1,-1,-1):
numerator += digits[i] * numerator_place_value
numerator_place_value *= TEN
commit 298797a9bebb1140a61dee87b89d2ff962b78f58
Author: c-holtermann <mail at c-holtermann.net>
Date: Thu Apr 4 11:03:52 2019 +0200
fix due to different invoice date handling
diff --git a/bindings/python/example_scripts/gncinvoice_jinja.py b/bindings/python/example_scripts/gncinvoice_jinja.py
index bcfd3441e..f44f308ab 100755
--- a/bindings/python/example_scripts/gncinvoice_jinja.py
+++ b/bindings/python/example_scripts/gncinvoice_jinja.py
@@ -196,7 +196,7 @@ def main(argv=None):
output = template.render(invoice=invoice, locale=locale) #, company=company)
if filename_from_invoice:
- filename_date = str(invoice.GetDatePosted()) # something like 2014-11-01
+ filename_date = invoice.GetDatePosted().strftime("%Y-%m-%d") # something like 2014-11-01
filename_owner_name = str(invoice.GetOwner().GetName())
filename_invoice_id = str(invoice.GetID())
filename_output = filename_date + "_" + filename_owner_name + "_" + filename_invoice_id + ".tex"
commit 206ed63233ede3a7bd7e00961d85f78bd7aa4b5d
Author: Christoph Holtermann <c.holtermann at gmx.de>
Date: Fri Sep 21 08:53:16 2018 +0200
typo
diff --git a/bindings/python/example_scripts/gncinvoice_jinja.py b/bindings/python/example_scripts/gncinvoice_jinja.py
index e199eb262..bcfd3441e 100755
--- a/bindings/python/example_scripts/gncinvoice_jinja.py
+++ b/bindings/python/example_scripts/gncinvoice_jinja.py
@@ -9,8 +9,8 @@
#
# @details
# Input is a template file that will be filled with information from
-# gnucash Invoices. Jinja2 templating engine ist used. Templates can
-# be Latex, Html or anything.
+# gnucash Invoices. Jinja2 templating engine is being used for this.
+# Templates can be Latex, Html or anything.
#
# Example templates for german invoices:
# - Invoice.tex.tmpl
commit 247d04a5441d8a102555c8bd69c154f9060dd06e
Author: Christoph Holtermann <c.holtermann at gmx.de>
Date: Fri Sep 21 08:49:48 2018 +0200
make executable, remove double -o
diff --git a/bindings/python/example_scripts/gncinvoice_jinja.py b/bindings/python/example_scripts/gncinvoice_jinja.py
old mode 100644
new mode 100755
index 6066d5812..e199eb262
--- a/bindings/python/example_scripts/gncinvoice_jinja.py
+++ b/bindings/python/example_scripts/gncinvoice_jinja.py
@@ -5,7 +5,7 @@
# @brief exports an invoice from gnucash using a template file, see \ref py_invoice_export
# @ingroup python_bindings_examples
# @author Christoph Holtermann (c.holtermann (at) gmx.de)
-# @date 2014-11
+# @date 2014-2018
#
# @details
# Input is a template file that will be filled with information from
@@ -143,9 +143,8 @@ def main(argv=None):
print("-I ID use invoice ID")
print("-t filename use filename as template file")
print("-o filename use filename as output file")
- print( "-o filename use filename as output file" )
- print( "-O create output filename by date, owner and invoice number" )
- print( "-P path path for output file. Overwrites path in -o option" )
+ print("-O create output filename by date, owner and invoice number")
+ print("-P path path for output file. Overwrites path in -o option")
return retcode
commit 1184e92687e704d67373e4ce6c55165577faa132
Author: Christoph Holtermann <c.holtermann at gmx.de>
Date: Thu Sep 6 13:17:31 2018 +0200
2to3
diff --git a/bindings/python/example_scripts/str_methods.py b/bindings/python/example_scripts/str_methods.py
index 64c81445c..dfbec36c6 100644
--- a/bindings/python/example_scripts/str_methods.py
+++ b/bindings/python/example_scripts/str_methods.py
@@ -1,10 +1,10 @@
#!/usr/bin/env python3
## @file
-# @brief Add __str__ and __unicode__ methods to financial objects so that @code print object @endcode leads to human readable results
-""" @package str_methods.py -- Add __str__ and __unicode__ methods to financial objects
+# @brief Add __str__ methods to financial objects so that @code print object @endcode leads to human readable results
+""" @package str_methods.py -- Add __str__ methods to financial objects
- Import this module and str(Object) and unicode(Object) where Object is Transaction, Split,Invoice
- or Entry leads to human readable results. That is handy when using @code print object @endcode
+ Import this module and str(Object) where Object is Transaction, Split, Invoice or Entry leads to
+ human readable results. That is handy when using @code print object @endcode
I chose to put these functions/methods in a separate file to develop them like this and maybe if
they prove to be useful they can be put in gnucash_core.py.
@@ -150,29 +150,29 @@ class ClassWithCutting__format__():
value=self.value
# Replace Tabs and linebreaks
- import types
- if type(value) in [types.StringType, types.UnicodeType]:
- value=value.replace("\t","|")
- value=value.replace("\n","|")
+ #import types
+ if isinstance(value, str):
+ value = value.replace("\t","|")
+ value = value.replace("\n","|")
# Do regular formatting of object
- value=value.__format__(fmt)
+ value = value.__format__(fmt)
# Cut resulting value if longer than specified by width
- width=get_width(fmt)
+ width = get_width(fmt)
if width:
- value=cut(value, width, "...")
+ value = cut(value, width, "...")
return value
def all_as_classwithcutting__format__(*args):
"""Converts every argument to instance of ClassWithCutting__format__"""
- import types
+ #import types
l=[]
for a in args:
- if type(a) in [types.StringType, types.UnicodeType]:
- a=a.decode("UTF-8")
+ #if type(a) in [types.StringType, types.UnicodeType]:
+ # a=a.decode("UTF-8")
l.append(ClassWithCutting__format__(a))
return l
@@ -180,15 +180,15 @@ def all_as_classwithcutting__format__(*args):
def all_as_classwithcutting__format__keys(encoding=None, error=None, **keys):
"""Converts every argument to instance of ClassWithCutting__format__"""
- import types
+ #import types
d={}
if encoding==None:
encoding=DEFAULT_ENCODING
if error==None:
error=DEFAULT_ERROR
for a in keys:
- if type(keys[a]) in [types.StringType, types.UnicodeType]:
- keys[a]=keys[a].decode(encoding,error)
+ #if isinstance(keys[a], str):
+ # keys[a]=keys[a].decode(encoding,error)
d[a]=ClassWithCutting__format__(keys[a])
return d
@@ -196,8 +196,8 @@ def all_as_classwithcutting__format__keys(encoding=None, error=None, **keys):
# Split
-def __split__unicode__(self, encoding=None, error=None):
- """__unicode__(self, encoding=None, error=None) -> object
+def __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.
@@ -229,40 +229,31 @@ def __split__unicode__(self, encoding=None, error=None):
"memo":self.GetMemo(),
"lot":lot_str}
- fmt_str= (u"Account: {account:20} "+
- u"Value: {value:>10} "+
- u"Memo: {memo:30} ")
+ fmt_str= ("Account: {account:20} "+
+ "Value: {value:>10} "+
+ "Memo: {memo:30} ")
if self.optionflags & self.OPTIONFLAGS_BY_NAME["PRINT_TRANSACTION"]:
fmt_t_dict={
"transaction_time":time.ctime(transaction.GetDate()),
"transaction2":transaction.GetDescription()}
fmt_t_str=(
- u"Transaction: {transaction_time:30} "+
- u"- {transaction2:30} "+
- u"Lot: {lot:10}")
+ "Transaction: {transaction_time:30} "+
+ "- {transaction2:30} "+
+ "Lot: {lot:10}")
fmt_dict.update(fmt_t_dict)
fmt_str += fmt_t_str
return fmt_str.format(**all_as_classwithcutting__format__keys(encoding,error,**fmt_dict))
-def __split__str__(self):
- """Returns a bytestring representation of self.__unicode__"""
-
- from gnucash import Split
- #self=Split(instance=self)
-
- return unicode(self).encode('utf-8')
-
# This could be something like an __init__. Maybe we could call it virus because it infects the Split object which
# thereafter mutates to have better capabilities.
infect(gnucash.Split,__split__str__,"__str__")
-infect(gnucash.Split,__split__unicode__,"__unicode__")
gnucash.Split.register_optionflag("PRINT_TRANSACTION")
gnucash.Split.setflag("PRINT_TRANSACTION",True)
-def __transaction__unicode__(self):
- """__unicode__ method for Transaction class"""
+def __transaction__str__(self):
+ """__str__ method for Transaction class"""
from gnucash import Transaction
import time
self=Transaction(instance=self)
@@ -271,7 +262,7 @@ def __transaction__unicode__(self):
'Description:',self.GetDescription(),
'Notes:',self.GetNotes())
- transaction_str = u"{0:6}{1:25} {2:14}{3:40} {4:7}{5:40}".format(
+ transaction_str = "{0:6}{1:25} {2:14}{3:40} {4:7}{5:40}".format(
*all_as_classwithcutting__format__(*fmt_tuple))
transaction_str += "\n"
@@ -282,29 +273,18 @@ def __transaction__unicode__(self):
transaction_flag = split.getflag("PRINT_TRANSACTION")
split.setflag("PRINT_TRANSACTION",False)
- splits_str += u"[{0:>2}] ".format(unicode(n))
- splits_str += unicode(split)
+ splits_str += "[{0:>2}] ".format(str(n))
+ splits_str += str(split)
splits_str += "\n"
split.setflag("PRINT_TRANSACTION",transaction_flag)
return transaction_str + splits_str
-def __transaction__str__(self):
- """__str__ method for Transaction class"""
- from gnucash import Transaction
-
- self=Transaction(instance=self)
- return unicode(self).encode('utf-8')
-
-# These lines add transaction_str as method __str__ to Transaction object
gnucash.gnucash_core_c.__transaction__str__=__transaction__str__
gnucash.Transaction.add_method("__transaction__str__","__str__")
-gnucash.gnucash_core_c.__transaction__unicode__=__transaction__unicode__
-gnucash.Transaction.add_method("__transaction__unicode__","__unicode__")
-
-def __invoice__unicode__(self):
- """__unicode__ method for Invoice"""
+def __invoice__str__(self):
+ """__str__ method for Invoice"""
from gnucash.gnucash_business import Invoice
self=Invoice(instance=self)
@@ -324,37 +304,27 @@ def __invoice__unicode__(self):
"total_value":str(self.GetTotal()),
"currency_mnemonic":self.GetCurrency().get_mnemonic()}
- ret_invoice= (u"{id_name:4}{id_value:10} {notes_name:7}{notes_value:20} {active_name:8}{active_value:7} {owner_name:12}{owner_value:20}"+
- u"{total_name:8}{total_value:10}{currency_mnemonic:3}").\
+ 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}"+
+ "{total_name:8}{total_value:10}{currency_mnemonic:3}").\
format(**all_as_classwithcutting__format__keys(**fmt_dict))
- ret_entries=u""
+ ret_entries=""
entry_list = self.GetEntries()
for entry in entry_list: # Type of entry has to be checked
if not(type(entry)==Entry):
entry=Entry(instance=entry)
- ret_entries += " "+unicode(entry)+"\n"
+ ret_entries += " "+str(entry)+"\n"
return ret_invoice+"\n"+ret_entries
-def __invoice__str__(self):
- """__str__ method for invoice class"""
-
- from gnucash.gnucash_business import Invoice
- self=Invoice(instance=self)
-
- return unicode(self).encode('utf-8')
from gnucash.gnucash_business import Invoice
gnucash.gnucash_core_c.__invoice__str__=__invoice__str__
gnucash.gnucash_business.Invoice.add_method("__invoice__str__","__str__")
-gnucash.gnucash_core_c.__invoice__unicode__=__invoice__unicode__
-gnucash.gnucash_business.Invoice.add_method("__invoice__unicode__","__unicode__")
-
-def __entry__unicode__(self):
- """__unicode__ method for Entry"""
+def __entry__str__(self):
+ """__str__ method for Entry"""
from gnucash.gnucash_business import Entry
self=Entry(instance=self)
@@ -362,34 +332,21 @@ def __entry__unicode__(self):
# This dict and the return statement can be changed according to individual needs
fmt_dict={
"date_name":"Date:",
- "date_value":unicode(self.GetDate()),
+ "date_value":str(self.GetDate()),
"description_name":"Description:",
"description_value":self.GetDescription(),
"notes_name":"Notes:",
"notes_value":self.GetNotes(),
"quant_name":"Quantity:",
- "quant_value":unicode(self.GetQuantity()),
+ "quant_value":str(self.GetQuantity()),
"invprice_name":"InvPrice:",
- "invprice_value":unicode(self.GetInvPrice())}
+ "invprice_value":str(self.GetInvPrice())}
- return (u"{date_name:6}{date_value:15} {description_name:13}{description_value:20} {notes_name:7}{notes_value:20}"+
- u"{quant_name:12}{quant_value:7} {invprice_name:10}{invprice_value:7}").\
+ return ("{date_name:6}{date_value:15} {description_name:13}{description_value:20} {notes_name:7}{notes_value:20}"+
+ "{quant_name:12}{quant_value:7} {invprice_name:10}{invprice_value:7}").\
format(**all_as_classwithcutting__format__keys(**fmt_dict))
-def __entry__str__(self):
- """__str__ method for Entry class"""
-
- from gnucash.gnucash_business import Entry
- self=Entry(instance=self)
-
- return unicode(self).encode('utf-8')
-
from gnucash.gnucash_business import Entry
gnucash.gnucash_core_c.__entry__str__=__entry__str__
gnucash.gnucash_business.Entry.add_method("__entry__str__","__str__")
-
-gnucash.gnucash_core_c.__entry__unicode__=__entry__unicode__
-gnucash.gnucash_business.Entry.add_method("__entry__unicode__","__unicode__")
-
-
commit 002595f4ccf6912235f5d41117b4796dae7f223a
Author: Christoph Holtermann <c.holtermann at gmx.de>
Date: Thu Sep 6 13:15:20 2018 +0200
add options iOP
diff --git a/bindings/python/example_scripts/gncinvoice_jinja.py b/bindings/python/example_scripts/gncinvoice_jinja.py
index c6d59c4df..6066d5812 100644
--- a/bindings/python/example_scripts/gncinvoice_jinja.py
+++ b/bindings/python/example_scripts/gncinvoice_jinja.py
@@ -32,6 +32,7 @@
try:
import locale
+ import os
import sys
import getopt
import gnucash
@@ -60,9 +61,12 @@ def main(argv=None):
list_invoices = False
invoice_number = None
invoice_id = None
+ filename_from_invoice = False
+ output_path = None
+ with_ipshell = False
try:
- opts, args = getopt.getopt(argv[1:], "fhlI:t:o:", ["help"])
+ opts, args = getopt.getopt(argv[1:], "fhliI:t:o:OP:", ["help"])
except getopt.error as msg:
raise Usage(msg)
@@ -74,16 +78,27 @@ def main(argv=None):
raise Usage("Help:")
if opt[0] in ["-I"]:
invoice_id = opt[1]
- print("using invoice ID '" + str(invoice_id) + "'.")
+ print ("using invoice ID '" + str(invoice_id) + "'.")
+ if opt[0] in ["-i"]:
+ print ("Using ipshell")
+ with_ipshell = True
if opt[0] in ["-o"]:
filename_output = opt[1]
print("using output file", filename_output)
+ if opt[0] in ["-O"]:
+ if filename_output:
+ print ("given output filename will be overwritten,")
+ print ("creating output filename from Invoice data.")
+ filename_from_invoice = True
if opt[0] in ["-t"]:
filename_template = opt[1]
print("using template file", filename_template)
if opt[0] in ["-l"]:
list_invoices = True
print("listing invoices")
+ if opt[0] in ["-P"]:
+ output_path = opt[1]
+ print ("output path is", output_path + ".")
# Check for correct input
if len(args)>1:
@@ -100,7 +115,7 @@ def main(argv=None):
raise Usage("No template given !")
# Check for output file
- if not filename_output:
+ if not (filename_output or filename_from_invoice):
if filename_template:
filename_output = filename_template + ".out"
print("no output filename given, will be:", filename_output)
@@ -128,6 +143,9 @@ def main(argv=None):
print("-I ID use invoice ID")
print("-t filename use filename as template file")
print("-o filename use filename as output file")
+ print( "-o filename use filename as output file" )
+ print( "-O create output filename by date, owner and invoice number" )
+ print( "-P path path for output file. Overwrites path in -o option" )
return retcode
@@ -166,17 +184,35 @@ def main(argv=None):
print("Using the following invoice:")
print(invoice)
- loader = jinja2.FileSystemLoader('.')
+
+ path_template = os.path.dirname(filename_template)
+ filename_template_basename = os.path.basename(filename_template)
+
+ loader = jinja2.FileSystemLoader(path_template)
env = jinja2.Environment(loader=loader)
- template = env.get_template(filename_template)
+ template = env.get_template(filename_template_basename)
+
+ #company = gnucash_business.Company(book.instance)
+
+ output = template.render(invoice=invoice, locale=locale) #, company=company)
- #import IPython
- #IPython.embed()
- output = template.render(invoice=invoice, locale=locale)
+ if filename_from_invoice:
+ filename_date = str(invoice.GetDatePosted()) # something like 2014-11-01
+ filename_owner_name = str(invoice.GetOwner().GetName())
+ filename_invoice_id = str(invoice.GetID())
+ filename_output = filename_date + "_" + filename_owner_name + "_" + filename_invoice_id + ".tex"
- print("Writing output", filename_output, ".")
+ if output_path:
+ filename_output = os.path.join(output_path, os.path.basename(filename_output))
+
+ print ("Writing output", filename_output, ".")
with open(filename_output, 'w') as f:
- f.write(output.encode('utf-8'))
+ f.write(output)
+
+ if with_ipshell:
+ import IPython
+ IPython.embed()
+
if __name__ == "__main__":
sys.exit(main())
commit 61f7613b8d7a88b31b37ad1c82063a5a5a46a29e
Author: Christoph Holtermann <c.holtermann at gmx.de>
Date: Sun Sep 2 16:25:04 2018 +0200
fix for python3
diff --git a/bindings/python/example_scripts/gncinvoice_jinja.py b/bindings/python/example_scripts/gncinvoice_jinja.py
index 73aa805b8..c6d59c4df 100644
--- a/bindings/python/example_scripts/gncinvoice_jinja.py
+++ b/bindings/python/example_scripts/gncinvoice_jinja.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
##@file
@@ -63,7 +63,7 @@ def main(argv=None):
try:
opts, args = getopt.getopt(argv[1:], "fhlI:t:o:", ["help"])
- except getopt.error, msg:
+ except getopt.error as msg:
raise Usage(msg)
for opt in opts:
@@ -105,12 +105,12 @@ def main(argv=None):
filename_output = filename_template + ".out"
print("no output filename given, will be:", filename_output)
- except Usage, err:
+ except Usage as err:
if err.msg == "Help:":
retcode=0
else:
- print(>>sys.stderr, "Error:",err.msg)
- print(>>sys.stderr, "for help use --help")
+ print("Error:", err.msg, file=sys.stderr)
+ print("for help use --help", file=sys.stderr)
retcode=2
print()
diff --git a/bindings/python/example_scripts/str_methods.py b/bindings/python/example_scripts/str_methods.py
index d1f2f52b8..64c81445c 100644
--- a/bindings/python/example_scripts/str_methods.py
+++ b/bindings/python/example_scripts/str_methods.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
## @file
# @brief Add __str__ and __unicode__ methods to financial objects so that @code print object @endcode leads to human readable results
""" @package str_methods.py -- Add __str__ and __unicode__ methods to financial objects
@@ -30,7 +30,8 @@
# * It seems useful to have an object for each modification. That is because there is some Initialisation to be done.
#
-import gnucash, function_class
+import gnucash
+from gnucash import function_class
# Default values for encoding of strings in GnuCashs Database
DEFAULT_ENCODING = "UTF-8"
Summary of changes:
.../python/example_scripts/account_analysis.py | 2 +-
bindings/python/example_scripts/gnc_convenience.py | 2 +-
.../python/example_scripts/gncinvoice_jinja.py | 71 ++++++++---
bindings/python/example_scripts/latex_invoices.py | 2 +-
.../new_book_with_opening_balances.py | 4 +-
bindings/python/example_scripts/priceDB_test.py | 2 +-
.../example_scripts/price_database_example.py | 2 +-
bindings/python/example_scripts/quotes_historic.py | 2 +-
.../example_scripts/rest-api/gnucash_rest.py | 6 +-
.../example_scripts/rest-api/gnucash_simple.py | 21 ++--
bindings/python/example_scripts/simple_book.py | 2 +-
.../example_scripts/simple_business_create.py | 2 +-
.../example_scripts/simple_invoice_insert.py | 2 +-
bindings/python/example_scripts/simple_session.py | 6 +-
.../python/example_scripts/simple_sqlite_create.py | 2 +-
bindings/python/example_scripts/simple_test.py | 2 +-
bindings/python/example_scripts/str_methods.py | 134 +++++++--------------
bindings/python/gnucash_business.py | 2 +-
bindings/python/gnucash_core.py | 3 +-
bindings/python/time64.i | 100 ++++++++++++---
20 files changed, 216 insertions(+), 153 deletions(-)
mode change 100644 => 100755 bindings/python/example_scripts/gncinvoice_jinja.py
More information about the gnucash-changes
mailing list