From b1d692a544dc8ff5e534c1ffb70706e93d933f25 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Fri, 13 Jan 2012 14:22:14 +0100 Subject: [PATCH] [FIX] do not try to select rows in the database by float value [FIX] split up transaction is not preserved in matching process [FIX] workaround for lp:915975 writing fields.related of type 'many2many' --- account_banking/__openerp__.py | 4 +- account_banking/bank_import_transaction.py | 43 +++++++++++++------ .../wizard/banking_transaction_wizard.py | 32 +++++++++++++- 3 files changed, 62 insertions(+), 17 deletions(-) diff --git a/account_banking/__openerp__.py b/account_banking/__openerp__.py index 4f04b177e..3c7eeb863 100644 --- a/account_banking/__openerp__.py +++ b/account_banking/__openerp__.py @@ -4,7 +4,7 @@ # (C) 2011 Therp BV (). # (C) 2011 Smile (). # -# All other contributions are (C) by their own contributors +# All other contributions are (C) by their respective contributors # # All Rights Reserved # @@ -30,7 +30,7 @@ ############################################################################## { 'name': 'Account Banking', - 'version': '0.1.99', + 'version': '0.1.100', 'license': 'GPL-3', 'author': 'Banking addons community', 'website': 'https://launchpad.net/banking-addons', diff --git a/account_banking/bank_import_transaction.py b/account_banking/bank_import_transaction.py index 9fca9a492..442edb2b2 100644 --- a/account_banking/bank_import_transaction.py +++ b/account_banking/bank_import_transaction.py @@ -52,11 +52,6 @@ class banking_import_transaction(osv.osv): _description = 'Bank import transaction' _rec_name = 'transaction' - signal_duplicate_keys = [ - 'execution_date', 'local_account', 'remote_account', - 'remote_owner', 'reference', 'message', 'transferred_amount' - ] - payment_window = datetime.timedelta(days=10) def _match_costs(self, cr, uid, trans, period_id, account_info, log): @@ -200,7 +195,9 @@ class banking_import_transaction(osv.osv): TODO: REVISE THIS DOC #Return values: - #move_info: the move_line information belonging to the matched + # old_trans: this function can modify and rebrowse the modified + # transaction. + # move_info: the move_line information belonging to the matched # invoice # new_trans: the new transaction when the current one was split. # This can happen when multiple invoices were paid with a single @@ -361,7 +358,7 @@ class banking_import_transaction(osv.osv): else: # Multiple matches # TODO select best bank account in this case - return (self._get_move_info( + return (trans, self._get_move_info( cr, uid, [x.id for x in candidates]), False) move_line = False @@ -408,19 +405,19 @@ class banking_import_transaction(osv.osv): transaction = trans.transaction + 'a', ), context) # rebrowse the current record after writing - trans=self.browse(cr, uid, trans.id, context=context) + trans = self.browse(cr, uid, trans.id, context=context) if move_line: account_ids = [ x.id for x in bank_account_ids if x.partner_id.id == move_line.partner_id.id ] - return (self._get_move_info( + return (trans, self._get_move_info( cr, uid, [move_line.id], account_ids and account_ids[0] or False), trans2) - return (False, False) + return trans, False, False def _do_move_reconcile( self, cr, uid, move_line_ids, currency, amount, context=None): @@ -782,6 +779,7 @@ class banking_import_transaction(osv.osv): self.pool.get('account.bank.statement.line').write( cr, uid, transaction.statement_line_id.id, {'reconcile_id': reconcile_id}, context=context) + # TODO # update the statement line bank account reference # as follows (from _match_invoice) @@ -912,6 +910,13 @@ class banking_import_transaction(osv.osv): return False + signal_duplicate_keys = [ + # does not include float values + # such as transferred_amount + 'execution_date', 'local_account', 'remote_account', + 'remote_owner', 'reference', 'message', + ] + def create(self, cr, uid, vals, context=None): res = super(banking_import_transaction, self).create( cr, uid, vals, context) @@ -920,10 +925,20 @@ class banking_import_transaction(osv.osv): search_vals = [(key, '=', me[key]) for key in self.signal_duplicate_keys] ids = self.search(cr, uid, search_vals, context=context) - if len(ids) < 1: + dupes = [] + # Test for transferred_amount seperately + # due to float representation and rounding difficulties + for trans in self.browse(cr, uid, ids, context=context): + if self.pool.get('res.currency').is_zero( + cr, uid, + trans.statement_id.currency, + me['transferred_amount'] - trans.transferred_amount): + dupes.append(trans.id) + if len(dupes) < 1: raise osv.except_osv(_('Cannot check for duplicate'), - _("I can't find myself...")) - if len(ids) > 1: + _("Cannot check for duplicate. " + "I can't find myself.")) + if len(dupes) > 1: self.write( cr, uid, res, {'duplicate': True}, context=context) return res @@ -1288,7 +1303,7 @@ class banking_import_transaction(osv.osv): # invoice, automatic invoicing on bank costs will create # these, and invoice matching still has to be done. - move_info, remainder = self._match_invoice( + transaction, move_info, remainder = self._match_invoice( cr, uid, transaction, move_lines, partner_ids, partner_banks, results['log'], linked_invoices, context=context) diff --git a/account_banking/wizard/banking_transaction_wizard.py b/account_banking/wizard/banking_transaction_wizard.py index cdf890153..a50039ec8 100644 --- a/account_banking/wizard/banking_transaction_wizard.py +++ b/account_banking/wizard/banking_transaction_wizard.py @@ -81,8 +81,38 @@ class banking_transaction_wizard(osv.osv_memory): manual_invoice_id = vals.pop('manual_invoice_id', False) manual_move_line_id = vals.pop('manual_move_line_id', False) + # Support for writing fields.related is still flakey: + # https://bugs.launchpad.net/openobject-server/+bug/915975 + # Will do so myself. + + if not vals: + return True + + # Separate the related fields + transaction_vals = {} + wizard_vals = vals.copy() + for key in vals.keys(): + field = self._columns[key] + if (isinstance(field, fields.related) and + field._arg[0] == 'import_transaction_id'): + transaction_vals[field._arg[1]] = vals[key] + del wizard_vals[key] + + # write the related fields on the transaction model + for wizard in self.read( + cr, uid, ids, ['import_transaction_id'], context=context): + if wizard['import_transaction_id']: + transaction_obj.write( + cr, uid, wizard['import_transaction_id'][0], + transaction_vals, context=context) + + # write other fields to the wizard model res = super(banking_transaction_wizard, self).write( - cr, uid, ids, vals, context=context) + cr, uid, ids, wizard_vals, context=context) + + # End of workaround for lp:915975 + + """ Process the logic of the written values """ # An invoice is selected from multiple candidates if vals and 'invoice_id' in vals: