From 227738dedb586128eac1753795bc85d806ee127d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Grand-Guillaume?= Date: Fri, 26 Oct 2012 15:54:15 +0200 Subject: [PATCH] [IMP] Forbid to remove the reconcile on opening entries, we introduce a new boolean field to identify the reconciliation made by the closing process from others. bzr revid: joel.grandguillaume@camptocamp.com-20121026135415-k1q0yq5zxngmfm5k --- addons/account/account.py | 31 +++++++++++++------ addons/account/account_move_line.py | 4 ++- .../wizard/account_fiscalyear_close.py | 4 +-- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 330e3f2d742..2e60c47d758 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1698,23 +1698,36 @@ class account_move_reconcile(osv.osv): 'line_id': fields.one2many('account.move.line', 'reconcile_id', 'Entry Lines'), 'line_partial_ids': fields.one2many('account.move.line', 'reconcile_partial_id', 'Partial Entry lines'), 'create_date': fields.date('Creation date', readonly=True), + 'opening_reconcile': fields.boolean('Opening entries reconciliation', help="Is this reconciliation produced by the opening of a new fiscal year ?."), } _defaults = { 'name': lambda self,cr,uid,ctx=None: self.pool.get('ir.sequence').get(cr, uid, 'account.reconcile', context=ctx) or '/', + 'opening_reconcile': 0, } + # You cannot unlink a reconciliation if it is a opening_reconcile one, + # you should use the generate opening entries wizard for that + def unlink(self, cr, uid, ids, context=None): + for move_rec in self.browse(cr, uid, ids): + if move_rec.opening_reconcile: + raise osv.except_osv(_('Error!'), _('You cannot unreconcile journal items if they has been generated by the \ + opening/closing fiscal year process.')) + return super(account_move_reconcile, self).unlink(cr, uid, ids, context=context) + # Look in the line_id and line_partial_ids to ensure the partner is the same or empty - # on all lines + # on all lines. We allow that only for opening/closing period def _check_same_partner(self, cr, uid, ids, context=None): for reconcile in self.browse(cr, uid, ids, context=context): - if reconcile.line_id: - first_partner = reconcile.line_id[0].partner_id.id - move_lines = reconcile.line_id - elif reconcile.line_partial_ids: - first_partner = reconcile.line_partial_ids[0].partner_id.id - move_lines = reconcile.line_partial_ids - if any([line.partner_id.id != first_partner for line in move_lines]): - return False + move_lines = [] + if not reconcile.opening_reconcile: + if reconcile.line_id: + first_partner = reconcile.line_id[0].partner_id.id + move_lines = reconcile.line_id + elif reconcile.line_partial_ids: + first_partner = reconcile.line_partial_ids[0].partner_id.id + move_lines = reconcile.line_partial_ids + if any([line.partner_id.id != first_partner for line in move_lines]): + return False return True _constraints = [ diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 147fe7f76a4..ed6b9caf9a8 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -1126,7 +1126,7 @@ class account_move_line(osv.osv): 'has been confirmed.') % res[2]) return res - def _remove_move_reconcile(self, cr, uid, move_ids=None, context=None): + def _remove_move_reconcile(self, cr, uid, move_ids=None, opening_reconcile=False, context=None): # Function remove move rencocile ids related with moves obj_move_line = self.pool.get('account.move.line') obj_move_rec = self.pool.get('account.move.reconcile') @@ -1141,6 +1141,8 @@ class account_move_line(osv.osv): unlink_ids += rec_ids unlink_ids += part_rec_ids if unlink_ids: + if opening_reconcile: + obj_move_rec.write(cr, uid, unlink_ids, {'opening_reconcile':False}) obj_move_rec.unlink(cr, uid, unlink_ids) return True diff --git a/addons/account/wizard/account_fiscalyear_close.py b/addons/account/wizard/account_fiscalyear_close.py index 196c14d3792..60a2e486948 100644 --- a/addons/account/wizard/account_fiscalyear_close.py +++ b/addons/account/wizard/account_fiscalyear_close.py @@ -60,7 +60,7 @@ class account_fiscalyear_close(osv.osv_memory): cr.execute('select distinct(company_id) from account_move_line where id in %s',(tuple(ids),)) if len(cr.fetchall()) > 1: raise osv.except_osv(_('Warning!'), _('The entries to reconcile should belong to the same company.')) - r_id = self.pool.get('account.move.reconcile').create(cr, uid, {'type': 'auto'}) + r_id = self.pool.get('account.move.reconcile').create(cr, uid, {'type': 'auto', 'opening_reconcile':True}) cr.execute('update account_move_line set reconcile_id = %s where id in %s',(r_id, tuple(ids),)) return r_id @@ -107,7 +107,7 @@ class account_fiscalyear_close(osv.osv_memory): ('journal_id', '=', new_journal.id), ('period_id', '=', period.id)]) if move_ids: move_line_ids = obj_acc_move_line.search(cr, uid, [('move_id', 'in', move_ids)]) - obj_acc_move_line._remove_move_reconcile(cr, uid, move_line_ids, context=context) + obj_acc_move_line._remove_move_reconcile(cr, uid, move_line_ids, opening_reconcile=True, context=context) obj_acc_move_line.unlink(cr, uid, move_line_ids, context=context) obj_acc_move.unlink(cr, uid, move_ids, context=context)