From 93734cb82b571d4b2b48e6567299f15d2e1a2f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 25 Feb 2021 21:13:56 +0100 Subject: [PATCH] Default to ordering documents by date issue10079 review339831002 --- stock.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/stock.py b/stock.py index 21e5f7c4d2..9b7982095d 100644 --- a/stock.py +++ b/stock.py @@ -4,6 +4,7 @@ from collections import defaultdict from decimal import Decimal from sql import Column +from sql.conditionals import Coalesce from sql.operators import Concat from sql.aggregate import Count @@ -260,7 +261,10 @@ class ShipmentDrop(Workflow, ModelSQL, ModelView): @classmethod def __setup__(cls): super(ShipmentDrop, cls).__setup__() - cls._order[0] = ('id', 'DESC') + cls._order = [ + ('effective_date', 'ASC NULLS LAST'), + ('id', 'DESC'), + ] cls._transitions |= set(( ('draft', 'waiting'), ('waiting', 'shipped'), @@ -297,6 +301,11 @@ class ShipmentDrop(Workflow, ModelSQL, ModelView): }, }) + @classmethod + def order_effective_date(cls, tables): + table, _ = tables[None] + return [Coalesce(table.effective_date, table.planned_date)] + @staticmethod def default_state(): return 'draft'