[IMP] Change strategy

This commit is contained in:
Jordi Ballester Alomar
2018-10-04 07:21:49 +02:00
committed by mreficent
parent f7e751cfdb
commit 31f749b4ec

View File

@@ -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)