--- old/account/wizard/wizard_fiscalyear_close.py 2010-01-13 16:30:28 +0000 +++ new/account/wizard/wizard_fiscalyear_close.py 2010-03-29 11:31:48 +0000 @@ -56,14 +56,15 @@ pool = pooler.get_pool(cr.dbname) fy_id = data['form']['fy_id'] - period_ids = pool.get('account.period').search(cr, uid, [('fiscalyear_id', '=', fy_id)]) - fy_period_set = ','.join(map(str, period_ids)) - periods_fy2 = pool.get('account.period').search(cr, uid, [('fiscalyear_id', '=', data['form']['fy2_id'])]) - fy2_period_set = ','.join(map(str, periods_fy2)) + fy2_id = data['form']['fy2_id'] + cr.execute("SELECT id FROM account_period WHERE date_stop < (SELECT date_start FROM account_fiscalyear WHERE id = " + str(fy2_id) + ")") + fy_period_set = ','.join(map(lambda id: str(id[0]), cr.fetchall())) + cr.execute("SELECT id FROM account_period WHERE date_start > (SELECT date_stop FROM account_fiscalyear WHERE id = " + str(fy_id) + ")") + fy2_period_set = ','.join(map(lambda id: str(id[0]), cr.fetchall())) period = pool.get('account.period').browse(cr, uid, data['form']['period_id'], context=context) - new_fyear = pool.get('account.fiscalyear').browse(cr, uid, data['form']['fy2_id'], context=context) - old_fyear = pool.get('account.fiscalyear').browse(cr, uid, data['form']['fy_id'], context=context) + new_fyear = pool.get('account.fiscalyear').browse(cr, uid, fy2_id, context=context) + old_fyear = pool.get('account.fiscalyear').browse(cr, uid, fy_id, context=context) new_journal = data['form']['journal_id'] new_journal = pool.get('account.journal').browse(cr, uid, new_journal, context=context) @@ -141,9 +142,7 @@ offset = 0 limit = 100 while True: - #TODO: this query could be improved in order to work if there is more than 2 open FY - # a.period_id IN ('+fy2_period_set+') is the problematic clause - cr.execute('SELECT b.id, b.name, b.quantity, b.debit, b.credit, b.account_id, b.ref, ' \ + cr.execute('SELECT DISTINCT b.id, b.name, b.quantity, b.debit, b.credit, b.account_id, b.ref, ' \ 'b.amount_currency, b.currency_id, b.blocked, b.partner_id, ' \ 'b.date_maturity, b.date_created ' \ 'FROM account_move_line a, account_move_line b ' \