Skip to Content
Menu
This question has been flagged
2 Replies
2807 Views

Hello guys, in my model "Prospect.py" i have this:

    num_prospect = fields.Char(string='Prospect',compute='_compute_prospect')

    

    @api.depends('num_prospect')

    def_compute_prospect(self):

        for record in self:     

        record.num_prospect[0= record.num_prospect[0] + 1

        return record.num_prospect[0]

This is suppose to adding plus one to the value on prospect every time i create a new prospect,(eg. the first prospect it's gonna be "1", when i create a new prospect, automatacally

add 1 to that value for the value of the second prospect be "2") but these keep me giving this error: "TypeError: 'bool' object is not subscriptable", anyone can help me, pls?

Avatar
Discard
Author

But the only place i have the "num_prospect" declared is in the first line, where the type of num_prospect is char...

Author Best Answer

@api.depends('num_prospect')

def_compute_prospect(self):

    for record in self:

        last_prospect =self.search([], limit=1, order="id asc") 

        record.num_prospect =int(last_prospect.num_prospect) +1


Do this changes to the code but isn't work very well, the first to prospects i created was good, the first one with the value 1 and the second one with the value 2, but after that, all the prospects i created have the number 2 in num_prospec field. 

Avatar
Discard
Best Answer

Hi @Guilherme

Please try below code:

@api.depends('num_prospect')
def _compute_prospect(self):
for record in self:
# get the last record and add + 1 to its num_prospect
# If no records exist the num_prospect = 1 by default
last_prospect = self.search([], limit=1, order="id desc")
record.num_prospect = last_prospect and int(last_prospect.num_prospect) + 1 or 1


Hope this solves your query.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard
Author

Hi @Jainesh Shah(Aktiv Software)

Tanks for responding me and help me in my problem, so, with your code im able to create prospect's but in the num_prospect field keep printing the same number, the number 1, for example, if i create five prospects, all the five prospects have the same num_prospect, what is the number "1".

Related Posts Replies Views Activity
3
Apr 24
1024
0
May 24
46
1
Apr 24
1830
4
Sep 23
3085
2
Sep 23
5593