From f66bd8c4591a0574d34b7086c05cd8af7b40febb Mon Sep 17 00:00:00 2001 From: "Guewen Baconnier @ Camptocamp" Date: Wed, 19 Dec 2012 11:55:57 +0100 Subject: [PATCH 01/13] [ADD] structure for the reconciliation history --- account_easy_reconcile/__init__.py | 1 + account_easy_reconcile/__openerp__.py | 5 +- .../easy_reconcile_history.py | 39 ++++++++++ .../easy_reconcile_history_view.xml | 75 +++++++++++++++++++ 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 account_easy_reconcile/easy_reconcile_history.py create mode 100644 account_easy_reconcile/easy_reconcile_history_view.xml diff --git a/account_easy_reconcile/__init__.py b/account_easy_reconcile/__init__.py index 19e90a30..b648751f 100755 --- a/account_easy_reconcile/__init__.py +++ b/account_easy_reconcile/__init__.py @@ -22,3 +22,4 @@ import easy_reconcile import base_reconciliation import simple_reconciliation +import easy_reconcile_history diff --git a/account_easy_reconcile/__openerp__.py b/account_easy_reconcile/__openerp__.py index 3d341325..cae7ca12 100755 --- a/account_easy_reconcile/__openerp__.py +++ b/account_easy_reconcile/__openerp__.py @@ -48,7 +48,10 @@ This latter add more complex reconciliations, allows multiple lines and partial. "category" : "Finance", "init_xml" : [], "demo_xml" : [], - "update_xml" : ["easy_reconcile.xml"], + "update_xml" : [ + "easy_reconcile.xml", + "easy_reconcile_history_view.xml", + ], 'license': 'AGPL-3', "auto_install": False, "installable": True, diff --git a/account_easy_reconcile/easy_reconcile_history.py b/account_easy_reconcile/easy_reconcile_history.py new file mode 100644 index 00000000..e37e2c52 --- /dev/null +++ b/account_easy_reconcile/easy_reconcile_history.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Guewen Baconnier +# Copyright 2012 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.osv import orm, fields + + +class easy_reconcile_history(orm.Model): + """ Store an history of the runs per profile + Each history stores the list of reconciliations done""" + + _name = 'easy.reconcile.history' + + _columns = { + 'easy_reconcile_id': fields.many2one( + 'account.easy.reconcile', 'Reconcile Profile', readonly=True), + 'date': fields.datetime('Run date', readonly=True), + 'reconcile_ids': fields.many2many( + 'account.move.reconcile', string='Reconciliations', readonly=True), + 'reconcile_partial_ids': fields.many2many( + 'account.move.reconcile', string='Partial Reconciliations', readonly=True), + } diff --git a/account_easy_reconcile/easy_reconcile_history_view.xml b/account_easy_reconcile/easy_reconcile_history_view.xml new file mode 100644 index 00000000..a11edf91 --- /dev/null +++ b/account_easy_reconcile/easy_reconcile_history_view.xml @@ -0,0 +1,75 @@ + + + + + + easy.reconcile.history.search + easy.reconcile.history + search + + + + + + + + + + + + + + + + + + + easy.reconcile.history.form + 16 + easy.reconcile.history + form + +
+ + + + + + +
+ + + easy.reconcile.history.tree + 16 + easy.reconcile.history + tree + + + + + + + + + + Easy Automatic Reconcile History + ir.actions.act_window + easy.reconcile.history + form + tree,form + + + + +
+
From 3ff89320a18cae980dbbf5c83f4717fe26bb5e9b Mon Sep 17 00:00:00 2001 From: "Guewen Baconnier @ Camptocamp" Date: Wed, 19 Dec 2012 14:07:07 +0100 Subject: [PATCH 02/13] [IMP] create history of reconciliations --- account_easy_reconcile/easy_reconcile.py | 65 ++++++++++++------- .../easy_reconcile_history.py | 10 ++- .../easy_reconcile_history_view.xml | 5 +- 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/account_easy_reconcile/easy_reconcile.py b/account_easy_reconcile/easy_reconcile.py index 6a2899cd..2637be71 100644 --- a/account_easy_reconcile/easy_reconcile.py +++ b/account_easy_reconcile/easy_reconcile.py @@ -144,7 +144,7 @@ class account_easy_reconcile(Model): 'scheduler': fields.many2one('ir.cron', 'scheduler', readonly=True), 'rec_log': fields.text('log', readonly=True), 'unreconciled_count': fields.function(_get_total_unrec, - type='integer', string='Fully Unreconciled Entries'), + type='integer', string='Unreconciled Entries'), 'reconciled_partial_count': fields.function(_get_partial_rec, type='integer', string='Partially Reconciled Entries'), } @@ -168,39 +168,58 @@ class account_easy_reconcile(Model): 'filter': rec_method.filter} def run_reconcile(self, cr, uid, ids, context=None): + def find_reconcile_ids(fieldname, move_line_ids): + if not move_line_ids: + return [] + sql = ("SELECT DISTINCT " + fieldname + + " FROM account_move_line " + " WHERE id in %s " + " AND " + fieldname + " IS NOT NULL") + cr.execute(sql, (tuple(move_line_ids),)) + res = cr.fetchall() + return [row[0] for row in res] + if context is None: context = {} - for rec_id in ids: - rec = self.browse(cr, uid, rec_id, context=context) - total_rec = 0 - total_partial_rec = 0 - details = [] - count = 0 - for method in rec.reconcile_method: - count += 1 + for rec in self.browse(cr, uid, ids, context=context): + 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), context=context) - rec_ids, partial_ids = rec_model.automatic_reconcile( + ml_rec_ids, ml_partial_ids = rec_model.automatic_reconcile( cr, uid, auto_rec_id, context=context) - details.append(_('method %d : full: %d lines, partial: %d lines') % \ - (count, len(rec_ids), len(partial_ids))) + all_ml_rec_ids += ml_rec_ids + all_ml_partial_ids += ml_partial_ids - total_rec += len(rec_ids) - total_partial_rec += len(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) - log = self.read(cr, uid, rec_id, ['rec_log'], context=context)['rec_log'] - log_lines = log and log.splitlines() or [] - log_lines[0:0] = [_("%s : %d lines have been fully reconciled" \ - " and %d lines have been partially reconciled (%s)") % \ - (time.strftime(DEFAULT_SERVER_DATETIME_FORMAT), total_rec, - total_partial_rec, ' | '.join(details))] - log = "\n".join(log_lines) - self.write(cr, uid, rec_id, {'rec_log': log}, context=context) - return True + history_id = 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) + return { + 'name':_("Reconciliations"), + 'view_mode': 'tree,form', # FIXME: In OpenERP 6.1 we can't display + 'view_id': False, # only the form, check in version 7.0 + 'view_type': 'form', + 'res_model': 'easy.reconcile.history', + 'type': 'ir.actions.act_window', + 'nodestroy': True, + 'target': 'current', + 'domain': unicode([('id', '=', history_id)]), + } diff --git a/account_easy_reconcile/easy_reconcile_history.py b/account_easy_reconcile/easy_reconcile_history.py index e37e2c52..251745fa 100644 --- a/account_easy_reconcile/easy_reconcile_history.py +++ b/account_easy_reconcile/easy_reconcile_history.py @@ -27,13 +27,19 @@ class easy_reconcile_history(orm.Model): Each history stores the list of reconciliations done""" _name = 'easy.reconcile.history' + _rec_name = 'easy_reconcile_id' + _order = 'date DESC' _columns = { 'easy_reconcile_id': fields.many2one( 'account.easy.reconcile', 'Reconcile Profile', readonly=True), 'date': fields.datetime('Run date', readonly=True), 'reconcile_ids': fields.many2many( - 'account.move.reconcile', string='Reconciliations', readonly=True), + 'account.move.reconcile', + 'account_move_reconcile_history_rel', + string='Reconciliations', readonly=True), 'reconcile_partial_ids': fields.many2many( - 'account.move.reconcile', string='Partial Reconciliations', readonly=True), + 'account.move.reconcile', + 'account_move_reconcile_history_partial_rel', + string='Partial Reconciliations', readonly=True), } diff --git a/account_easy_reconcile/easy_reconcile_history_view.xml b/account_easy_reconcile/easy_reconcile_history_view.xml index a11edf91..be1a2b57 100644 --- a/account_easy_reconcile/easy_reconcile_history_view.xml +++ b/account_easy_reconcile/easy_reconcile_history_view.xml @@ -20,6 +20,7 @@ + - + easy.reconcile.history.form 16 easy.reconcile.history @@ -46,7 +47,7 @@ - + easy.reconcile.history.tree 16 easy.reconcile.history From 18e08c0e98cacd841af51c4c85b404d0772ea2a0 Mon Sep 17 00:00:00 2001 From: "Guewen Baconnier @ Camptocamp" Date: Wed, 19 Dec 2012 14:11:13 +0100 Subject: [PATCH 03/13] [IMP] remove rec_log column no longer used with an history --- account_easy_reconcile/easy_reconcile.py | 3 +-- account_easy_reconcile/easy_reconcile.xml | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/account_easy_reconcile/easy_reconcile.py b/account_easy_reconcile/easy_reconcile.py index 2637be71..e093f8d8 100644 --- a/account_easy_reconcile/easy_reconcile.py +++ b/account_easy_reconcile/easy_reconcile.py @@ -142,7 +142,6 @@ class account_easy_reconcile(Model): 'account': fields.many2one('account.account', 'Account', required=True), 'reconcile_method': fields.one2many('account.easy.reconcile.method', 'task_id', 'Method'), 'scheduler': fields.many2one('ir.cron', 'scheduler', readonly=True), - 'rec_log': fields.text('log', readonly=True), 'unreconciled_count': fields.function(_get_total_unrec, type='integer', string='Unreconciled Entries'), 'reconciled_partial_count': fields.function(_get_partial_rec, @@ -152,7 +151,7 @@ class account_easy_reconcile(Model): def copy_data(self, cr, uid, id, default=None, context=None): if default is None: default = {} - default = dict(default, rec_log=False, scheduler=False) + default = dict(default, scheduler=False) return super(account_easy_reconcile, self).copy_data( cr, uid, id, default=default, context=context) diff --git a/account_easy_reconcile/easy_reconcile.xml b/account_easy_reconcile/easy_reconcile.xml index 1bd84c66..e26e785c 100644 --- a/account_easy_reconcile/easy_reconcile.xml +++ b/account_easy_reconcile/easy_reconcile.xml @@ -33,8 +33,6 @@ The lines should have the same amount (with the write-off) and the same partner