From c338e24ee7589c2f4c0d71595262cee58435416b Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Mon, 4 Dec 2017 14:54:21 +0100 Subject: [PATCH 1/3] [FIX] *: ordered group_by for field with capital letters When doing a group_by in a tree view, and then ordering by an aggregated field which contains at least one capital letter in its name, you will get an error and won't be able to ordery by this field. Why? read_group is called when sorting a group by, which calls _read_group_raw which then goes to call _read_group_prepare, which will return order by terms in this manner ['id asc', 'x_Test desc'] the problem with this is that postgres automatically converts non-quoted/non-qualified column name to lowercase, of course this means that if we have a field "x_Test" but no field "x_test", it will try to look up "x_test" instead of "x_Test" and since the column doesn't exist, it will throw a ProgrammingError. This commit changes this behavior by wrapping the order_by terms generated in _read_group_prepare with double quotes, which postgres interprets correctly. Fixes #21348 --- openerp/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openerp/models.py b/openerp/models.py index f7b68297e6e..ef1d92540d4 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -1914,7 +1914,8 @@ class BaseModel(object): order = '"%s" %s' % (order_field, '' if len(order_split) == 1 else order_split[1]) orderby_terms.append(order) elif order_field in aggregated_fields: - orderby_terms.append(order_part) + order_split[0] = '"' + order_field + '"' + orderby_terms.append(' '.join(order_split)) else: # Cannot order by a field that will not appear in the results (needs to be grouped or aggregated) _logger.warn('%s: read_group order by `%s` ignored, cannot sort on empty columns (not grouped/aggregated)', From 220bdb358719213b9d2fd51965931c85be7912d3 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Mon, 4 Dec 2017 16:35:28 +0100 Subject: [PATCH 2/3] [FIX] mrp: qty producing on update qty of mo When updating the quantity of an MO, the qty we are producing on a work order should possibly be updated. When the finished product is tracked by serial number it should be 1.0 when some quantity is still to be treated. (and not 0 as before) opw-785190 --- addons/mrp/wizard/change_production_qty.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/mrp/wizard/change_production_qty.py b/addons/mrp/wizard/change_production_qty.py index e9588516a0c..3422edd8cb5 100644 --- a/addons/mrp/wizard/change_production_qty.py +++ b/addons/mrp/wizard/change_production_qty.py @@ -68,7 +68,7 @@ class ChangeProductionQty(models.TransientModel): cycle_number * operation.time_cycle * 100.0 / operation.workcenter_id.time_efficiency) quantity = wo.qty_production - wo.qty_produced if production.product_id.tracking == 'serial': - quantity = 1.0 if float_is_zero(quantity, precision_digits=precision) else 0.0 + quantity = 1.0 if not float_is_zero(quantity, precision_digits=precision) else 0.0 else: quantity = quantity if (quantity > 0) else 0 if float_is_zero(quantity, precision_digits=precision): From 78aef7605c63a2ff0ee7e4a16ebccd7a5ab901b5 Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Mon, 4 Dec 2017 14:54:21 +0100 Subject: [PATCH 3/3] [FIX] *: ordered group_by for field with capital letters When doing a group_by in a tree view, and then ordering by an aggregated field which contains at least one capital letter in its name, you will get an error and won't be able to ordery by this field. Why? read_group is called when sorting a group by, which calls _read_group_raw which then goes to call _read_group_prepare, which will return order by terms in this manner ['id asc', 'x_Test desc'] the problem with this is that postgres automatically converts non-quoted/non-qualified column name to lowercase, of course this means that if we have a field "x_Test" but no field "x_test", it will try to look up "x_test" instead of "x_Test" and since the column doesn't exist, it will throw a ProgrammingError. This commit changes this behavior by wrapping the order_by terms generated in _read_group_prepare with double quotes, which postgres interprets correctly. Fixes #21348 Cherry-Pick of c338e24ee7589c2f4c0d71595262cee58435416b as previous forward-port has been badly done... --- odoo/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/odoo/models.py b/odoo/models.py index b37fa0fe530..611b2bdbff3 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -1752,7 +1752,8 @@ class BaseModel(object): order = '"%s" %s' % (order_field, '' if len(order_split) == 1 else order_split[1]) orderby_terms.append(order) elif order_field in aggregated_fields: - orderby_terms.append(order_part) + order_split[0] = '"' + order_field + '"' + orderby_terms.append(' '.join(order_split)) else: # Cannot order by a field that will not appear in the results (needs to be grouped or aggregated) _logger.warn('%s: read_group order by `%s` ignored, cannot sort on empty columns (not grouped/aggregated)',