diff --git a/account_banking/account_banking.py b/account_banking/account_banking.py index ed1b1e495..039e8e062 100644 --- a/account_banking/account_banking.py +++ b/account_banking/account_banking.py @@ -410,13 +410,19 @@ class account_bank_statement(osv.osv): 'account.bank.statement.line') st_line = account_bank_statement_line_obj.browse( cr, uid, st_line_id, context=context) + period_id = self._get_period( + cr, uid, st_line.date, context=context) # AB # Start account voucher # Post the voucher and update links between statement and moves if st_line.voucher_id: voucher_pool = self.pool.get('account.voucher') wf_service = netsvc.LocalService("workflow") voucher_pool.write( - cr, uid, [st_line.voucher_id.id], {'number': st_line_number}, context=context) + cr, uid, [st_line.voucher_id.id], { + 'number': st_line_number, + 'date': st_line.date, + 'period_id': period_id, # AB + }, context=context) if st_line.voucher_id.state == 'cancel': voucher_pool.action_cancel_draft( cr, uid, [st_line.voucher_id.id], context=context) @@ -443,8 +449,6 @@ class account_bank_statement(osv.osv): context.update({'date': st_line.date}) ctxt = context.copy() # AB ctxt['company_id'] = st_line.company_id.id # AB - period_id = self._get_period( - cr, uid, st_line.date, context=ctxt) # AB move_id = account_move_obj.create(cr, uid, { 'journal_id': st.journal_id.id, diff --git a/account_banking/banking_import_transaction.py b/account_banking/banking_import_transaction.py index 330a0710d..45bbaa6b0 100644 --- a/account_banking/banking_import_transaction.py +++ b/account_banking/banking_import_transaction.py @@ -25,7 +25,6 @@ ############################################################################## from osv import osv, fields -import time import netsvc import base64 import datetime @@ -494,7 +493,7 @@ class banking_import_transaction(osv.osv): if from_curr_id != to_curr_id: amount_currency = statement_line_pool._convert_currency( cr, uid, from_curr_id, to_curr_id, move_line_amount, - round=True, date=time.strftime('%Y-%m-%d'), + round=True, date=transaction.move_line_id.date, context=context) else: amount_currency = move_line_amount @@ -606,7 +605,7 @@ class banking_import_transaction(osv.osv): payment_line_obj.write( cr, uid, transaction.payment_line_id.id, { 'export_state': 'done', - 'date_done': transaction.effective_date, + 'date_done': transaction.statement_line_id.date, } ) self._confirm_move(cr, uid, transaction_id, context=context) @@ -961,9 +960,14 @@ class banking_import_transaction(osv.osv): ] def create(self, cr, uid, vals, context=None): + """ + Search for duplicates of the newly created transaction + and mark them as such unless a context key + 'transaction_no_duplicate_search' is defined and true. + """ res = super(banking_import_transaction, self).create( cr, uid, vals, context) - if res: + if res and not context.get('transaction_no_duplicate_search'): me = self.browse(cr, uid, res, context) search_vals = [(key, '=', me[key]) for key in self.signal_duplicate_keys] @@ -1319,7 +1323,8 @@ class banking_import_transaction(osv.osv): transaction.remote_owner, transaction.remote_owner_address, transaction.remote_owner_city, - country_code, results['log'] + country_code, results['log'], + bic=transaction.remote_bank_bic ) partner_banks = partner_bank_obj.browse( cr, uid, [partner_bank_id] @@ -1556,11 +1561,19 @@ class banking_import_transaction(osv.osv): if transaction.move_line_id: move_line_amount = transaction.move_line_id.amount_residual_currency - to_curr_id = transaction.statement_id.journal_id.currency and transaction.statement_id.journal_id.currency.id or transaction.statement_line_id.statement_id.company_id.currency_id.id - from_curr_id = transaction.move_line_id.currency_id and transaction.move_line_id.currency_id.id or transaction.statement_id.company_id.currency_id.id + to_curr_id = ( + transaction.statement_line_id.statement_id.journal_id.currency + and transaction.statement_line_id.statement_id.journal_id.currency.id + or transaction.statement_line_id.statement_id.company_id.currency_id.id + ) + from_curr_id = ( + transaction.move_line_id.currency_id + and transaction.move_line_id.currency_id.id + or transaction.statement_line_id.statement_id.company_id.currency_id.id + ) if from_curr_id != to_curr_id: amount_currency = stline_pool._convert_currency(cr, uid, from_curr_id, to_curr_id, move_line_amount, round=True, - date=time.strftime('%Y-%m-%d'), context=context) + date=transaction.statement_line_id.date, context=context) else: amount_currency = move_line_amount sign = 1 @@ -1871,6 +1884,42 @@ class account_bank_statement_line(osv.osv): return super(account_bank_statement_line, self).unlink( cr, uid, ids, context=context) + def create_instant_transaction( + self, cr, uid, ids, context=None): + """ + Check for existance of import transaction on the + bank statement lines. Create instant items if appropriate. + + This way, the matching wizard works on manually + encoded statements. + + The transaction is only filled with the most basic + information. The use of the transaction at this point + is rather to store matching data rather than to + provide data about the transaction which have all been + transferred to the bank statement line. + """ + import_transaction_pool = self.pool.get('banking.import.transaction') + if ids and isinstance(ids, (int, long)): + ids = [ids] + if context is None: + context = {} + localcontext = context.copy() + localcontext['transaction_no_duplicate_search'] = True + for line in self.browse( + cr, uid, ids, context=context): + if line.state != 'confirmed' and not line.import_transaction_id: + res = import_transaction_pool.create( + cr, uid, { + 'company_id': line.statement_id.company_id.id, + 'statement_line_id': line.id, + }, + context=localcontext) + self.write( + cr, uid, line.id, { + 'import_transaction_id': res}, + context=context) + account_bank_statement_line() class account_bank_statement(osv.osv): @@ -1919,6 +1968,7 @@ class account_bank_statement(osv.osv): _('The account entries lines are not in valid state.')) line_obj.confirm(cr, uid, [line.id for line in st.line_ids], context) + st.refresh() self.log(cr, uid, st.id, _('Statement %s is confirmed, journal ' 'items are created.') % (st.name,)) return self.write(cr, uid, ids, {'state':'confirm'}, context=context) diff --git a/account_banking/wizard/account_payment_order.py b/account_banking/wizard/account_payment_order.py index 686c8bdfe..f85b556ba 100644 --- a/account_banking/wizard/account_payment_order.py +++ b/account_banking/wizard/account_payment_order.py @@ -112,7 +112,7 @@ class payment_order_create(osv.osv_memory): 'state': state, ### end account banking 'date': date_to_pay, - 'currency': line.invoice and line.invoice.currency_id.id or False, + 'currency': line.invoice and line.invoice.currency_id.id or line.journal_id.currency.id or line.journal_id.company_id.currency_id.id, }, context=context) return {'type': 'ir.actions.act_window_close'} diff --git a/account_banking/wizard/bank_import.py b/account_banking/wizard/bank_import.py index 6e2139341..9dc222272 100644 --- a/account_banking/wizard/bank_import.py +++ b/account_banking/wizard/bank_import.py @@ -263,6 +263,16 @@ class banking_import(osv.osv_memory): ('date_stop','>=',statement.date), ('special', '=', False)]) + if not period_ids: + results.log.append( + _('No period found covering statement date %(date)s, ' + 'statement %(id)s skipped') % { + 'date': statement.date, + 'id': statement.id, + } + ) + continue + # Create the bank statement record statement_id = statement_obj.create(cursor, uid, dict( name = statement.id, diff --git a/account_banking/wizard/banking_transaction_wizard.py b/account_banking/wizard/banking_transaction_wizard.py index 8171cb776..53d2158d3 100644 --- a/account_banking/wizard/banking_transaction_wizard.py +++ b/account_banking/wizard/banking_transaction_wizard.py @@ -35,6 +35,18 @@ class banking_transaction_wizard(osv.osv_memory): _name = 'banking.transaction.wizard' _description = 'Match transaction' + def create(self, cr, uid, vals, context=None): + """ + Make sure that the statement line has an import transaction + """ + res = super(banking_transaction_wizard, self).create( + cr, uid, vals, context=context) + if res and vals.get('statement_line_id'): + line_pool = self.pool.get('account.bank.statement.line') + line_pool.create_instant_transaction( + cr, uid, vals['statement_line_id'], context=context) + return res + def create_act_window(self, cr, uid, ids, nodestroy=True, context=None): """ Return a popup window for this model diff --git a/account_banking/wizard/banking_transaction_wizard.xml b/account_banking/wizard/banking_transaction_wizard.xml index 59a697570..1d76fd29c 100644 --- a/account_banking/wizard/banking_transaction_wizard.xml +++ b/account_banking/wizard/banking_transaction_wizard.xml @@ -93,7 +93,21 @@ - + +