From b5a8e5c86424a1d2a3a8eb1e2662e922683a7f27 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 14 Jun 2017 10:26:06 +0200 Subject: [PATCH] [FIX] account: verify the partners are the same Re-enable the constraint when reconciling entries belonging to different partners. The constrain was not triggerd because of the triggers on line_id. In old API it was triggered only when explicitely writing on that field. Convert to new API instead. Fixes #17292 Closes #17600 --- addons/account/account.py | 20 -------------------- addons/account/account_move_line.py | 23 ++++++++++++++++++++++- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 655db7065d5..c08be3323b5 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1655,26 +1655,6 @@ class account_move_reconcile(osv.osv): 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. 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): - move_lines = [] - if not reconcile.opening_reconciliation: - 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.account_id.type in ('receivable', 'payable') and line.partner_id.id != first_partner) for line in move_lines]): - return False - return True - - _constraints = [ - (_check_same_partner, 'You can only reconcile journal items with the same partner.', ['line_id', 'line_partial_ids']), - ] - 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): diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 982b1d8c23b..d38b604cb15 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -22,7 +22,7 @@ import time from datetime import datetime -from openerp import workflow +from openerp import api, workflow from openerp.osv import fields, osv from openerp.tools.translate import _ import openerp.addons.decimal_precision as dp @@ -607,6 +607,27 @@ class account_move_line(osv.osv): cr.execute('CREATE INDEX account_move_line_date_id_index ON account_move_line (date DESC, id desc)') return res + @api.constrains('reconcile_id', 'reconcile_partial_id') + def _check_reconcile_same_partner(self): + """ Ensure the partner is the same or empty on all lines and a reconcile mark. + We allow that only for opening/closing period""" + for line in self: + rec = False + move_lines = [] + if line.reconcile_id: + rec = line.reconcile_id + move_lines = rec.line_id + elif line.reconcile_partial_id: + rec = line.reconcile_partial_id + move_lines = rec.line_partial_ids + if rec and not rec.opening_reconciliation: + first_partner = line.partner_id + for rline in move_lines: + if (rline.partner_id != first_partner and + rline.account_id.type in ('receivable', 'payable')): + raise osv.except_osv( + _('Error!'), _("You can only reconcile journal items with the same partner.")) + def _check_no_view(self, cr, uid, ids, context=None): lines = self.browse(cr, uid, ids, context=context) for l in lines: