[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
This commit is contained in:
parent
eba662336c
commit
b5a8e5c864
|
@ -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):
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue