Add issue8880_trytond.diff - trytond - Position new record based on order

This commit is contained in:
Raimon Esteve 2020-01-14 14:56:04 +01:00
parent 7c80810ef7
commit d9d15cca61
2 changed files with 198 additions and 0 deletions

196
issue8880_trytond.diff Normal file
View file

@ -0,0 +1,196 @@
diff --git a/trytond/trytond/ir/action.py b/trytond/ir/action.py
index a6d6ec32..9904c8dc 100644
--- a/trytond/trytond/ir/action.py
+++ b/trytond/ir/action.py
@@ -10,6 +10,7 @@ from sql import Null
from trytond.config import config
from trytond.i18n import gettext
from trytond.model.exceptions import ValidationError
+from trytond.pyson import PYSONEncoder
from ..model import (
ModelView, ModelStorage, ModelSQL, DeactivableMixin, fields,
sequence_ordered)
@@ -647,6 +648,8 @@ class ActionReport(ActionMixin, ModelSQL, ModelView):
@classmethod
def get_pyson(cls, reports, name):
+ pool = Pool()
+ encoder = PYSONEncoder()
pysons = {}
field = name[6:]
defaults = {
@@ -870,6 +873,8 @@ class ActionActWindow(ActionMixin, ModelSQL, ModelView):
@classmethod
def get_pyson(cls, windows, name):
+ pool = Pool()
+ encoder = PYSONEncoder()
pysons = {}
field = name[6:]
defaults = {
@@ -878,6 +883,12 @@ class ActionActWindow(ActionMixin, ModelSQL, ModelView):
'search_value': '[]',
}
for window in windows:
+ if not window.order and field == 'order':
+ if window.res_model:
+ defaults['order'] = encoder.encode(
+ getattr(pool.get(window.res_model), '_order', 'null'))
+ else:
+ defaults['order'] = 'null'
pysons[window.id] = (getattr(window, field)
or defaults.get(field, 'null'))
return pysons
diff --git a/trytond/trytond/ir/attachment.py b/trytond/ir/attachment.py
index c9f92a10..5aa85afd 100644
--- a/trytond/trytond/ir/attachment.py
+++ b/trytond/ir/attachment.py
@@ -54,7 +54,10 @@ class Attachment(ResourceMixin, ModelSQL, ModelView):
@classmethod
def __setup__(cls):
super().__setup__()
- cls._order.insert(0, ('create_date', 'DESC'))
+ cls._order = [
+ ('create_date', 'DESC'),
+ ('id', 'DESC'),
+ ]
@classmethod
def __register__(cls, module_name):
diff --git a/trytond/trytond/ir/ui/tree.rnc b/trytond/ir/ui/tree.rnc
index b694f5f4..77625b55 100644
--- a/trytond/trytond/ir/ui/tree.rnc
+++ b/trytond/ir/ui/tree.rnc
@@ -5,7 +5,7 @@ tree = element tree { attlist.tree,
| button)*
}
attlist.tree &= attribute on_write { text }?
-attlist.tree &= attribute editable { "top" | "bottom" }?
+attlist.tree &= attribute editable { "top" | "bottom" | "0" | "1" }?
attlist.tree &= attribute sequence { text }?
attlist.tree &=
[ a:defaultValue = "0" ] attribute keyword_open { "0" | "1" }?
diff --git a/trytond/trytond/ir/ui/tree.rng b/trytond/ir/ui/tree.rng
index 0c5651fc..73437d74 100644
--- a/trytond/trytond/ir/ui/tree.rng
+++ b/trytond/ir/ui/tree.rng
@@ -29,6 +29,8 @@
<choice>
<value>top</value>
<value>bottom</value>
+ <value>0</value>
+ <value>1</value>
</choice>
</attribute>
</optional>
diff --git a/trytond/trytond/ir/view/attachment_list.xml b/trytond/ir/view/attachment_list.xml
index 4759271b..cf5b577b 100644
--- a/trytond/trytond/ir/view/attachment_list.xml
+++ b/trytond/ir/view/attachment_list.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
-<tree editable="top">
+<tree editable="1">
<field name="resource" expand="2"/>
<field name="name" expand="2"/>
<field name="summary" expand="1"/>
diff --git a/trytond/trytond/ir/view/lang_list.xml b/trytond/ir/view/lang_list.xml
index b50df81d..2d06b1d0 100644
--- a/trytond/trytond/ir/view/lang_list.xml
+++ b/trytond/ir/view/lang_list.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
-<tree editable="top">
+<tree editable="1">
<field name="name" expand="1"/>
<field name="code"/>
<field name="direction"/>
diff --git a/trytond/trytond/ir/view/module_config_wizard_item_list.xml b/trytond/ir/view/module_config_wizard_item_list.xml
index 51bfa46f..87498859 100644
--- a/trytond/trytond/ir/view/module_config_wizard_item_list.xml
+++ b/trytond/ir/view/module_config_wizard_item_list.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
-<tree editable="top">
+<tree editable="1">
<field name="action" expand="1"/>
<field name="sequence"/>
<field name="state"/>
diff --git a/trytond/trytond/ir/view/translation_list.xml b/trytond/ir/view/translation_list.xml
index 9b5df31a..0bbe31da 100644
--- a/trytond/trytond/ir/view/translation_list.xml
+++ b/trytond/ir/view/translation_list.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
-<tree editable="top">
+<tree editable="1">
<field name="src" widget="char" expand="2"/>
<field name="value" widget="char" expand="2"/>
<field name="fuzzy"/>
diff --git a/trytond/trytond/model/fields/many2many.py b/trytond/model/fields/many2many.py
index 0c68be0d..0191cc21 100644
--- a/trytond/trytond/model/fields/many2many.py
+++ b/trytond/model/fields/many2many.py
@@ -455,6 +455,9 @@ class Many2Many(Field):
definition['search_context'] = encoder.encode(self.search_context)
definition['search_order'] = encoder.encode(self.search_order)
definition['sortable'] &= hasattr(model, 'order_' + self.name)
+ definition['order'] = encoder.encode(
+ getattr(model, '_order', None)
+ if self.order is None else self.order)
if self.size is not None:
definition['size'] = encoder.encode(self.size)
return definition
diff --git a/trytond/trytond/model/fields/one2many.py b/trytond/model/fields/one2many.py
index 24d67e09..401e7ef3 100644
--- a/trytond/trytond/model/fields/one2many.py
+++ b/trytond/model/fields/one2many.py
@@ -349,4 +349,7 @@ class One2Many(Field):
if self.size is not None:
definition['size'] = encoder.encode(self.size)
definition['sortable'] &= hasattr(model, 'order_' + self.name)
+ definition['order'] = encoder.encode(
+ getattr(model, '_order', None)
+ if self.order is None else self.order)
return definition
diff --git a/trytond/trytond/model/modelsql.py b/trytond/model/modelsql.py
index 0ace0b7f..af41284d 100644
--- a/trytond/trytond/model/modelsql.py
+++ b/trytond/model/modelsql.py
@@ -188,7 +188,7 @@ class ModelSQL(ModelStorage):
cls._sql_constraints.append(
('id_positive', Check(table, table.id >= 0),
'ir.msg_id_positive'))
- cls._order = [('id', 'ASC')]
+ cls._order = [('id', None)]
if issubclass(cls, ModelView):
cls.__rpc__.update({
'history_revisions': RPC(),
@@ -1262,11 +1262,14 @@ class ModelSQL(ModelStorage):
for oexpr, otype in order:
fname, _, extra_expr = oexpr.partition('.')
field = cls._fields[fname]
- otype = otype.upper()
- try:
- otype, null_ordering = otype.split(' ', 1)
- except ValueError:
- null_ordering = None
+ if not otype:
+ otype, null_ordering = 'ASC', None
+ else:
+ otype = otype.upper()
+ try:
+ otype, null_ordering = otype.split(' ', 1)
+ except ValueError:
+ null_ordering = None
Order = order_types[otype]
NullOrdering = null_ordering_types[null_ordering]
forder = field.convert_order(oexpr, tables, cls)

2
series
View file

@ -42,3 +42,5 @@ issue7805.diff # [stock] [stock_lot_sled] Allow configuring which quantity is gr
issue8860.diff # [stock_forecast] stock_forecast does not spread all the quantities
statement_of_account.diff # [account] Cumulate balance of previous fiscal years
issue8880_trytond.diff # [trytond] Position new record based on order