Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
7858 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhấ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>
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhấ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"/>


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 2 25
1429
1
thg 7 25
1734
3
thg 6 25
990
1
thg 5 25
1746
1
thg 4 25
2300