← Back to team overview

clearcorp team mailing list archive

[Branch ~banking-addons-team/banking-addons/6.1] Rev 145: [IMP] Create import transactions instantly on manually encoded statements

 

Merge authors:
  Stefan Rijnhart (Therp) (stefan-therp)
Related merge proposals:
  https://code.launchpad.net/~therp-nl/banking-addons/6.1-lp1066826-matching_wizard_on_manual_statements/+merge/137400
  proposed by: Stefan Rijnhart (Therp) (stefan-therp)
  review: Approve - Guewen Baconnier @ Camptocamp (gbaconnier-c2c)
------------------------------------------------------------
revno: 145 [merge]
author: Stefan Rijnhart <stefan@xxxxxxxx>
committer: Guewen Baconnier @ Camptocamp <guewen.baconnier@xxxxxxxxxxxxxx>
branch nick: banking-addons
timestamp: Tue 2012-12-18 15:39:00 +0100
message:
  [IMP] Create import transactions instantly on manually encoded statements
modified:
  account_banking/banking_import_transaction.py
  account_banking/wizard/banking_transaction_wizard.py


--
lp:banking-addons
https://code.launchpad.net/~banking-addons-team/banking-addons/6.1

Your team CLEARCORP development team is subscribed to branch lp:banking-addons.
To unsubscribe from this branch go to https://code.launchpad.net/~banking-addons-team/banking-addons/6.1/+edit-subscription
=== 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-10 09:32:39 +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,42 @@
         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):

=== 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:31:34 +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