تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
1424 أدوات العرض

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)

 

الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

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.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
3
أغسطس 25
2836
1
مايو 25
2776
1
أبريل 25
3742
1
أبريل 25
4612
1
أبريل 25
2045