Use a list of dictionaries in create().
issue2358 review266002
This commit is contained in:
1 parent
7d48e3b1cb
commit
9ea0e8e0f7
1 file changed
+22
-20
@@ -88,23 +88,25 @@ class SaleLine:
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
def create(cls, vals):
|
||||
def create(cls, vlist):
|
||||
Selection = Pool().get('analytic_account.account.selection')
|
||||
vals = vals.copy()
|
||||
selection_vals = {}
|
||||
for field in vals.keys():
|
||||
if field.startswith('analytic_account_'):
|
||||
if vals[field]:
|
||||
selection_vals.setdefault('accounts', [])
|
||||
selection_vals['accounts'].append(('add', [vals[field]]))
|
||||
del vals[field]
|
||||
if vals.get('analytic_accounts'):
|
||||
Selection.write([Selection(vals['analytic_accounts'])],
|
||||
selection_vals)
|
||||
elif vals.get('type', 'line') == 'line':
|
||||
selection = Selection.create(selection_vals)
|
||||
vals['analytic_accounts'] = selection.id
|
||||
return super(SaleLine, cls).create(vals)
|
||||
vlist = [x.copy() for x in vlist]
|
||||
for vals in vlist:
|
||||
selection_vals = {}
|
||||
for field in vals.keys():
|
||||
if field.startswith('analytic_account_'):
|
||||
if vals[field]:
|
||||
selection_vals.setdefault('accounts', [])
|
||||
selection_vals['accounts'].append(('add',
|
||||
[vals[field]]))
|
||||
del vals[field]
|
||||
if vals.get('analytic_accounts'):
|
||||
Selection.write([Selection(vals['analytic_accounts'])],
|
||||
selection_vals)
|
||||
elif vals.get('type', 'line') == 'line':
|
||||
selection, = Selection.create([selection_vals])
|
||||
vals['analytic_accounts'] = selection.id
|
||||
return super(SaleLine, cls).create(vlist)
|
||||
|
||||
@classmethod
|
||||
def write(cls, lines, vals):
|
||||
@@ -124,7 +126,7 @@ class SaleLine:
|
||||
if not line.analytic_accounts:
|
||||
# Create missing selection
|
||||
with Transaction().set_user(0):
|
||||
selection = Selection.create({})
|
||||
selection, = Selection.create([{}])
|
||||
cls.write([line], {
|
||||
'analytic_accounts': selection.id,
|
||||
})
|
||||
@@ -196,12 +198,12 @@ class Account:
|
||||
SaleLine._fields_view_get_cache.clear()
|
||||
|
||||
@classmethod
|
||||
def create(cls, vals):
|
||||
def create(cls, vlist):
|
||||
SaleLine = Pool().get('sale.line')
|
||||
account = super(Account, cls).create(vals)
|
||||
accounts = super(Account, cls).create(vlist)
|
||||
# Restart the cache on the fields_view_get method of sale.line
|
||||
SaleLine._fields_view_get_cache.clear()
|
||||
return account
|
||||
return accounts
|
||||
|
||||
@classmethod
|
||||
def write(cls, accounts, vals):
|
||||
|
||||
Reference in new issue
Block a user