diff --git a/account_analytic_parent/models/account_analytic_account.py b/account_analytic_parent/models/account_analytic_account.py index 0268d69c1d..22b2ae7844 100644 --- a/account_analytic_parent/models/account_analytic_account.py +++ b/account_analytic_parent/models/account_analytic_account.py @@ -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) diff --git a/account_analytic_parent/tests/test_account_analytic_account.py b/account_analytic_parent/tests/test_account_analytic_account.py index 83ca74c868..053a48902c 100644 --- a/account_analytic_parent/tests/test_account_analytic_account.py +++ b/account_analytic_parent/tests/test_account_analytic_account.py @@ -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()