Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odgovori
7822 Prikazi

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
Opusti
Best Answer

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
Opusti
Best Answer

-> 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
Opusti
Related Posts Odgovori Prikazi Aktivnost
1
feb. 25
1420
1
jul. 25
1710
3
jun. 25
974
1
maj 25
1704
1
apr. 25
2280