details:   https://code.tryton.org/tryton/commit/1cf6e5cb9e4f
branch:    default
user:      Cédric Krier <[email protected]>
date:      Mon May 19 21:42:27 2025 +0200
description:
        Add option to order products from web shop
diffstat:

 modules/web_shop/web.py |  13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diffs (30 lines):

diff -r 02d1fb1eaefe -r 1cf6e5cb9e4f modules/web_shop/web.py
--- a/modules/web_shop/web.py   Thu Nov 20 10:14:13 2025 +0100
+++ b/modules/web_shop/web.py   Mon May 19 21:42:27 2025 +0200
@@ -188,8 +188,11 @@
             'stock_assign': True,
             }
 
-    def get_products(self, pattern=None):
-        "Return the list of products with corresponding prices and taxes"
+    def get_products(self, pattern=None, key=None):
+        """Return a list of products with their corresponding dictionaries of
+        prices and taxes according to the tax pattern.
+        If a key function is supplied, the products will be sorted in ascending
+        order based on the key applied to each product."""
         pool = Pool()
         Date = pool.get('ir.date')
         Product = pool.get('product.product')
@@ -198,7 +201,11 @@
             pattern = {}
 
         with Transaction().set_context(**self.get_context()):
-            all_products = Product.browse(self.products)
+            if key is not None:
+                all_products = sorted(self.products, key=key)
+            else:
+                all_products = self.products
+            all_products = Product.browse(all_products)
             today = Date.today()
 
         customer_tax_rule = self._customer_taxe_rule()

Reply via email to