details:   https://code.tryton.org/tryton/commit/00f66b5708b6
branch:    default
user:      Cédric Krier <[email protected]>
date:      Fri Oct 10 17:42:08 2025 +0200
description:
        Order the list of variants on the product

        Closes #14285
diffstat:

 modules/product/CHANGELOG                             |   1 +
 modules/product/product.py                            |  11 +++++++++++
 modules/product/product.xml                           |   7 +++++++
 modules/product/view/product_form_simple.xml          |   8 +++++---
 modules/product/view/product_tree_simple_sequence.xml |   6 ++++++
 modules/product/view/template_form.xml                |   2 +-
 modules/web_shop_shopify/product.py                   |   2 +-
 7 files changed, 32 insertions(+), 5 deletions(-)

diffs (119 lines):

diff -r 1fd1b8cb6ac6 -r 00f66b5708b6 modules/product/CHANGELOG
--- a/modules/product/CHANGELOG Mon Mar 17 18:24:14 2025 +0100
+++ b/modules/product/CHANGELOG Fri Oct 10 17:42:08 2025 +0200
@@ -1,3 +1,4 @@
+* Order the list of variants on the product
 * Allow a different list price to be set for each variant
 
 Version 7.6.0 - 2025-04-28
diff -r 1fd1b8cb6ac6 -r 00f66b5708b6 modules/product/product.py
--- a/modules/product/product.py        Mon Mar 17 18:24:14 2025 +0100
+++ b/modules/product/product.py        Fri Oct 10 17:42:08 2025 +0200
@@ -120,6 +120,10 @@
         'template', 'category', "Categories", readonly=True)
     products = fields.One2Many(
         'product.product', 'template', "Variants",
+        order=[
+            ('position', 'ASC NULLS FIRST'),
+            ('id', 'ASC'),
+            ],
         help="The different variants the product comes in.")
 
     @classmethod
@@ -416,6 +420,9 @@
     code = fields.Char(
         "Code", readonly=True,
         help="A unique identifier for the variant.")
+    position = fields.Integer(
+        "Position",
+        help="The order of the variant in the list of variants on product.")
     identifiers = fields.One2Many(
         'product.identifier', 'product', "Identifiers",
         help="Other identifiers associated with the variant.")
@@ -498,6 +505,10 @@
             ]
         cls._sql_indexes.add(
             Index(t, (t.code, Index.Similarity(cardinality='high'))))
+        cls._sql_indexes.add(
+            Index(t,
+                (t.position, Index.Range(order='ASC NULLS FIRST')),
+                (t.id, Index.Range(order='ASC'))))
 
         for attr in dir(Template):
             tfield = getattr(Template, attr)
diff -r 1fd1b8cb6ac6 -r 00f66b5708b6 modules/product/product.xml
--- a/modules/product/product.xml       Mon Mar 17 18:24:14 2025 +0100
+++ b/modules/product/product.xml       Fri Oct 10 17:42:08 2025 +0200
@@ -113,6 +113,13 @@
             <field name="name">product_tree_simple</field>
         </record>
 
+        <record model="ir.ui.view" id="product_view_tree_simple_sequence">
+            <field name="model">product.product</field>
+            <field name="type">tree</field>
+            <field name="priority" eval="20"/>
+            <field name="name">product_tree_simple_sequence</field>
+        </record>
+
         <record model="ir.ui.view" id="product_view_form">
             <field name="model">product.product</field>
             <field name="type" eval="None"/>
diff -r 1fd1b8cb6ac6 -r 00f66b5708b6 
modules/product/view/product_form_simple.xml
--- a/modules/product/view/product_form_simple.xml      Mon Mar 17 18:24:14 
2025 +0100
+++ b/modules/product/view/product_form_simple.xml      Fri Oct 10 17:42:08 
2025 +0200
@@ -2,9 +2,6 @@
 <!-- This file is part of Tryton.  The COPYRIGHT file at the top level of
 this repository contains the full copyright notices and license terms. -->
 <form>
-    <label name="template"/>
-    <field name="template"/>
-    <newline/>
     <label name="code"/>
     <group col="-1" name="code" string="">
         <field name="prefix_code"/>
@@ -13,6 +10,11 @@
     <label name="active"/>
     <field name="active"/>
 
+    <label name="template"/>
+    <field name="template"/>
+    <label name="position"/>
+    <field name="position"/>
+
     <label name="list_price"/>
     <field name="list_price"/>
     <newline/>
diff -r 1fd1b8cb6ac6 -r 00f66b5708b6 
modules/product/view/product_tree_simple_sequence.xml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/product/view/product_tree_simple_sequence.xml     Fri Oct 10 
17:42:08 2025 +0200
@@ -0,0 +1,6 @@
+<?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 sequence="position">
+    <field name="rec_name" expand="1"/>
+</tree>
diff -r 1fd1b8cb6ac6 -r 00f66b5708b6 modules/product/view/template_form.xml
--- a/modules/product/view/template_form.xml    Mon Mar 17 18:24:14 2025 +0100
+++ b/modules/product/view/template_form.xml    Fri Oct 10 17:42:08 2025 +0200
@@ -29,7 +29,7 @@
           <field name="cost_price_method"/>
           <newline/>
           <field name="products" mode="form,tree" colspan="2"
-              view_ids="product.product_view_form_simple"/>
+              
view_ids="product.product_view_form_simple,product.product_view_tree_simple_sequence"/>
           <group id="categories" colspan="2" col="2" yexpand="1" yfill="1">
               <field name="categories" colspan="2" yexpand="1" yfill="1" 
view_ids="product.category_view_list"/>
           </group>
diff -r 1fd1b8cb6ac6 -r 00f66b5708b6 modules/web_shop_shopify/product.py
--- a/modules/web_shop_shopify/product.py       Mon Mar 17 18:24:14 2025 +0100
+++ b/modules/web_shop_shopify/product.py       Fri Oct 10 17:42:08 2025 +0200
@@ -192,7 +192,7 @@
     @classmethod
     def __setup__(cls):
         super().__setup__()
-        cls._shopify_fields.update(['code', 'attributes'])
+        cls._shopify_fields.update(['code', 'attributes', 'position'])
 
     @classmethod
     def get_shopify_identifier_to_update(cls, records):

Reply via email to