From 4c907cc165d5f6949a10f961cbc18d9dfbf0e3af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 15 Apr 2009 11:37:57 +0200 Subject: [PATCH] Create missing analytic_accounts on write and skip it on read for issue993 --- sale.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sale.py b/sale.py index 695f9d50b2..07568cf34b 100644 --- a/sale.py +++ b/sale.py @@ -66,6 +66,8 @@ class SaleLine(ModelSQL, ModelView): for line in lines: if line.type != 'line': continue + if not line.analytic_accounts: + continue for account in line.analytic_accounts.accounts: if account.root.id in root_ids: id2record[line.id]['analytic_account_' \ @@ -116,6 +118,14 @@ class SaleLine(ModelSQL, ModelView): if line.type != 'line': continue accounts = [] + if not line.analytic_accounts: + # Create missing selection + selection_id = selection_obj.create(cursor, 0, {}, + context=context) + self.write(cursor, user, line.id, { + 'analytic_accounts': selection_id, + }, context=context) + line = self.browse(cursor, user, line.id, context=context) for account in line.analytic_accounts.accounts: if account.root.id in selection_vals: value = selection_vals[account.root.id]