From 9ea335fa4a997bcaa2e33aa3939a82c8a1415f62 Mon Sep 17 00:00:00 2001 From: rhe-odoo Date: Wed, 7 Jun 2023 14:48:01 +0000 Subject: [PATCH] [FIX] point_of_sale: load product requests When the pos was loading only a part of the products, the request should follow those rules order: - product is a favorite - product is a service - product had stock moves soon - product update But this request didn't take into account consumables products and if there was no stock move, the value was null and postgres consider null values first when ordering desc. Now with that changes, the order is correctly set based on the rules above. X-original-commit: f38bea2f8410282c864cc282392572ca27a948ce --- addons/point_of_sale/models/pos_config.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index 51530d93cb318..e3139d76e98dc 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -653,8 +653,9 @@ def get_limited_products_loading(self, fields): WITH pm AS ( SELECT product_id, Max(write_date) date - FROM stock_quant + FROM stock_move_line GROUP BY product_id + ORDER BY date DESC ) SELECT p.id FROM product_product p @@ -669,10 +670,11 @@ def get_limited_products_loading(self, fields): WHERE product_template_id = t.id AND pos_category_id = ANY(%(available_categ_ids)s))) ) OR p.id=%(tip_product_id)s - ORDER BY t.priority DESC, - t.detailed_type DESC, - COALESCE(pm.date,p.write_date) DESC - LIMIT %(limit)s + ORDER BY t.priority DESC, + case when t.detailed_type = 'service' then 1 else 0 end DESC, + pm.date DESC NULLS LAST, + p.write_date + LIMIT %(limit)s """ params = { 'company_id': self.company_id.id,