aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
wheres = [""]
- if query:
+ if query.strip():
wheres.append(query.strip())
- if aml_query:
+ if aml_query.strip():
wheres.append(aml_query.strip())
- query = " AND ".join(wheres)
-
- cr.execute(("SELECT l.account_id as id, " +\
- ' , '.join(map(lambda x: mapping[x], field_names)) +
- "FROM " \
- "account_move_line l " \
- "WHERE " \
- "l.account_id IN (%s) " \
- + query +
- " GROUP BY l.account_id") % (acc_set, ))
+ filters = " AND ".join(wheres)
+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
+ 'Filters: %s'%filters)
+ # IN might not work ideally in case there are too many
+ # children_and_consolidated, in that case join on a
+ # values() e.g.:
+ # SELECT l.account_id as id FROM account_move_line l
+ # INNER JOIN (VALUES (id1), (id2), (id3), ...) AS tmp (id)
+ # ON l.account_id = tmp.id
+ # or make _get_children_and_consol return a query and join on that
+ request = ("SELECT l.account_id as id, " +\
+ ' , '.join(map(mapping.__getitem__, field_names)) +
+ " FROM account_move_line l" \
+ " WHERE l.account_id IN %s " \
+ + filters +
+ " GROUP BY l.account_id")
+ params = (tuple(children_and_consolidated),) + query_params
+ cr.execute(request, params)
+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
+ 'Status: %s'%cr.statusmessage)
for res in cr.dictfetchall():
accounts[res['id']] = res
-
# consolidate accounts with direct children
- brs = list(self.browse(cr, uid, children_and_consolidated,
- context=context))
+ ids2.reverse()
+ brs = list(self.browse(cr, uid, ids2, context=context))
sums = {}
while brs:
current = brs[0]
if new_name:
self.write(cr, uid, [move.id], {'name':new_name})
- cr.execute('update account_move set state=%s where id in ('+','.join(map(str,ids))+')', ('posted',))
+ cr.execute('UPDATE account_move '\
+ 'SET state=%s '\
+ 'WHERE id IN %s',
+ ('posted', tuple(ids)))
else:
- raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non-balanced entry !'))
+ raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non-balanced entry !\nMake sure you have configured Payment Term properly !\nIt should contain atleast one Payment Term Line with type "Balance" !'))
return True
def button_validate(self, cursor, user, ids, context=None):
'sign': lambda *args: 1.0,
'notprintable': lambda *a: False,
}
- def _check_recursion(self, cr, uid, ids):
- level = 100
- while len(ids):
- cr.execute('select distinct parent_id from account_tax_code where id in ('+','.join(map(str,ids))+')')
- ids = filter(None, map(lambda x:x[0], cr.fetchall()))
- if not level:
- return False
- level -= 1
- return True
+
+ def copy(self, cr, uid, id, default=None, context=None):
+ if default is None:
+ default = {}
+ default = default.copy()
+ default.update({'line_ids': []})
+ return super(account_tax_code, self).copy(cr, uid, id, default, context)
-
++
+ _check_recursion = check_cycle
++
_constraints = [
(_check_recursion, 'Error ! You can not create recursive accounts.', ['parent_id'])
]