From 380d1bc083422b062500406fe6ada2d30451506a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 19 Dec 2013 14:44:48 +0100 Subject: [PATCH] Use a sequence of records, values in write issue3499 review1641003 --- sale.py | 77 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/sale.py b/sale.py index 5c021b8451..8aafd9655d 100644 --- a/sale.py +++ b/sale.py @@ -110,42 +110,47 @@ class SaleLine: return super(SaleLine, cls).create(vlist) @classmethod - def write(cls, lines, vals): + def write(cls, *args): Selection = Pool().get('analytic_account.account.selection') - vals = vals.copy() - selection_vals = {} - for field in vals.keys(): - if field.startswith('analytic_account_'): - root_id = int(field[len('analytic_account_'):]) - selection_vals[root_id] = vals[field] - del vals[field] - if selection_vals: - for line in lines: - if line.type != 'line': - continue - accounts = [] - if not line.analytic_accounts: - # Create missing selection - with Transaction().set_user(0): - selection, = Selection.create([{}]) - cls.write([line], { - 'analytic_accounts': selection.id, + + actions = iter(args) + args = [] + for lines, values in zip(actions, actions): + values = values.copy() + selection_vals = {} + for field, value in values.items(): + if field.startswith('analytic_account_'): + root_id = int(field[len('analytic_account_'):]) + selection_vals[root_id] = value + del values[field] + if selection_vals: + for line in lines: + if line.type != 'line': + continue + accounts = [] + if not line.analytic_accounts: + # Create missing selection + with Transaction().set_user(0): + selection, = Selection.create([{}]) + cls.write([line], { + 'analytic_accounts': selection.id, + }) + for account in line.analytic_accounts.accounts: + if account.root.id in selection_vals: + value = selection_vals[account.root.id] + if value: + accounts.append(value) + else: + accounts.append(account.id) + for account_id in selection_vals.values(): + if account_id \ + and account_id not in accounts: + accounts.append(account_id) + Selection.write([line.analytic_accounts], { + 'accounts': [('set', accounts)], }) - for account in line.analytic_accounts.accounts: - if account.root.id in selection_vals: - value = selection_vals[account.root.id] - if value: - accounts.append(value) - else: - accounts.append(account.id) - for account_id in selection_vals.values(): - if account_id \ - and account_id not in accounts: - accounts.append(account_id) - Selection.write([line.analytic_accounts], { - 'accounts': [('set', accounts)], - }) - return super(SaleLine, cls).write(lines, vals) + args.extend((lines, values)) + return super(SaleLine, cls).write(*args) @classmethod def delete(cls, lines): @@ -207,8 +212,8 @@ class Account: return accounts @classmethod - def write(cls, accounts, vals): + def write(cls, accounts, values, *args): SaleLine = Pool().get('sale.line') - super(Account, cls).write(accounts, vals) + super(Account, cls).write(accounts, values, *args) # Restart the cache on the fields_view_get method of sale.line SaleLine._fields_view_get_cache.clear()