Skip to content

Commit

Permalink
[IMP]propagate active through hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronHForgeFlow committed Nov 20, 2018
1 parent 5f116e1 commit 5d21b2e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
17 changes: 17 additions & 0 deletions account_analytic_parent/models/account_analytic_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,20 @@ def name_get(self):
current = current.parent_id
res.append((account.id, name))
return res

@api.multi
@api.constrains('active')
def check_parent_active(self):
for account in self:
if (account.active and account.parent_id and
account.parent_id not in self and
not account.parent_id.active):
raise UserError(
_('Please activate first parent account %s')
% account.parent_id.display_name)

@api.multi
def write(self, vals):
if self and 'active' in vals and not vals['active']:
self.mapped('child_ids').write({'active': False})
return super(AccountAnalyticAccount, self).write(vals)
18 changes: 18 additions & 0 deletions account_analytic_parent/tests/test_account_analytic_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,21 @@ def test_debit_credit_balance(self):
"Analytic account in the debit side")
self.assertEqual(self.analytic_parent2.credit, 50, "Wrong amount")
self.assertEqual(self.analytic_parent2.balance, 50, "Wrong amount")

def test_wizard(self):
self.wizard = self.env['account.analytic.chart'].create({
'from_date': '2017-01-01',
'to_date': '2017-12-31',
})
result = self.wizard.analytic_account_chart_open_window()
self.assertTrue('2017-01-01' in result['context'])
self.assertTrue('2017-12-31' in result['context'])

def test_archive(self):
self.analytic_parent1.toggle_active()
self.assertEqual(self.analytic_son.active, False)
self.analytic_parent1.toggle_active()
self.assertEqual(self.analytic_son.active, False)
self.analytic_parent1.toggle_active()
with self.assertRaises(ValidationError):
self.analytic_son.toggle_active()

0 comments on commit 5d21b2e

Please sign in to comment.