diff --git a/addons/account/wizard/wizard_statement_from_invoice.py b/addons/account/wizard/wizard_statement_from_invoice.py index b32d4933ad6..351e7197546 100644 --- a/addons/account/wizard/wizard_statement_from_invoice.py +++ b/addons/account/wizard/wizard_statement_from_invoice.py @@ -40,26 +40,49 @@ FIELDS = { START_FIELD = { 'date': {'string': 'Date payment', 'type': 'date','required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')}, - + 'journal_id': {'string': 'Journal', 'type': 'many2many', 'relation': 'account.journal', 'domain': '[("type","in",["sale","purchase"])]', 'help': 'This field allow you to choose the accounting journals you want for filtering the invoices. If you left this field empty, it will search on all sale and purchase journals.'}, } + START_FORM = '''
''' -def _search_customer_invoices(obj, cursor, user, data, context): - pool = pooler.get_pool(cursor.dbname) +def _search_invoices(obj, cr, uid, data, context): + pool = pooler.get_pool(cr.dbname) line_obj = pool.get('account.move.line') statement_obj = pool.get('account.bank.statement') + journal_obj = pool.get('account.journal') - statement = statement_obj.browse(cursor, user, data['id'], context=context) - line_ids = line_obj.search(cursor, user, [ + statement = statement_obj.browse(cr, uid, data['id'], context=context) + journal_ids = data['form']['journal_id'][0][2] + + if journal_ids == []: + sale_journal_ids = journal_obj.search(cr, uid, [('type', '=', 'sale')], context=context) + pur_journal_ids = journal_obj.search(cr, uid, [('type', '=', 'purchase')], context=context) + else: + pur_journal_ids = sale_journal_ids = [] + for journal in pool.get('account.journal').browse(cr, uid, journal_ids): + if journal.type == 'sale': + sale_journal_ids.append(journal.id) + else: + pur_journal_ids.append(journal.id) + + line_ids = line_obj.search(cr, uid, [ ('reconcile_id', '=', False), + ('journal_id', 'in', sale_journal_ids), ('account_id.type', '=', 'receivable')], #order='date DESC, id DESC', #doesn't work context=context) - + line_ids += line_obj.search(cr, uid, [ + ('reconcile_id', '=', False), + ('journal_id', 'in', pur_journal_ids), + ('account_id.type', '=', 'payable')], + #order='date DESC, id DESC', #doesn't work + context=context) + FORM.string = '''