changeset 79d2c40d90a4 in modules/sale:default
details: https://hg.tryton.org/modules/sale?cmd=changeset;node=79d2c40d90a4
description:
Use the number of category for pairing the categories and the lines
The Elegant Pairing generate integer out of range as soon as there are
more
than 46340 sale lines (under PostgreSQL).
As the number of category is almost fixed and small, we can pair by
multiplying
the line id per the number of category and add the category id.
We must try to use number of category that does not change if new
categories
are created meanwhile. For that we always takes the first power of ten
bigger
then the current number. This reduces the number of cases when all ids
will be
changed because a new category was added.
issue8941
review278321003
diffstat:
sale_reporting.py | 18 ++++++++++--------
1 files changed, 10 insertions(+), 8 deletions(-)
diffs (37 lines):
diff -r 8b5b19274cb4 -r 79d2c40d90a4 sale_reporting.py
--- a/sale_reporting.py Sat Dec 14 10:47:54 2019 +0100
+++ b/sale_reporting.py Mon Jan 13 23:48:22 2020 +0100
@@ -9,9 +9,8 @@
pygal = None
from dateutil.relativedelta import relativedelta
from sql import Null, Literal, Column
-from sql.aggregate import Sum, Min, Count
-from sql.conditionals import Case
-from sql.functions import CurrentTimestamp, DateTrunc
+from sql.aggregate import Sum, Max, Min, Count
+from sql.functions import CurrentTimestamp, DateTrunc, Power, Ceil, Log
from trytond.pool import Pool
from trytond.model import ModelSQL, ModelView, UnionMixin, fields
@@ -385,13 +384,16 @@
@classmethod
def _column_id(cls, tables):
+ pool = Pool()
+ Category = pool.get('product.category')
+ category = Category.__table__()
line = tables['line']
template_category = tables['line.product.template_category']
- # Pairing function from http://szudzik.com/ElegantPairing.pdf
- return Min(Case(
- (line.id < template_category.id,
- (template_category.id * template_category.id) + line.id),
- else_=(line.id * line.id) + line.id + template_category.id))
+ # Get a stable number of category over time
+ # by using number one order bigger.
+ nb_category = category.select(
+ Power(10, (Ceil(Log(Max(category.id))) + Literal(1))))
+ return Min(line.id * nb_category + template_category.id)
@classmethod
def _group_by(cls, tables):