(tuple(ids), ))
r = cr.fetchall()
#TODO: move this check to a constraint in the account_move_reconcile object
- if (len(r) != 1) and not context.get('fy_closing', False):
- raise osv.except_osv(_('Error'), _('Entries are not of the same account or already reconciled ! '))
if not unrec_lines:
raise osv.except_osv(_('Error'), _('Entry is already reconciled'))
account = account_obj.browse(cr, uid, account_id, context=context)
- if not context.get('fy_closing', False) and not account.reconcile:
- raise osv.except_osv(_('Error'), _('This account does not allow reconciliation! You should update the account definition to change this.'))
if r[0][1] != None:
raise osv.except_osv(_('Error'), _('Some entries are already reconciled !'))
@param ids: List of Account fiscalyear close state’s IDs
"""
+ def _reconcile_fy_closing(cr, uid, ids, context=None):
+ """
+ This private function manually do the reconciliation on the account_move_line given as `ids´, and directly
+ through psql. It's necessary to do it this way because the usual `reconcile()´ function on account.move.line
+ object is really resource greedy (not supposed to work on reconciliation between thousands of records) and
+ it does a lot of different computation that are useless in this particular case.
+ """
+ #check that the reconcilation concern journal entries from only one company
+ 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'})
+ cr.execute('update account_move_line set reconcile_id = %s where id in %s',(r_id, tuple(ids),))
+ return r_id
+
obj_acc_period = self.pool.get('account.period')
obj_acc_fiscalyear = self.pool.get('account.fiscalyear')
obj_acc_journal = self.pool.get('account.journal')
#reconcile all the move.line of the opening move
ids = obj_acc_move_line.search(cr, uid, [('journal_id', '=', new_journal.id),
('period_id.fiscalyear_id','=',new_fyear.id)])
- context['fy_closing'] = True
if ids:
- reconcile_id = obj_acc_move_line.reconcile(cr, uid, ids, context=context)
+ reconcile_id = _reconcile_fy_closing(cr, uid, ids, context=context)
#set the creation date of the reconcilation at the first day of the new fiscalyear, in order to have good figures in the aged trial balance
self.pool.get('account.move.reconcile').write(cr, uid, [reconcile_id], {'create_date': new_fyear.date_start}, context=context)