Merge pull request #17 from guewen/reconcile-store-history

The history does not store the reconciled entries
This commit is contained in:
Leonardo Pistone
2014-08-26 11:02:33 +02:00
8 changed files with 59 additions and 57 deletions

View File

@@ -23,4 +23,3 @@
import easy_reconcile
import base_advanced_reconciliation
import advanced_reconciliation
import res_config # noqa

View File

@@ -75,7 +75,7 @@ many offices.
""",
'website': 'http://www.camptocamp.com',
'data': ['easy_reconcile_view.xml',
'res_config_view.xml'],
],
'test': [],
'images': [],
'installable': True,

View File

@@ -23,10 +23,8 @@ import logging
from itertools import product
from openerp.osv import orm
from openerp import pooler
from openerp.tools.translate import _
_logger = logging.getLogger(__name__)
@@ -222,29 +220,10 @@ class easy_reconcile_advanced(orm.AbstractModel):
cr, uid, rec, move_line, op, matchers, context=context)]
def _action_rec(self, cr, uid, rec, context=None):
# we use a new cursor to be able to commit the reconciliation
# often. We have to create it here and not later to avoid problems
# where the new cursor sees the lines as reconciles but the old one
# does not.
if context is None:
context = {}
ctx = context.copy()
ctx['commit_every'] = (
rec.journal_id.company_id.reconciliation_commit_every
)
if ctx['commit_every']:
new_cr = pooler.get_db(cr.dbname).cursor()
else:
new_cr = cr
try:
credit_lines = self._query_credit(new_cr, uid, rec, context=ctx)
debit_lines = self._query_debit(new_cr, uid, rec, context=ctx)
result = self._rec_auto_lines_advanced(
new_cr, uid, rec, credit_lines, debit_lines, context=ctx)
finally:
if ctx['commit_every']:
new_cr.commit()
new_cr.close()
credit_lines = self._query_credit(cr, uid, rec, context=context)
debit_lines = self._query_debit(cr, uid, rec, context=context)
result = self._rec_auto_lines_advanced(
cr, uid, rec, credit_lines, debit_lines, context=context)
return result
def _skip_line(self, cr, uid, rec, move_line, context=None):

View File

@@ -23,3 +23,4 @@ import easy_reconcile
import base_reconciliation
import simple_reconciliation
import easy_reconcile_history
import res_config

View File

@@ -58,7 +58,9 @@ allows multiple lines and partial.
"data": ["easy_reconcile.xml",
"easy_reconcile_history_view.xml",
"security/ir_rule.xml",
"security/ir.model.access.csv"],
"security/ir.model.access.csv",
"res_config_view.xml",
],
'license': 'AGPL-3',
"auto_install": False,
"installable": True,

View File

@@ -21,6 +21,7 @@
from openerp.osv import fields, orm
from openerp.tools.translate import _
from openerp import pooler
class EasyReconcileOptions(orm.AbstractModel):
@@ -208,7 +209,7 @@ class AccountEasyReconcile(orm.Model):
'filter': rec_method.filter}
def run_reconcile(self, cr, uid, ids, context=None):
def find_reconcile_ids(fieldname, move_line_ids):
def find_reconcile_ids(cr, fieldname, move_line_ids):
if not move_line_ids:
return []
sql = ("SELECT DISTINCT " + fieldname +
@@ -219,37 +220,57 @@ class AccountEasyReconcile(orm.Model):
res = cr.fetchall()
return [row[0] for row in res]
# we use a new cursor to be able to commit the reconciliation
# often. We have to create it here and not later to avoid problems
# where the new cursor sees the lines as reconciles but the old one
# does not.
if context is None:
context = {}
for rec in self.browse(cr, uid, ids, context=context):
all_ml_rec_ids = []
all_ml_partial_ids = []
ctx = context.copy()
ctx['commit_every'] = (
rec.account.company_id.reconciliation_commit_every
)
if ctx['commit_every']:
new_cr = pooler.get_db(cr.dbname).cursor()
else:
new_cr = cr
try:
all_ml_rec_ids = []
all_ml_partial_ids = []
for method in rec.reconcile_method:
rec_model = self.pool.get(method.name)
auto_rec_id = rec_model.create(
cr, uid,
self._prepare_run_transient(
cr, uid, method, context=context),
for method in rec.reconcile_method:
rec_model = self.pool.get(method.name)
auto_rec_id = rec_model.create(
new_cr, uid,
self._prepare_run_transient(
new_cr, uid, method, context=context),
context=context)
ml_rec_ids, ml_partial_ids = rec_model.automatic_reconcile(
new_cr, uid, auto_rec_id, context=ctx)
all_ml_rec_ids += ml_rec_ids
all_ml_partial_ids += ml_partial_ids
reconcile_ids = find_reconcile_ids(
new_cr, 'reconcile_id', all_ml_rec_ids)
partial_ids = find_reconcile_ids(
new_cr, 'reconcile_partial_id', all_ml_partial_ids)
self.pool.get('easy.reconcile.history').create(
new_cr, uid,
{'easy_reconcile_id': rec.id,
'date': fields.datetime.now(),
'reconcile_ids': [(4, rid) for rid in reconcile_ids],
'reconcile_partial_ids': [(4, rid) for rid in partial_ids],
},
context=context)
ml_rec_ids, ml_partial_ids = rec_model.automatic_reconcile(
cr, uid, auto_rec_id, context=context)
all_ml_rec_ids += ml_rec_ids
all_ml_partial_ids += ml_partial_ids
reconcile_ids = find_reconcile_ids(
'reconcile_id', all_ml_rec_ids)
partial_ids = find_reconcile_ids(
'reconcile_partial_id', all_ml_partial_ids)
self.pool.get('easy.reconcile.history').create(
cr,
uid,
{'easy_reconcile_id': rec.id,
'date': fields.datetime.now(),
'reconcile_ids': [(4, rid) for rid in reconcile_ids],
'reconcile_partial_ids': [(4, rid) for rid in partial_ids]},
context=context)
finally:
if ctx['commit_every']:
new_cr.commit()
new_cr.close()
return True
def _no_history(self, cr, uid, rec, context=None):