From 7a6d6ad4ab9b6940f88555df18b92a95059b42a1 Mon Sep 17 00:00:00 2001 From: florian-dacosta Date: Fri, 20 Feb 2015 15:24:37 +0100 Subject: [PATCH 1/3] Add commit every X line in easy_reconcile module --- account_easy_reconcile/simple_reconciliation.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/account_easy_reconcile/simple_reconciliation.py b/account_easy_reconcile/simple_reconciliation.py index f108ff4f..1af93353 100644 --- a/account_easy_reconcile/simple_reconciliation.py +++ b/account_easy_reconcile/simple_reconciliation.py @@ -19,8 +19,11 @@ # ############################################################################## +import logging from openerp.osv.orm import AbstractModel, TransientModel +_logger = logging.getLogger(__name__) + class EasyReconcileSimple(AbstractModel): _name = 'easy.reconcile.simple' @@ -58,6 +61,11 @@ class EasyReconcileSimple(AbstractModel): del lines[i] break count += 1 + if (context['commit_every'] and + count % context['commit_every'] == 0): + cr.commit() + _logger.info("Commit the reconciliations after %d lines", + count) return res, [] # empty list for partial, only full rec in "simple" rec def _simple_order(self, rec, *args, **kwargs): From 7e699d50db629cafc2781a7a02da8b80d85066f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Sun, 22 Feb 2015 21:26:49 +0100 Subject: [PATCH 2/3] [FIX] commit after each X line reconciled --- account_easy_reconcile/simple_reconciliation.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/account_easy_reconcile/simple_reconciliation.py b/account_easy_reconcile/simple_reconciliation.py index 1af93353..02ef74c5 100644 --- a/account_easy_reconcile/simple_reconciliation.py +++ b/account_easy_reconcile/simple_reconciliation.py @@ -59,13 +59,14 @@ class EasyReconcileSimple(AbstractModel): if reconciled: res += [credit_line['id'], debit_line['id']] del lines[i] + count += 1 + if (context['commit_every'] and + count % context['commit_every'] == 0): + cr.commit() + _logger.info( + "Commit the reconciliations after %d lines", + count) break - count += 1 - if (context['commit_every'] and - count % context['commit_every'] == 0): - cr.commit() - _logger.info("Commit the reconciliations after %d lines", - count) return res, [] # empty list for partial, only full rec in "simple" rec def _simple_order(self, rec, *args, **kwargs): From 85f548e4d3977dd969a88a23fc43a72360b2ba71 Mon Sep 17 00:00:00 2001 From: Florian Date: Mon, 23 Feb 2015 11:42:22 +0100 Subject: [PATCH 3/3] Fix infinite loop in easy_reconcile --- account_easy_reconcile/simple_reconciliation.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/account_easy_reconcile/simple_reconciliation.py b/account_easy_reconcile/simple_reconciliation.py index 02ef74c5..6659526a 100644 --- a/account_easy_reconcile/simple_reconciliation.py +++ b/account_easy_reconcile/simple_reconciliation.py @@ -37,6 +37,7 @@ class EasyReconcileSimple(AbstractModel): if self._key_field is None: raise ValueError("_key_field has to be defined") count = 0 + commit_count = 0 res = [] while (count < len(lines)): for i in xrange(count + 1, len(lines)): @@ -57,16 +58,17 @@ class EasyReconcileSimple(AbstractModel): cr, uid, rec, [credit_line, debit_line], allow_partial=False, context=context) if reconciled: + commit_count += 1 res += [credit_line['id'], debit_line['id']] del lines[i] - count += 1 if (context['commit_every'] and - count % context['commit_every'] == 0): + commit_count % context['commit_every'] == 0): cr.commit() _logger.info( "Commit the reconciliations after %d lines", count) break + count += 1 return res, [] # empty list for partial, only full rec in "simple" rec def _simple_order(self, rec, *args, **kwargs):