changeset 53c5917c0602 in modules/product:default
details: https://hg.tryton.org/modules/product?cmd=changeset;node=53c5917c0602
description:
        Add default order on product and template

        issue9339
        review321331002
diffstat:

 CHANGELOG  |   1 +
 product.py |  12 ++++++++++++
 2 files changed, 13 insertions(+), 0 deletions(-)

diffs (51 lines):

diff -r b40ffc3412b7 -r 53c5917c0602 CHANGELOG
--- a/CHANGELOG Mon Jun 01 10:08:02 2020 +0100
+++ b/CHANGELOG Mon Jun 15 09:00:44 2020 +0200
@@ -1,3 +1,4 @@
+* Add default order on product and template
 * Check price_decimal configuration
 
 Version 5.6.0 - 2020-05-04
diff -r b40ffc3412b7 -r 53c5917c0602 product.py
--- a/product.py        Mon Jun 01 10:08:02 2020 +0100
+++ b/product.py        Mon Jun 15 09:00:44 2020 +0200
@@ -52,6 +52,7 @@
         DeactivableMixin, ModelSQL, ModelView, CompanyMultiValueMixin):
     "Product Template"
     __name__ = "product.template"
+    _order_name = 'rec_name'
     name = fields.Char(
         "Name", size=None, required=True, translate=True, select=True)
     code = fields.Char("Code", select=True)
@@ -111,6 +112,11 @@
                 cls._table)
 
     @classmethod
+    def __setup__(cls):
+        super().__setup__()
+        cls._order.insert(0, ('rec_name', 'ASC'))
+
+    @classmethod
     def multivalue_model(cls, field):
         pool = Pool()
         if field == 'list_price':
@@ -119,6 +125,11 @@
             return pool.get('product.cost_price_method')
         return super(Template, cls).multivalue_model(field)
 
+    @classmethod
+    def order_rec_name(cls, tables):
+        table, _ = tables[None]
+        return [table.code, table.name]
+
     def get_rec_name(self, name):
         if self.code:
             return '[' + self.code + ']' + self.name
@@ -300,6 +311,7 @@
         cls._no_template_field.update(['products'])
 
         super(Product, cls).__setup__()
+        cls._order.insert(0, ('rec_name', 'ASC'))
 
         t = cls.__table__()
         cls._sql_constraints = [

Reply via email to