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

What is the Python error `TypeError: 'bool' object is unsubscriptable`?

By
ahmed
on 3/2/13, 6:29 AM 4,439 views

i am a beginner in eprnerp and I currently working on the implementation of the payroll module Moroccan openerp 6.0 ​​on Windows XP, so everything was a wonder until the last step where I wanted to calculate the pay slip every time I Click on the button I get this error message:

Traceback (most recent call last): File "netsvc.pyo", line 489, in dispatch File "service\web_services.pyo", line 599, in dispatch File "osv\osv.pyo", line 122, in wrapper File "osv\osv.pyo", line 176, in execute File "osv\osv.pyo", line 167, in execute_cr File "C:\Program Files\OpenERP6.0\Server\addons\syst_hr_payroll_ma\hr_payroll_ma.py", line 154, in compute_all_lines File "osv\orm.pyo", line 181, in <lambda> File "C:\Program Files\OpenERP6.0\Server\addons\syst_hr_payroll_ma\hr_payroll_ma.py", line 674, in compute_all_lines File "C:\Program Files\OpenERP6.0\Server\addons\syst_hr_payroll_ma\hr_payroll_ma.py", line 518, in get_igr TypeError: 'bool' object is unsubscriptable

And here is the line of code concern:

def get_igr(self, cr, uid, ids, montant, cotisations): #print('fonction IGR') res = {} taux=0 somme=0 salaire_net_imposable = 0 pool = pooler.get_pool(cr.dbname) id_bulletin = ids[0] bulletin = pool.get('hr.payroll_ma.bulletin').browse(cr, uid, id_bulletin) personnes = bulletin.employee_id.chargefam logement = bulletin.employee_id.logement params = self.pool.get('hr.payroll_ma.parametres') ids_params = params.search(cr, uid, []) dictionnaire = params.read(cr, uid, ids_params[0]) fraispro = montant * dictionnaire['fraispro'] / 100 if fraispro < dictionnaire['plafond']: salaire_net_imposable = montant - fraispro - cotisations - logement else : salaire_net_imposable = montant - dictionnaire['plafond'] - cotisations - logement

    objet_ir = self.pool.get('hr.payroll_ma.ir')
    id_ir = objet_ir.search(cr, uid, [])
    liste = objet_ir.read(cr, uid, id_ir, ['debuttranche', 'fintranche', 'taux', 'somme'])
    for tranche in liste:
        if(salaire_net_imposable >= tranche['debuttranche']/12) and (salaire_net_imposable < tranche['fintranche']/12):
            taux = (tranche['taux'])
            somme = (tranche['somme']/12) 

    ir_brute = (salaire_net_imposable * taux / 100) - somme
    if((ir_brute - (personnes * dictionnaire['charge'])) < 0):
        ir_net = 0
    else:
        ir_net = ir_brute - (personnes * dictionnaire['charge'])
    res = {'salaire_net_imposable':salaire_net_imposable,
         'taux':taux,
         'ir_net':ir_net,
         'credit_account_id':dictionnaire['credit_account_id'][0],
         'frais_pro' : fraispro,
         'personnes' : personnes
         }

    return res

So I apologize for the inconvenience and I hope you can help me thank you in advance

any help please ???

ahmed
on 3/2/13, 7:40 AM

It would be good if you update your question which more code instead of just showing one line.

Andreas Brueckl
on 3/5/13, 8:40 AM

agree this is done and I hope you can help me :)

ahmed
on 3/5/13, 10:11 AM

Your dictionnaire var is probabley a boolean (False or True)

Camptocamp SA
on 3/5/13, 10:17 AM

I can not see the additional code!

Andreas Brueckl
on 3/5/13, 10:19 AM

and now you can see it ??

ahmed
on 3/5/13, 10:22 AM

yes it is true this boolean variable is but I do not know where is the problem exactly, is that I should not put type variable or there yardstick method for spesifique called boolean variable

ahmed
on 3/5/13, 10:31 AM

Can you please point line 518 in the code of hr_payroll_ma.py?

Lucio
on 3/5/13, 12:24 PM

yes lucio this is the line 518 of code : 'credit_account_id':dictionnaire['credit_account_id'][0],

ahmed
on 3/5/13, 12:38 PM

What are you getting now? I can not see any updates in your question although you are constantly updating it!

Lucio
on 3/12/13, 11:20 AM

yes I know there is no update in my question I wanted ONLY FOR that another person has come to see sorry

ahmed
on 3/12/13, 11:25 AM
1
Lucio
On 3/5/13, 1:16 PM

You are defining dictionnarie within this 3 lines:

params = self.pool.get('hr.payroll_ma.parametres') 
ids_params = params.search(cr, uid, []) 
dictionnaire = params.read(cr, uid, ids_params[0])

And the error is coming from here:

dictionnaire['credit_account_id'][0]

because it seems that when accessing dictionnaire with key 'credit_account_id' you are getting False.

This is probably because the record you are reading in here:

dictionnaire = params.read(cr, uid, ids_params[0])

has no reference to an credit account.

It is weird for my that you are reading the first that appears, so I do not know how you want to solve this. If there should be a value in there or it might no be any, which value is supposed to be stored in dictionnarie in the first place...

But the explanation of why is not working, I am pretty sure that is the one above.

Good Luck!

thank you very much, I appreciate your effort to explain

ahmed
on 3/7/13, 4:52 AM
1
nazarii
On 3/2/13, 3:58 PM

You need to change this line to:

'credit_account_id':dictionnaire['credit_account_id'] and dictionnaire['credit_account_id'][0] or False,

Error occurs because dictionary returned {'credit_account_id': False}, expected {'credit_account_id': [1,2,3...]} or smth like that. Hope this will help.

0
ahmed
On 3/5/13, 5:36 AM

thank you for your help as even despite it not work :(

problem solved: the problem was: I want to access a variable 'credit_account_id' in the form of pay slip without grasping parameters in payroll so it returns the value false to me generates this error thank you to everyone who tried to help me

ahmed
on 3/13/13, 12:49 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

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

Question tools

0 follower(s)

Stats

Asked: 3/2/13, 6:29 AM
Seen: 4439 times
Last updated: 3/16/15, 8:10 AM