Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

TypeError: argument 2 to map() must support iteration [Closed]

By
santhosh
on 12/21/15, 1:52 AM 346 views

The Question has been closed

by
santhosh
on 12/29/2015 01:40:22

Hi Every one,

i want to create account.move with balanced credit and debit amount i have return code for that when i run the code it shows

TypeError: argument 2 to map() must support iteration error if i pass [(0,0,{'name':name,'account_id':com_acc,'debit':amount}] in line_ids it create only debit when i add

[(0,0,{'name':name,'account_id':com_acc,'credit':amount} to it it returns the error below is my code can any one tell my mistake and how to fix it:

def account_move_get(self, cr, uid, exp, context=None):

journal_obj = self.pool.get('account.journal')

expense = self.browse(cr, uid, exp, context=context)

company_id = expense.company_id.id

date = expense.approve_date

ref = expense.req_no

journal_id = False

if expense.journal_id:

journal_id = expense.journal_id.id

else:

journal_id = journal_obj.search(cr, uid, [('type', '=', 'purchase'), ('company_id', '=', company_id)])

if not journal_id:

raise osv.except_osv(_('Error!'), _("No expense journal found. Please make sure you have a journal with type 'purchase' configured."))

journal_id = journal_id[0]

return self.pool.get('account.move').account_move_prepare(cr, uid, journal_id, company_id=company_id, context=context)

def line_get_convert(self, cr, uid, x, exp, part, date, context=None):

partner_id = self.pool.get('res.partner')._find_accounting_partner(part).id

return {

'name': exp.req_no,

#'currency_id': x['currency_id'],

'partner_id': partner_id,

'date': exp.approve_date,

'debit': exp.approve_amount>0 and exp.approve_amount,

'credit': exp.approve_amount<0 and -exp.approve_amount,

'account_id': exp.company_acc,

}

def action_receipt_create(self, cr, uid, ids, context=None):

'''

main function that is called when trying to create the accounting entries related to an expense

'''

move_obj = self.pool.get('account.move')

for exp in self.browse(cr, uid, ids, context=context):

if not exp.employee_name.address_home_id:

raise osv.except_osv(_('Error!'), _('The employee must have a home address.'))

if not exp.employee_name.address_home_id.property_account_payable.id:

raise osv.except_osv(_('Error!'), _('The employee must have a payable account set on his home address.'))

company_currency = exp.company_id.currency_id.id

j_id = exp.journal_id.id

name= exp.req_no

amount= exp.approve_amount

com_acc = exp.company_acc

diff_currency_p = exp.currency_id.id <> company_currency

#create the move that will contain the accounting entries

eml = self.move_line_get(cr, uid, exp.id, context=context)

move_id = move_obj.create(cr, uid, self.account_move_get(cr, uid, exp.id, context=context), context=context)

acc = exp.employee_name.address_home_id.property_account_payable.id

eml.append({

'name' : name,

'account_id' : acc,

})

lines = map(lambda x:(0,0,self.line_get_convert(cr, uid, x, exp, exp.employee_name.address_home_id, exp.approve_date, context=context)), eml)

journal_id = move_obj.browse(cr, uid, move_id, context).journal_id

# post the journal entry if 'Skip 'Draft' State for Manual Entries' is checked #####[(0,0,{'name':name,'account_id':com_acc,'debit':amount},{'name':name,'account_id':acc,'credit':amount})]

if journal_id.entry_posted:

move_obj.button_validate(cr, uid, [move_id], context)

move_obj.write(cr, uid, [move_id], {'line_id': lines}, context=context)

self.write(cr, uid, ids, {'account_move_id': move_id, 'state': 'approved'}, context=context)

return True

def action_receipt_create(self, cr, uid, ids, context=None):

'''

main function that is called when trying to create the accounting entries related to an expense

'''

move_obj = self.pool.get('account.move')

for exp in self.browse(cr, uid, ids, context=context):

if not exp.employee_name.address_home_id:

raise osv.except_osv(_('Error!'), _('The employee must have a home address.'))

if not exp.employee_name.address_home_id.property_account_payable.id:

raise osv.except_osv(_('Error!'), _('The employee must have a payable account set on his home address.'))

company_currency = exp.company_id.currency_id.id

j_id = exp.journal_id.id

name= exp.req_no

amount= exp.approve_amount

com_acc = exp.company_acc

diff_currency_p = exp.currency_id.id <> company_currency

#create the move that will contain the accounting entries

eml = self.move_line_get(cr, uid, exp.id, context=context)

move_id = move_obj.create(cr, uid, self.account_move_get(cr, uid, exp.id, context=context), context=context)

acc = exp.employee_name.address_home_id.property_account_payable.id

eml.append({

'name' : name,

'account_id' : acc,

})

lines = map(lambda x:(0,0,self.line_get_convert(cr, uid, x, exp, exp.employee_name.address_home_id, exp.approve_date, context=context)), eml)

journal_id = move_obj.browse(cr, uid, move_id, context).journal_id

# post the journal entry if 'Skip 'Draft' State for Manual Entries' is checked #####[(0,0,{'name':name,'account_id':com_acc,'debit':amount},{'name':name,'account_id':acc,'credit':amount})]

if journal_id.entry_posted:

move_obj.button_validate(cr, uid, [move_id], context)

move_obj.write(cr, uid, [move_id], {'line_id': lines}, context=context)

self.write(cr, uid, ids, {'account_move_id': move_id, 'state': 'approved'}, context=context)

return True

def move_line_get(self, cr, uid, expense_id, context=None):

res=[]

cur_obj = self.pool.get('res.currency')

exp = self.browse(cr, uid, expense_id, context=context)

company_currency = exp.company_id.currency_id.id

res.append({'currency_id':company_currency})

return res

 ___________________

Thanks In advance.

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/21/15, 1:52 AM
Seen: 346 times
Last updated: 12/29/15, 1:40 AM