- We create a simple hierarchy like this Toplevel view account ├ Real analytic account 1 └ Real analytic account 2 - !record {model: account.analytic.account, id: analytic_account_view1}: name: 'Toplevel view account' type: 'view' - !record {model: account.analytic.account, id: analytic_account1}: name: 'Real analytic account 1' type: 'normal' parent_id: analytic_account_view1 - !record {model: account.analytic.account, id: analytic_account2}: name: 'Real analytic account 2' type: 'normal' parent_id: analytic_account_view1 - We add analytic lines in real accounts and journal - !record {model: account.analytic.journal, id: analytic_journal1}: name: 'Analytic journal' - !record {model: account.analytic.line, id: analytic_line1}: name: 'Analytic line 1' account_id: analytic_account1 journal_id: analytic_journal1 general_account_id: account.a_expense - !record {model: account.analytic.line, id: analytic_line2}: name: 'Analytic line 2' account_id: analytic_account2 journal_id: analytic_journal1 general_account_id: account.a_expense - Now we copy the toplevel account - !function {model: account.analytic.account, name: copy, id: analytic_account_view1}: - eval: "ref('analytic_account_view1')" - !python {model: account.analytic.account}: | # the toplevel account has been copied with the (copy) suffix accounts = self.search(cr, uid, [('name', 'like', '%Toplevel view account%')]) assert len(accounts) == 2, 'The toplevel account has not been copied' accounts = self.search(cr, uid, [('name', '=', 'Toplevel view account')]) assert len(accounts) == 1, 'The toplevel account copy has a bad name' # the sub-accounts and sub-accounts have been copied without the (copy) suffix accounts = self.search(cr, uid, [('name', '=', 'Real analytic account 1')]) assert len(accounts) == 2, 'The sub-account has not been copied' accounts = self.search(cr, uid, [('name', '=', 'Real analytic account 2')]) assert len(accounts) == 2, 'The sub-account has not been copied' # the analytic lines should not be duplicated lines = self.pool.get('account.analytic.line').search(cr, uid, [('name', 'like', '%Analytic line %')]) assert len(lines) == 2, "The analytic lines shouldn't have been copied"