İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
7846 Görünümler

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

Avatar
Vazgeç
En İyi Yanıt

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>
Avatar
Vazgeç
En İyi Yanıt

-> 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"/>


Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Şub 25
1423
1
Tem 25
1723
3
Haz 25
983
1
May 25
1726
1
Nis 25
2290