콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
708 화면

I would like to have a computed field that shows the number of days an order is overdue.

I have created a field called x_studio_days_overdue that is an integer.

I would like to compute this field by subtracting two other fields and I would like to show the result as a number of days.

x_studio_shipping_date - scheduled_date = x_studio_days_overdue

How would I write the code to do this in the Compute section of the x_studio_days_overdue field?



Here is the code that ultimately worked:

아바타
취소
베스트 답변

Hii Daniel Murphy,


This code ensures the field x_studio_days_overdue shows the correct number of overdue days as an integer by subtracting scheduled_date from x_studio_shipping_date. If either date is missing, it defaults to 0.

from datetime import date

@api.depends('x_studio_shipping_date', 'scheduled_date')
def _compute_days_overdue(self):
for record in self:
if record.x_studio_shipping_date and record.scheduled_date:
shipping_date = fields.Date.from_string(record.x_studio_shipping_date)
scheduled_date = fields.Date.from_string(record.scheduled_date)
record.x_studio_days_overdue = (shipping_date - scheduled_date).days
else:
record.x_studio_days_overdue = 0

Let me know if you need further clarification!

Thanks,

아바타
취소
베스트 답변

What do you need that you can't get from the Scheduled Date?

아바타
취소
작성자 베스트 답변

I would like to know the number of days between when the order was scheduled to ship and when it actually shipped.  I want to be able to run reports off of this number so that I can track on-time delivery performance.

아바타
취소