← Back to team overview

banking-addons-team team mailing list archive

[Merge] lp:~camptocamp/banking-addons/bank-statement-reconcile-7.0-fix-1313689 into lp:banking-addons/bank-statement-reconcile-7.0

 

Yannick Vaucher @ Camptocamp has proposed merging lp:~camptocamp/banking-addons/bank-statement-reconcile-7.0-fix-1313689 into lp:banking-addons/bank-statement-reconcile-7.0.

Requested reviews:
  Laurent Mignon (Acsone) (lmi)
  Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c): code review, no tests
  Banking Addons Core Editors (banking-addons-team)

For more details, see:
https://code.launchpad.net/~camptocamp/banking-addons/bank-statement-reconcile-7.0-fix-1313689/+merge/218575

Few cleaning to complete fix for 1313689

 * The _insert_lines and _update_line method in *_base_completion/statement.py calls the symbol_f method to prorperly initiate the default value (e.g. integer default null value should be Null not False).

 * The mechanism that allow to have a null account_id in bank statement line has been move in *_base_completion, instead of *_base_import.
-- 
https://code.launchpad.net/~camptocamp/banking-addons/bank-statement-reconcile-7.0-fix-1313689/+merge/218575
Your team Banking Addons Core Editors is requested to review the proposed merge of lp:~camptocamp/banking-addons/bank-statement-reconcile-7.0-fix-1313689 into lp:banking-addons/bank-statement-reconcile-7.0.
=== modified file 'account_statement_base_completion/statement.py'
--- account_statement_base_completion/statement.py	2014-04-27 18:44:20 +0000
+++ account_statement_base_completion/statement.py	2014-05-07 08:58:28 +0000
@@ -397,6 +397,8 @@
             "Auto-Completed",
             help="When this checkbox is ticked, the auto-completion "
                  "process/button will ignore this line."),
+        # Set account_id field as optional by removing required option.
+        'account_id': fields.many2one('account.account', 'Account'),
     }
 
     _defaults = {
@@ -440,6 +442,25 @@
         keys.sort()
         return keys
 
+    def _prepare_insert(self, statement, cols):
+        """ Apply column formating to prepare data for SQL inserting
+        Return a copy of statement
+        """
+        st_copy = statement
+        for k, col in st_copy.iteritems():
+            if k in cols:
+                st_copy[k] = self._columns[k]._symbol_set[1](col)
+        return st_copy
+
+    def _prepare_manyinsert(self, statement_store, cols):
+        """ Apply column formating to prepare multiple SQL inserts
+        Return a copy of statement_store
+        """
+        values = []
+        for statement in statement_store:
+            values.append(self._prepare_insert(statement, cols))
+        return values
+
     def _serialize_sparse_fields(self, cols, statement_store):
         """ Serialize sparse fields values in the target serialized field
         Return a copy of statement_store
@@ -469,6 +490,7 @@
         statement_line_obj.check_access_rule(cr, uid, [], 'create')
         statement_line_obj.check_access_rights(cr, uid, 'create', raise_exception=True)
         cols = self._get_available_columns(statement_store, include_serializable=True)
+        statement_store = self._prepare_manyinsert(statement_store, cols)
         tmp_vals = (', '.join(cols), ', '.join(['%%(%s)s' % i for i in cols]))
         sql = "INSERT INTO account_bank_statement_line (%s) VALUES (%s);" % tmp_vals
         try:
@@ -487,6 +509,7 @@
         from the ORM for records updating this kind of fields.
         """
         cols = self._get_available_columns([vals])
+        vals = self._prepare_insert(vals, cols)
         tmp_vals = (', '.join(['%s = %%(%s)s' % (i, i) for i in cols]))
         sql = "UPDATE account_bank_statement_line SET %s where id = %%(id)s;" % tmp_vals
         try:

=== modified file 'account_statement_base_import/statement.py'
--- account_statement_base_import/statement.py	2014-04-28 15:07:53 +0000
+++ account_statement_base_import/statement.py	2014-05-07 08:58:28 +0000
@@ -95,7 +95,7 @@
         return self.prepare_statement_lines_vals(*args, **kwargs)
 
     def prepare_statement_lines_vals(
-            self, cr, uid, parser_vals, account_payable, account_receivable,
+            self, cr, uid, parser_vals,
             statement_id, context):
         """
         Hook to build the values of a line from the parser returned values. At
@@ -104,8 +104,6 @@
 
         :param dict of vals from parser for account.bank.statement.line (called by
                 parser.get_st_line_vals)
-        :param int/long account_payable: ID of the receivable account to use
-        :param int/long account_receivable: ID of the payable account to use
         :param int/long statement_id: ID of the concerned account.bank.statement
         :return: dict of vals that will be passed to create method of statement line.
         """
@@ -176,18 +174,13 @@
                                             statement_vals,
                                             context=context)
 
-        if prof.receivable_account_id:
-            account_receivable = account_payable = prof.receivable_account_id.id
-        else:
-            account_receivable, account_payable = statement_obj.get_default_pay_receiv_accounts(
-                                                       cr, uid, context)
         try:
             # Record every line in the bank statement
             statement_store = []
             for line in result_row_list:
                 parser_vals = parser.get_st_line_vals(line)
                 values = self.prepare_statement_lines_vals(
-                    cr, uid, parser_vals, account_payable, account_receivable, statement_id,
+                    cr, uid, parser_vals, statement_id,
                     context)
                 statement_store.append(values)
             # Hack to bypass ORM poor perfomance. Sob...
@@ -232,11 +225,3 @@
             raise osv.except_osv(_("Statement import error"),
                                  _("The statement cannot be created: %s") % st)
         return statement_id
-
-
-class AccountBankStatementLine(Model):
-    _inherit = "account.bank.statement.line"
-
-    _columns = {
-        'account_id': fields.many2one('account.account', 'Account'),
-    }