From ccfec0345d1c28682eeea0f14a874274de369c7a 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 --- CHANGELOG | 1 + shipment.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index bfa3062b2b..e53a9ed2b8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Default to ordering shipments by date * Add delivery usage to contact mechanism * Make customer's outgoing moves editable for same storage and output zone * Add margin reporting diff --git a/shipment.py b/shipment.py index f51cc233ab..d511cc70e6 100644 --- a/shipment.py +++ b/shipment.py @@ -6,6 +6,7 @@ from collections import defaultdict from functools import partial from sql import Null +from sql.conditionals import Coalesce from trytond.i18n import gettext from trytond.model import Workflow, ModelView, ModelSQL, fields, dualmethod @@ -194,7 +195,9 @@ class ShipmentIn(ShipmentMixin, Workflow, ModelSQL, ModelView): @classmethod def __setup__(cls): super(ShipmentIn, cls).__setup__() - cls._order[0] = ('id', 'DESC') + cls._order = [ + ('id', 'DESC'), + ] cls._transitions |= set(( ('draft', 'received'), ('received', 'done'), @@ -242,6 +245,11 @@ class ShipmentIn(ShipmentMixin, Workflow, ModelSQL, ModelView): [sql_table.state], ['cancelled'], where=sql_table.state == 'cancel')) + @classmethod + def order_effective_date(cls, tables): + table, _ = tables[None] + return [Coalesce(table.effective_date, table.planned_date)] + @staticmethod def default_planned_date(): return Pool().get('ir.date').today() @@ -595,7 +603,10 @@ class ShipmentInReturn(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): @classmethod def __setup__(cls): super(ShipmentInReturn, cls).__setup__() - cls._order[0] = ('id', 'DESC') + cls._order = [ + ('effective_date', 'ASC NULLS LAST'), + ('id', 'ASC'), + ] cls._transitions |= set(( ('draft', 'waiting'), ('waiting', 'assigned'), @@ -660,6 +671,11 @@ class ShipmentInReturn(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): [sql_table.state], ['cancelled'], where=sql_table.state == 'cancel')) + @classmethod + def order_effective_date(cls, tables): + table, _ = tables[None] + return [Coalesce(table.effective_date, table.planned_date)] + @staticmethod def default_state(): return 'draft' @@ -971,7 +987,10 @@ class ShipmentOut(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): @classmethod def __setup__(cls): super(ShipmentOut, cls).__setup__() - cls._order[0] = ('id', 'DESC') + cls._order = [ + ('effective_date', 'ASC NULLS LAST'), + ('id', 'ASC'), + ] cls._transitions |= set(( ('draft', 'waiting'), ('waiting', 'assigned'), @@ -1061,6 +1080,11 @@ class ShipmentOut(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): [sql_table.state], ['cancelled'], where=sql_table.state == 'cancel')) + @classmethod + def order_effective_date(cls, tables): + table, _ = tables[None] + return [Coalesce(table.effective_date, table.planned_date)] + @staticmethod def default_state(): return 'draft' @@ -1581,7 +1605,10 @@ class ShipmentOutReturn(ShipmentMixin, Workflow, ModelSQL, ModelView): @classmethod def __setup__(cls): super(ShipmentOutReturn, cls).__setup__() - cls._order[0] = ('id', 'DESC') + cls._order = [ + ('effective_date', 'ASC NULLS LAST'), + ('id', 'ASC'), + ] cls._transitions |= set(( ('draft', 'received'), ('received', 'done'), @@ -1630,6 +1657,11 @@ class ShipmentOutReturn(ShipmentMixin, Workflow, ModelSQL, ModelView): [sql_table.state], ['cancelled'], where=sql_table.state == 'cancel')) + @classmethod + def order_effective_date(cls, tables): + table, _ = tables[None] + return [Coalesce(table.effective_date, table.planned_date)] + @staticmethod def default_state(): return 'draft' @@ -2043,7 +2075,10 @@ class ShipmentInternal(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): @classmethod def __setup__(cls): super(ShipmentInternal, cls).__setup__() - cls._order[0] = ('id', 'DESC') + cls._order = [ + ('effective_date', 'ASC NULLS LAST'), + ('id', 'ASC'), + ] cls._transitions |= set(( ('request', 'draft'), ('draft', 'waiting'), @@ -2135,6 +2170,13 @@ class ShipmentInternal(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): [sql_table.state], ['cancelled'], where=sql_table.state == 'cancel')) + @classmethod + def order_effective_date(cls, tables): + table, _ = tables[None] + return [Coalesce( + table.effective_start_date, table.effective_date, + table.planned_start_date, table.planned_date)] + @staticmethod def default_state(): return 'draft'