Odoo Help

1

QWeb report : calculate number of days late for task deadlines

By
Seppe De Roeck
on 1/3/16, 4:58 PM 680 views

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

1
Jainesh Shah
On 6/9/17, 8:19 AM

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


0
Jusab Sida (jsi)
On 6/9/17, 9:50 AM

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>

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 1/3/16, 4:58 PM
Seen: 680 times
Last updated: 6/9/17, 9:50 AM