diff --git a/trytond/doc/ref/backend.rst b/trytond/doc/ref/backend.rst index 6f729f9412..303c99c5ab 100644 --- a/trytond/doc/ref/backend.rst +++ b/trytond/doc/ref/backend.rst @@ -65,9 +65,9 @@ Database If ``hostname`` is set, it checks also if it has the same configured hostname. -.. method:: Database.nextid(connection, table) +.. method:: Database.nextid(connection, table[, count]) - Return the next ID for the ``table`` using the ``connection``. + Return the next ``count`` IDs for the ``table`` using the ``connection``. .. note:: It may return ``None`` for some database. diff --git a/trytond/trytond/backend/database.py b/trytond/trytond/backend/database.py index 22c7ec9a52..4da335ef9a 100644 --- a/trytond/trytond/backend/database.py +++ b/trytond/trytond/backend/database.py @@ -55,7 +55,7 @@ class DatabaseInterface(object): ''' raise NotImplementedError - def nextid(self, connection, table): + def nextid(self, connection, table, count=1): pass def setnextid(self, connection, table, value): diff --git a/trytond/trytond/backend/postgresql/database.py b/trytond/trytond/backend/postgresql/database.py index 3e4680199b..7e52326512 100644 --- a/trytond/trytond/backend/postgresql/database.py +++ b/trytond/trytond/backend/postgresql/database.py @@ -414,12 +414,16 @@ class Database(DatabaseInterface): pass return True - def nextid(self, connection, table): + def nextid(self, connection, table, count=1): cursor = connection.cursor() cursor.execute( - "SELECT nextval(pg_get_serial_sequence(format(%s, %s), %s))", - ('%I', table, 'id')) - return cursor.fetchone()[0] + "SELECT nextval(pg_get_serial_sequence(format(%s, %s), %s)) " + "FROM generate_series(1, %s)", + ('%I', table, 'id', count)) + if count == 1: + return cursor.fetchone()[0] + else: + return [id for id, in cursor] def setnextid(self, connection, table, value): cursor = connection.cursor()