From 8132259454bf6b19b9f740510a21cf087a112dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Grand-Guillaume?= Date: Fri, 26 Oct 2012 10:49:58 +0200 Subject: [PATCH] [IMP] Add a constraints on reconcile object to forbid the reconciliation between different partner [IMP] Add a constraint on account move: you cannot pickup a date that is not in the fiscal year of the concerned period bzr revid: joel.grandguillaume@camptocamp.com-20121026084958-nlcoqlav00l42gwr --- addons/account/account.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/addons/account/account.py b/addons/account/account.py index 33150274bdf..f3ba38fee8d 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1313,6 +1313,14 @@ class account_move(osv.osv): 'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id, } + def _check_fiscal_year(self, cursor, user, ids): + for move in self.browse(cursor, user, ids): + date_start = move.period_id.fiscalyear_id.date_start + date_stop = move.period_id.fiscalyear_id.date_stop + if move.date < date_start or move.date > date_stop: + return False + return True + def _check_centralisation(self, cursor, user, ids, context=None): for move in self.browse(cursor, user, ids, context=context): if move.journal_id.centralisation: @@ -1328,6 +1336,9 @@ class account_move(osv.osv): (_check_centralisation, 'You cannot create more than one move per period on a centralized journal.', ['journal_id']), + (_check_fiscal_year, + 'You cannot create entries with date not in the fiscal year of the chosen period', + ['line_id','']), ] def post(self, cr, uid, ids, context=None): @@ -1686,7 +1697,25 @@ class account_move_reconcile(osv.osv): _defaults = { 'name': lambda self,cr,uid,ctx=None: self.pool.get('ir.sequence').get(cr, uid, 'account.reconcile', context=ctx) or '/', } + + # Look in the line_id and line_partial_ids to ensure the partner is the same or empty + # on all lines + 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 + return True + _constraints = [ + (_check_same_partner, 'You can only reconcile moves where the partner (we mean ID) is the same or empty on all entries.', ['line_id']), + ] + def reconcile_partial_check(self, cr, uid, ids, type='auto', context=None): total = 0.0 for rec in self.browse(cr, uid, ids, context=context):