Merge lp:~jfb-tempo-consulting/unifield-server/US-8276 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merged at revision: 5977
Proposed branch: lp:~jfb-tempo-consulting/unifield-server/US-8276
Merge into: lp:unifield-server
Diff against target: 98 lines (+19/-4)
3 files modified
bin/addons/product/product.py (+2/-1)
bin/osv/orm.py (+16/-3)
bin/osv/query.py (+1/-0)
To merge this branch: bzr merge lp:~jfb-tempo-consulting/unifield-server/US-8276
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+401174@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/addons/product/product.py'
2--- bin/addons/product/product.py 2020-08-11 12:55:22 +0000
3+++ bin/addons/product/product.py 2021-04-15 08:08:23 +0000
4@@ -470,7 +470,8 @@
5 ret.joins['"product_product"'] = [('"stock_mission_report_line_location"', 'id', 'product_id', 'LEFT JOIN')]
6 ret.where_clause.append(' "stock_mission_report_line_location"."remote_instance_id" is NULL AND "stock_mission_report_line_location"."location_id" in %s ')
7 ret.where_clause_params.append(tuple(location_ids))
8- ret.having = ' GROUP BY "product_product"."id" HAVING sum("stock_mission_report_line_location"."quantity") >0 '
9+ ret.having_group_by = ' GROUP BY "product_product"."id" '
10+ ret.having = ' HAVING sum("stock_mission_report_line_location"."quantity") >0 '
11 if filter_in_any_product_list:
12 ret.tables.append('"product_list_line"')
13 ret.joins['"product_product"'] = [('"product_list_line"', 'id', 'name', 'INNER JOIN')]
14
15=== modified file 'bin/osv/orm.py'
16--- bin/osv/orm.py 2021-02-02 10:20:51 +0000
17+++ bin/osv/orm.py 2021-04-15 08:08:23 +0000
18@@ -4842,6 +4842,7 @@
19 translation = 0
20 if order_spec:
21 order_by_elements = []
22+ order_by_elements_nodir = []
23 self._check_qorder(order_spec)
24 for order_part in order_spec.split(','):
25 translatable = False
26@@ -4890,6 +4891,8 @@
27 trans_name = '"ir_translation%s"' % translation
28 init_field = '"%s"."%s"' % (self._table, order_field)
29 order_by_elements.append('COALESCE(%s."value", %s) %s' % (trans_name, init_field, order_direction))
30+ if query.having:
31+ order_by_elements_nodir.append('COALESCE(%s."value", %s)' % (trans_name, init_field))
32 left_join_clause = 'LEFT JOIN "ir_translation" %s' % trans_name
33 on_clause = 'ON %s.res_id = "%s".id AND %s.name = \'%s,%s\' AND %s.type = \'model\' AND %s.lang = \'%s\'' % (
34 trans_name, trans_table, trans_name, trans_obj_name, order_field, trans_name, trans_name, context.get('lang', 'en_US'))
35@@ -4905,6 +4908,8 @@
36
37 init_field = self._inherits_join_calc(order_field, query)
38 order_by_elements.append('COALESCE(%s."value", %s) %s' % (trans_name, init_field, order_direction))
39+ if query.having:
40+ order_by_elements_nodir.append('COALESCE(%s."value", %s)' % (trans_name, init_field))
41 left_join_clause = 'LEFT JOIN "ir_translation" %s' % trans_name
42 on_clause = 'ON %s.res_id = "%s".id AND %s.name = \'%s,%s\' AND %s.type = \'model\' AND %s.lang = \'%s\'' % (
43 trans_name, parent_obj._table, trans_name, parent_obj._name, order_field, trans_name, trans_name, context.get('lang', 'en_US'))
44@@ -4924,11 +4929,18 @@
45 if isinstance(end_inner_clause, list):
46 for clause in end_inner_clause:
47 order_by_elements.append("%s %s" % (clause, order_direction))
48+ if query.having:
49+ order_by_elements_nodir.append(clause)
50 else:
51 order_by_elements.append("%s %s" % (end_inner_clause, order_direction))
52+ if query.having:
53+ order_by_elements_nodir.append(end_inner_clause)
54 if order_by_elements:
55 order_by_clause = ",".join(order_by_elements)
56
57+ if order_by_elements_nodir:
58+ query.having_group_by = '%s, %s' % (query.having_group_by, ','.join(order_by_elements_nodir))
59+
60 return order_by_clause and (' ORDER BY %s ' % order_by_clause) or '', from_order_clause
61
62 def _search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False, access_rights_uid=None):
63@@ -4947,7 +4959,7 @@
64
65 query = self._where_calc(cr, user, args, context=context)
66 self._apply_ir_rules(cr, user, query, 'read', context=context)
67- if order == 'NO_ORDER':
68+ if order == 'NO_ORDER' or count:
69 order_by=''
70 from_order_clause = []
71 else:
72@@ -4970,11 +4982,12 @@
73 return res[0][0]
74 else:
75 count_query = ''.join(('SELECT "%s".id FROM ' % self._table,
76- from_clause, where_str, query.having, limit_str, offset_str))
77+ from_clause, where_str, query.having_group_by, query.having, limit_str, offset_str))
78 cr.execute(count_query, where_clause_params)
79 return cr.rowcount
80+
81 select_query = ''.join(('SELECT "%s".id FROM ' % self._table,
82- from_clause, where_str, query.having, order_by,limit_str, offset_str))
83+ from_clause, where_str, query.having_group_by, query.having, order_by,limit_str, offset_str))
84 cr.execute(select_query, where_clause_params)
85 res = cr.fetchall()
86 return [x[0] for x in res]
87
88=== modified file 'bin/osv/query.py'
89--- bin/osv/query.py 2020-06-08 14:18:17 +0000
90+++ bin/osv/query.py 2021-04-15 08:08:23 +0000
91@@ -53,6 +53,7 @@
92 self.where_clause_params = where_clause_params or []
93
94 self.having = ''
95+ self.having_group_by = ''
96 # holds table joins done explicitly, supporting outer joins. The JOIN
97 # condition should not be in `where_clause`. The dict is used as follows:
98 # self.joins = {

Subscribers

People subscribed via source and target branches