commit de86dc7d48959ac5f2f9eee2245df54ff8761333
parent 725e428b7b5dd73c57766a756180573692c99608
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date: Mon, 20 Feb 2017 16:51:40 +0100
Adding initial logic for amounts arithmetics
in Python library.
Diffstat:
4 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
@@ -2,7 +2,7 @@
.PHONY: graphics
-SUBDIRS := php
+SUBDIRS := php Python
all: $(SUBDIRS)
diff --git a/Python/pytaler/__init__.py b/Python/pytaler/__init__.py
diff --git a/Python/pytaler/amounts.py b/Python/pytaler/amounts.py
@@ -0,0 +1,29 @@
+# This file is part of GNU TALER.
+# Copyright (C) 2014-2017 INRIA
+#
+# TALER is free software; you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free Software
+# Foundation; either version 2.1, or (at your option) any later version.
+#
+# TALER 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 Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License along with
+# GNU TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+#
+# @author Marcello Stanisci
+
+FRACTION = 100000000
+
+def amount_get_zero(currency):
+ return {"value": 0, "fraction": 0, "currency": currency}
+
+
+def amount_sum(a1, a2):
+ assert(a1['currency'] == a2['currency'])
+ fractions = a1['fraction'] + a2['fraction']
+ ret = {"value": a1["value"] + a2["value"] + int(fractions / FRACTION),
+ "fraction": fractions % FRACTION,
+ "currency": a1["currency"]}
+ return ret
diff --git a/Python/setup.py b/Python/setup.py
@@ -0,0 +1,11 @@
+from setuptools import setup, find_packages
+
+setup(name='pytaler',
+ version='0.0',
+ description='Helper functions for Taler amounts',
+ url='git://taler.net/merchant-frontend-examples',
+ author='Marcello Stanisci',
+ author_email='marcello.stanisci@inria.fr',
+ license='GPL',
+ packages=find_packages(),
+ zip_safe=False)