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

Hi,


Can anyone tell me how I can calculate on the fly the number of days a task is overdue in a QWeb report ?

I was hoping to be able to use a simple calculation and then format it to days, but even the calculation doesn't work yet.

<TD style="border-top: 1px solid black;border-bottom: 1px solid black;border-left: 1px solid black;border-right: 1px solid black;" t-if="task.date_deadline != false"><span t-esc="context_today()-task.date_deadline"/></TD>


Thanks for your help.

Seppe

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

Replace your line with

<TD style="border-top: 1px solid black;border-bottom: 1px solid black;border-left: 1px solid black;border-right: 1px solid black;" t-if="task.date_deadline != false">
    <t t-esc="(datetime.datetime.strptime(doc.date_deadline, '%Y-%m-%d') - datetime.datetime.strptime(datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d'),'%Y-%m-%d')).days"/>
</TD>
الصورة الرمزية
إهمال
أفضل إجابة

-> Create "_cal_task_duration" method in task which return difference between

task deadline and current date.

======== .py code ============

from datetime import datetime

class ProjectTask(models.Model):

    _inherit= 'project.task'

    @api.multi

    def _cal_task_duration(self):

        """ Calculate Project Duration"""

        deadline_days = 0.0

        if self.date_deadline:

            deadline_date = datetime.strptime(self.date_deadline, '%Y-%m-%d')

            deadline_days = (date.today() - deadline_date).days

        return deadline_days

======= End of .py code =======

-> Now change your Qweb template and call "_cal_task_duration" method and set it's value in "task_deadline"

and display that field in report.


<t t-set="task_deadline" t-value="task._cal_task_duration()"/>

<span t-esc="task_deadline"/>


الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
فبراير 25
1414
1
يوليو 25
1701
3
يونيو 25
947
1
مايو 25
1688
1
أبريل 25
2270