From 2d76b47316cd2135b2413a2c5c1a6b4ab5d02604 Mon Sep 17 00:00:00 2001 From: qdp Date: Wed, 21 Jan 2009 15:27:52 +0100 Subject: [PATCH] [IMP] improvement of import invoices on bank statement wizard. - cash journal are now allowed - search is done on account with reconcile = true bzr revid: qdp@tinyerp.com-20090121142752-zl7m2d0mwfa3r26h --- .../wizard/wizard_statement_from_invoice.py | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/addons/account/wizard/wizard_statement_from_invoice.py b/addons/account/wizard/wizard_statement_from_invoice.py index 351e7197546..892e35953a1 100644 --- a/addons/account/wizard/wizard_statement_from_invoice.py +++ b/addons/account/wizard/wizard_statement_from_invoice.py @@ -40,7 +40,7 @@ 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.'}, + 'journal_id': {'string': 'Journal', 'type': 'many2many', 'relation': 'account.journal', 'domain': '[("type","in",["sale","purchase","cash"])]', '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, purchase and cash journals.'}, } START_FORM = ''' @@ -60,26 +60,12 @@ def _search_invoices(obj, cr, uid, data, 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) - + journal_ids = journal_obj.search(cr, uid, [('type', 'in', ('sale','cash','purchase'))], context=context) + 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')], + ('journal_id', 'in', journal_ids), + ('account_id.reconcile', '=', True)], #order='date DESC, id DESC', #doesn't work context=context) @@ -88,8 +74,7 @@ def _search_invoices(obj, cr, uid, data, context): ''' % (','.join([str(x) for x in line_ids])) - return {'type':'customer'} - # return {'lines': line_ids,'type':'customer'} + return {} def _populate_statement(obj, cursor, user, data, context): line_ids = data['form']['lines'][0][2] @@ -124,10 +109,17 @@ def _populate_statement(obj, cursor, user, data, context): reconcile_id = statement_reconcile_obj.create(cursor, user, { 'line_ids': [(6, 0, [line.id])] }, context=context) + if line.journal_id.type == 'sale': + type = 'customer' + elif line.journal_id.type == 'purchase': + type = 'supplier' + else: + type = 'general' + statement_line_obj.create(cursor, user, { 'name': line.name or '?', 'amount': amount, - 'type': data['form']['type'], + 'type': type, 'partner_id': line.partner_id.id, 'account_id': line.account_id.id, 'statement_id': statement.id,