From 6fec6444fc6879d6f3aa821127dda84fa925dd2a Mon Sep 17 00:00:00 2001 From: David Harper Date: Sat, 6 Feb 2021 10:47:06 +0000 Subject: [PATCH] Add trigonometric functions to sqlite backend issue9996 review333731002 --- CHANGELOG | 1 + trytond/backend/sqlite/database.py | 11 +++++++++++ trytond/tests/test_backend.py | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 3e4875a3fb..9fc88d514a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add trigonometric functions to sqlite backend * Allow skipping user warnings globally * Add validate option to trytond-admin * Refresh pool of other processes diff --git a/trytond/backend/sqlite/database.py b/trytond/backend/sqlite/database.py index 6cc7e338b2..e95829dd2c 100644 --- a/trytond/backend/sqlite/database.py +++ b/trytond/backend/sqlite/database.py @@ -375,6 +375,17 @@ class Database(DatabaseInterface): self._conn.create_function('trunc', 1, math.trunc) self._conn.create_function('trunc', 2, trunc) + # Trigonomentric functions + self._conn.create_function('acos', 1, math.acos) + self._conn.create_function('asin', 1, math.asin) + self._conn.create_function('atan', 1, math.atan) + self._conn.create_function('atan2', 2, math.atan2) + self._conn.create_function('cos', 1, math.cos) + self._conn.create_function( + 'cot', 1, lambda x: 1 / math.tan(x) if x else math.inf) + self._conn.create_function('sin', 1, math.sin) + self._conn.create_function('tan', 1, math.tan) + # Random functions self._conn.create_function('random', 0, random.random) self._conn.create_function('setseed', 1, random.seed) diff --git a/trytond/tests/test_backend.py b/trytond/tests/test_backend.py index 1a46e2e578..01f4eed8fd 100644 --- a/trytond/tests/test_backend.py +++ b/trytond/tests/test_backend.py @@ -110,6 +110,15 @@ class BackendTestCase(unittest.TestCase): (functions.Sqrt(2.), 1.4142135623731), (functions.Trunc(42.8), 42), (functions.Trunc(42.4348, 2), 42.43), + (functions.Acos(0.5), 1.0471975511965979), + (functions.Asin(0.5), 0.5235987755982989), + (functions.Atan(0.5), 0.4636476090008061), + (functions.Atan2(0.5, 0.5), 0.7853981633974483), + (functions.Cos(1), 0.5403023058681398), + (functions.Cot(0), math.inf), + (functions.Cot(1), 0.6420926159343306), + (functions.Sin(1), 0.8414709848078965), + (functions.Tan(1), 1.5574077246549023), (functions.CharLength('jose'), 4), (functions.Lower('TOM'), 'tom'), (functions.Overlay('Txxxxas', 'hom', 2, 4), 'Thomas'),