changeset 3fd375dfc32e in modules/stock:default
details: https://hg.tryton.org/modules/stock?cmd=changeset;node=3fd375dfc32e
description:
        Default to ordering documents by date

        issue10079
        review339831002
diffstat:

 CHANGELOG   |   1 +
 shipment.py |  52 +++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 48 insertions(+), 5 deletions(-)

diffs (140 lines):

diff -r cfced3f166f2 -r 3fd375dfc32e CHANGELOG
--- a/CHANGELOG Mon Feb 15 13:59:13 2021 +0100
+++ b/CHANGELOG Thu Feb 25 21:13:56 2021 +0100
@@ -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 -r cfced3f166f2 -r 3fd375dfc32e shipment.py
--- a/shipment.py       Mon Feb 15 13:59:13 2021 +0100
+++ b/shipment.py       Thu Feb 25 21:13:56 2021 +0100
@@ -6,6 +6,7 @@
 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 @@
     @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 @@
                 [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 @@
     @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 @@
                 [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 @@
     @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 @@
                 [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 @@
     @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 @@
                 [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 @@
     @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 @@
                 [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'

Reply via email to