← Back to team overview

banking-addons-team team mailing list archive

lp:~therp-nl/banking-addons/6.1-lp1066826-matching_wizard_on_manual_statements into lp:banking-addons

 

Stefan Rijnhart (Therp) has proposed merging lp:~therp-nl/banking-addons/6.1-lp1066826-matching_wizard_on_manual_statements into lp:banking-addons.

Requested reviews:
  Banking Addons Team (banking-addons-team)

For more details, see:
https://code.launchpad.net/~therp-nl/banking-addons/6.1-lp1066826-matching_wizard_on_manual_statements/+merge/137400
-- 
https://code.launchpad.net/~therp-nl/banking-addons/6.1-lp1066826-matching_wizard_on_manual_statements/+merge/137400
Your team Banking Addons Team is requested to review the proposed merge of lp:~therp-nl/banking-addons/6.1-lp1066826-matching_wizard_on_manual_statements into lp:banking-addons.
=== modified file 'account_banking/banking_import_transaction.py'
--- account_banking/banking_import_transaction.py	2012-05-07 11:38:26 +0000
+++ account_banking/banking_import_transaction.py	2012-12-01 18:34:22 +0000
@@ -606,7 +606,7 @@
         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 +961,14 @@
         ]
 
     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]
@@ -1556,8 +1561,16 @@
 
             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)
@@ -1871,6 +1884,40 @@
         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]
+        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):

=== modified file 'account_banking/wizard/banking_transaction_wizard.py'
--- account_banking/wizard/banking_transaction_wizard.py	2012-05-02 09:29:06 +0000
+++ account_banking/wizard/banking_transaction_wizard.py	2012-12-01 18:34:22 +0000
@@ -35,6 +35,18 @@
     _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


Follow ups