SHORT SITUATION EXPLAINATION :
I am creating a method, trying to create a record on account.move object,
the account.move object had a one2many field into account.move.line, so as to fill this field while creating the account.move record, I used a list of dictionnaries like this : [{'name' : name, 'debit' : debit} , {'name' : name2 , 'debit' : debit}], so as every dictionnary of this list is corresponding to a record of the account.move.line.
CODE AND ERROR TRACEBACK :
Here is the interesting part of my method :
line = [{}]
line = [{
'name' : 'Credit Client',
'account_id' : acc_id,
'debit' : debit,
}]line.append({
'name' : 'equilibrage',
'account_id' : 726,
'credit' : debit,
})period = period_obj.find(cr, uid, date, context=None)
period_res = period[0]
move = {
'ref' : num_bl,
'line_id' : line,
'journal_id' : 2,
'date' : date,
'company_id' : company_id,
'period_id' : period_res,
}move_id = move_obj.create(cr, uid, move, context=None)
move_obj.post(cr, uid, [move_id], context=None)
res = super(StockPickingOut, self).force_assign(cr, uid, ids, *args)return res
Here is the create method of account.move overrided :
def create(self, cr, uid, vals, context=None):
if context is None:
context = {}
if 'line_id' in vals and context.get('copy'):
for l in vals['line_id']:
if not l[0]:
l[2].update({
'reconcile_id':False,
'reconcile_partial_id':False,
'analytic_lines':False,
'invoice':False,
'ref':False,
'balance':False,
'account_tax_id':False,
'statement_id': False,
})if 'journal_id' in vals and vals.get('journal_id', False):
for l in vals['line_id']:
if not l[0]:
l[2]['journal_id'] = vals['journal_id']
context['journal_id'] = vals['journal_id']
if 'period_id' in vals:
for l in vals['line_id']:
if not l[0]:
l[2]['period_id'] = vals['period_id']
context['period_id'] = vals['period_id']
else:
default_period = self._get_period(cr, uid, context)
for l in vals['line_id']:
if not l[0]:
l[2]['period_id'] = default_period
context['period_id'] = default_periodif vals.get('line_id', False):
c = context.copy()
c['novalidate'] = True
c['period_id'] = vals['period_id'] if 'period_id' in vals else self._get_period(cr, uid, context)
c['journal_id'] = vals['journal_id']
if 'date' in vals: c['date'] = vals['date']result = super(account_move, self).create(cr, uid, vals, c)
tmp = self.validate(cr, uid, [result], context)
journal = self.pool.get('account.journal').browse(cr, uid, vals['journal_id'], context)
if journal.entry_posted and tmp:
self.button_validate(cr,uid, [result], context)
else:
result = super(account_move, self).create(cr, uid, vals, context)
return result
Here is the server traceback :
File "/opt/openerp/server/openerp/addons/add_bl_valcr/stock.py", line 64, in force_assign move_id = move_obj.create(cr, uid, move, context=None) File "/opt/openerp/server/openerp/addons/account/account.py", line 1393, in create result = super(account_move, self).create(cr, uid, vals, c) File "/opt/openerp/server/openerp/osv/orm.py", line 4550, in create result += self._columns[field].set(cr, self, id_new, field, vals[field], user, rel_context) or [] File "/opt/openerp/server/openerp/osv/fields.py", line 557, in set if act[0] == 0: KeyError: 0
I think there is something wrong with the key 0 on the line 5 of create method, caused by the "line" type, it tried to access the object via the key 0, but it's not valid, I'm searching a simple and valid way to save these two records in account.move.line.
Should I override the create method too ? because it's used for another purpose, and because I am using it in different conditions.
Suggestions, solutions please ?