From 6da8103d228904401b346be8b580a2c7756b5b83 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Sat, 24 Jan 2015 22:08:30 +0100 Subject: [PATCH] Re-activate the code to auto-create journal, but needs a special key in context --- .../account_bank_statement_import.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/account_bank_statement_import/account_bank_statement_import.py b/account_bank_statement_import/account_bank_statement_import.py index ab53f2b5..3b997d60 100644 --- a/account_bank_statement_import/account_bank_statement_import.py +++ b/account_bank_statement_import/account_bank_statement_import.py @@ -133,6 +133,8 @@ class account_bank_statement_import(osv.TransientModel): def _get_journal(self, cr, uid, currency_id, bank_account_id, account_number, context=None): """ Find or create the journal """ + if context is None: + context = {} bank_pool = self.pool.get('res.partner.bank') # Find the journal from context or bank account @@ -155,11 +157,11 @@ class account_bank_statement_import(osv.TransientModel): raise Warning(_('The currency of the bank statement is not the same as the currency of the journal !')) # If there is no journal, create one (and its account) - # I think it's too dangerous, so I disable that code -- Alexis de Lattre - #if not journal_id and account_number: - # journal_id = self._create_journal(cr, uid, currency_id, account_number, context=context) - # if bank_account_id: - # bank_pool.write(cr, uid, [bank_account_id], {'journal_id': journal_id}, context=context) + # I think it's too dangerous, so I disable that code by default -- Alexis de Lattre + if context.get('allow_auto_create_journal') and not journal_id and account_number: + journal_id = self._create_journal(cr, uid, currency_id, account_number, context=context) + if bank_account_id: + bank_pool.write(cr, uid, [bank_account_id], {'journal_id': journal_id}, context=context) # If we couldn't find/create a journal, everything is lost if not journal_id: