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

Proposed by jftempo
Status: Merged
Merged at revision: 6140
Proposed branch: lp:~jfb-tempo-consulting/unifield-server/US-9456
Merge into: lp:unifield-server
Diff against target: 177 lines (+52/-8)
5 files modified
bin/addons/account/account_move_line.py (+3/-1)
bin/addons/account_override/account_move_line.py (+3/-2)
bin/osv/expression.py (+26/-2)
bin/osv/fields.py (+4/-0)
bin/osv/orm.py (+16/-3)
To merge this branch: bzr merge lp:~jfb-tempo-consulting/unifield-server/US-9456
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+413681@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/account/account_move_line.py'
2--- bin/addons/account/account_move_line.py 2021-07-07 16:30:21 +0000
3+++ bin/addons/account/account_move_line.py 2022-01-05 14:32:14 +0000
4@@ -632,7 +632,6 @@
5 'debit_currency': 0.0,
6 'credit_currency': 0.0,
7 }
8- _order = "date desc, id desc"
9 _sql_constraints = [
10 ('credit_debit1', 'CHECK (credit*debit=0)', 'Wrong credit or debit value in accounting entry !'),
11 ('credit_debit2', 'CHECK (credit+debit>=0)', 'Wrong credit or debit value in accounting entry !'),
12@@ -645,6 +644,9 @@
13 cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = \'account_move_line_journal_id_period_id_index\'')
14 if not cr.fetchone():
15 cr.execute('CREATE INDEX account_move_line_journal_id_period_id_index ON account_move_line (journal_id, period_id)')
16+ cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = \'account_move_line_move_id_id_index\'')
17+ if not cr.fetchone():
18+ cr.execute('CREATE INDEX account_move_line_move_id_id_index ON account_move_line (move_id DESC, id)')
19 return ret
20
21 def _check_no_view(self, cr, uid, ids, context=None):
22
23=== modified file 'bin/addons/account_override/account_move_line.py'
24--- bin/addons/account_override/account_move_line.py 2021-08-26 11:43:10 +0000
25+++ bin/addons/account_override/account_move_line.py 2022-01-05 14:32:14 +0000
26@@ -309,7 +309,7 @@
27 help="This indicates the state of the Journal Entry."),
28 'is_addendum_line': fields.boolean('Is an addendum line?', readonly=True,
29 help="This inform account_reconciliation module that this line is an addendum line for reconciliations."),
30- 'move_id': fields.many2one('account.move', 'Entry Sequence', ondelete="cascade", help="The move of this entry line.", select=2, required=True, readonly=True),
31+ 'move_id': fields.many2one('account.move', 'Entry Sequence', ondelete="cascade", help="The move of this entry line.", select=2, required=True, readonly=True, join=True),
32 'name': fields.char('Description', size=64, required=True, readonly=True),
33 'journal_id': fields.many2one('account.journal', 'Journal Code', required=True, select=1),
34 'debit': fields.float('Func. Debit', digits_compute=dp.get_precision('Account')),
35@@ -374,7 +374,8 @@
36 'is_si_refund': lambda *a: False,
37 }
38
39- _order = 'move_id DESC'
40+ _order = 'move_id DESC, id'
41+ # see account_move_line_move_id_id_index on account_move_line
42
43 def default_get(self, cr, uid, fields, context=None, from_web=False):
44 """
45
46=== modified file 'bin/osv/expression.py'
47--- bin/osv/expression.py 2021-08-09 18:09:28 +0000
48+++ bin/osv/expression.py 2022-01-05 14:32:14 +0000
49@@ -121,7 +121,26 @@
50 working_table = table
51 main_table = table
52 fargs = left.split('.', 1)
53- if fargs[0] in table._inherit_fields:
54+ inherited_fields = fargs[0] in table._inherit_fields
55+
56+ if not inherited_fields and len(fargs) > 1:
57+ # check if m2o fields can be sql joined
58+ field = working_table._columns.get(fargs[0], False)
59+ if field and field._type == 'many2one' and field._obj and field._join:
60+ new_working_table = working_table.pool.get(field._obj)
61+ if new_working_table not in self.__all_tables:
62+ self.__joins.append('%s.%s=%s.%s' % (new_working_table._table, 'id', main_table._table, fargs[0]))
63+ self.__all_tables.append(new_working_table)
64+ working_table = new_working_table
65+ self.__field_tables[i] = working_table
66+ left = fargs[1]
67+ fargs = left.split('.', 1)
68+ self.__exp[i] = (left, operator, right)
69+ inherited_fields = fargs[0] in working_table._inherit_fields
70+ if inherited_fields:
71+ main_table = working_table
72+
73+ if inherited_fields:
74 while True:
75 field = main_table._columns.get(fargs[0], False)
76 if field:
77@@ -142,6 +161,7 @@
78 continue
79
80 field_obj = table.pool.get(field._obj)
81+
82 if len(fargs) > 1:
83 if field._type == 'many2one':
84 right = field_obj.search(cr, uid, [(fargs[1], operator,
85@@ -171,7 +191,7 @@
86 # values in the database, so we must ignore it : we generate a dummy leaf
87 self.__exp[i] = self.__DUMMY_LEAF
88 else:
89- subexp = field.search(cr, uid, table, left, [self.__exp[i]], context=context)
90+ subexp = field.search(cr, uid, working_table, left, [self.__exp[i]], context=context)
91 if not subexp:
92 self.__exp[i] = self.__DUMMY_LEAF
93 else:
94@@ -181,6 +201,10 @@
95 self.__exp.insert(i + 1, self.__DUMMY_LEAF)
96 for j, se in enumerate(subexp):
97 self.__exp.insert(i + 2 + j, se)
98+ if self.__field_tables.get(i+j):
99+ # replace joined table
100+ self.__field_tables[i+2+j] = self.__field_tables[i+j]
101+ del self.__field_tables[i+j]
102 # else, the value of the field is store in the database, so we search on it
103
104 elif field._type == 'one2many':
105
106=== modified file 'bin/osv/fields.py'
107--- bin/osv/fields.py 2021-04-08 13:15:31 +0000
108+++ bin/osv/fields.py 2022-01-05 14:32:14 +0000
109@@ -59,6 +59,7 @@
110 _symbol_f = _symbol_set
111 _symbol_set = (_symbol_c, _symbol_f)
112 _symbol_get = None
113+ _join = False
114
115 def __init__(self, string='unknown', required=False, readonly=False,
116 domain=None, context=None, states=None, priority=0,
117@@ -376,6 +377,9 @@
118 def __init__(self, obj, string='unknown', **args):
119 _column.__init__(self, string=string, **args)
120 self._obj = obj
121+ self._join = args.get('join', False)
122+ if self._join and not self.required:
123+ raise Exception('join fields must be required')
124
125 def set_memory(self, cr, obj, id, field, values, user=None, context=None):
126 obj.datas.setdefault(id, {})
127
128=== modified file 'bin/osv/orm.py'
129--- bin/osv/orm.py 2021-10-20 13:51:35 +0000
130+++ bin/osv/orm.py 2022-01-05 14:32:14 +0000
131@@ -1015,7 +1015,6 @@
132 else:
133 while pos < len(datas):
134 res2 = process_liness(self, datas, prefix + [field[len(prefix)]], current_module, relation_obj._name, newfd, pos, first)
135- print res2
136 if not res2:
137 break
138 (newrow, pos, w2, data_res_id2, xml_id2) = res2
139@@ -2069,7 +2068,9 @@
140 or approximate.
141 :return: (count, boolean) boolean is True in case of approximation
142 """
143- if not args:
144+ if not args or \
145+ (self._table in ['account_move_line', 'account_move'] and args in ([('period_id.number', '!=', 0)], [('period_id.number', '!=', 0), ('move_id.state', '=', 'posted')])) or \
146+ (self._table == 'account_analytic_line' and args == [('account_id.category', '=', 'FUNDING')]):
147 cr.execute("""
148 SELECT reltuples::BIGINT AS approximate_row_count
149 FROM pg_class WHERE relname = '%s'
150@@ -2078,7 +2079,15 @@
151 approximative_result = approximative_result and approximative_result[0][0] or 0
152 # check if approximative is big
153 if approximative_result > 100000:
154- return int(approximative_result), True
155+ exclude = 0
156+ if self._table in ['account_move_line', 'account_move']:
157+ exclude = self.search_count(cr, user, [('period_id.number', '=', 0)], context={'show_period_0': 1})
158+ if self._table == 'account_move_line' and args == [('period_id.number', '!=', 0), ('move_id.state', '=', 'posted')]:
159+ exclude += self.search_count(cr, user, [('move_id.state', '=', 'draft')], context=context)
160+ if self._table == 'account_analytic_line':
161+ exclude = self.search_count(cr, user, [('account_id.category', '!=', 'FUNDING')], context=context)
162+ print exclude
163+ return int(approximative_result) - exclude, True
164 return self.search_count(cr, user, args, context=context), False
165
166
167@@ -4839,6 +4848,10 @@
168 for order_part in m2o_order.split(","):
169 m2o_order_list.append(order_part.strip().split(" ",1)[0].strip())
170 m2o_order = m2o_order_list
171+ if m2o_order == ['id']:
172+ # default order on m2o table is "id", not need to join table
173+ return qualified_field
174+
175
176 # Join the dest m2o table if it's not joined yet. We use [LEFT] OUTER join here
177 # as we don't want to exclude results that have NULL values for the m2o

Subscribers

People subscribed via source and target branches