Skip to Content
मेन्यू
This question has been flagged
2 Replies
1416 Views

I created a custom app to add some fields to the project module (see code below).
I can succesfully load the app but when I open the project task I get the following error. How to resolve this?


-------- error -----------
AttributeError: 'project.task' object has no attribute '_compute_progress'

The above server error caused the following client error:

null


-------- code -----------

from odoo import fields, models, api


@api.depends("planned_effort", "realized", "kanban_state")

def _compute_progress(self):

    for record in self: 

        if record['kanban_state'] == 'done':

            record['progressed'] = 100

        elif record['planned_effort'] > 0: 

            record['progressed'] = round(record['realized'] / record['planned_effort'] * 100)

        else:

            record['progressed'] = 0


class ClassAdditionalFields(models.Model):

   _inherit = 'project.task'

   planned_effort = fields.Integer(string='Planned effort (hr)', default=1)

   realized = fields.Integer(string='Realized (hr)', default=0)

   progressed = fields.Integer(string='Task progress', compute="_compute_progress", readonly=True)

 

Avatar
Discard
Best Answer

Hi,

This is because you have defined the compute function outside of your class definition as global. Try to define your function under the class definition (see the code below) , this will solve this issue

class ClassAdditionalFields(models.Model):
_inherit = 'project.task'

planned_effort = fields.Integer(string='Planned effort (hr)', default=1)
realized = fields.Integer(string='Realized (hr)', default=0)
progressed = fields.Integer(string='Task progress', compute="_compute_progress", readonly=True)

@api.depends("planned_effort", "realized", "kanban_state")
def _compute_progress(self):
for record in self:
if record['kanban_state'] == 'done':
record['progressed'] = 100
elif record['planned_effort'] > 0:
record['progressed'] = round(record['realized'] / record['planned_effort'] * 100)
else:
record['progressed'] = 0

Hope this will help you

Thanks

Avatar
Discard
Author Best Answer

Hi,

It worked! Thank you. 
Had the @api before under the class definition but forgot to have the same indent as the fields above. 
This indent together with placing the @api under the class definition made the difference.

Avatar
Discard
Related Posts Replies Views Activity
3
अग॰ 25
2835
1
मई 25
2771
1
अप्रैल 25
3738
1
अप्रैल 25
4608
1
अप्रैल 25
2042