Use a sequence of records, values in write

issue3499
review1641003
This commit is contained in:
Cédric Krier committed 2013-12-19 14:44:48 +01:00
1 parent dbcb2289c4
commit 380d1bc083
1 file changed
+41 -36
+41 -36
View File
@@ -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()