From 00d267a53db914708adc9dd08bace34607c6962d Mon Sep 17 00:00:00 2001 From: Jordi Ballester Alomar Date: Thu, 4 Oct 2018 07:21:49 +0200 Subject: [PATCH] [IMP] Change strategy --- .../models/account_account.py | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/account_set_reconcilable/models/account_account.py b/account_set_reconcilable/models/account_account.py index 9386c8a9..2c759388 100644 --- a/account_set_reconcilable/models/account_account.py +++ b/account_set_reconcilable/models/account_account.py @@ -9,23 +9,16 @@ class AccountAccount(models.Model): @api.multi def write(self, vals): - reconcile = False - if vals.get('reconcile', False) and not self.env.context.get( - 'set_reconcilable', False): - reconcile = vals.pop('reconcile') - rec = super(AccountAccount, self).write(vals=vals) - if reconcile: - moves_lines = self.env['account.move.line'].search( + if vals.get('reconcile', False): + move_lines = self.env['account.move.line'].search( [('account_id', 'in', self.ids)]) - for account in self: - lines = moves_lines.filtered( - lambda line: line.account_id == account) - if lines: - t_account = account.copy() - lines.write({'account_id': t_account.id}) - account.with_context(set_reconcilable=True).write( - {'reconcile': reconcile}) - lines.write({'account_id': account.id}) - lines._amount_residual() - t_account.unlink() - return rec + if move_lines: + for acc in self: + acc_move_lines = move_lines.filtered( + lambda line: line.account_id == acc) + self.env.cr.execute( + "UPDATE account_account SET reconcile=True " + "WHERE id=%s", (acc.id,)) + acc_move_lines._amount_residual() + vals.pop('reconcile') + return super(AccountAccount, self).write(vals=vals)