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

I have a boolean field called x_studio_overdue

I would like to make this a calculated field where the value is True if the field x_studio_shipping_date is greater than the field scheduled_date

x_studio_shipping_date is a Date field type

scheduled_date is a Datetime field type

 

Here is the code that I created that didn't work:

for record in self:

    ship_date = self.x_studio_shipping_date.strftime('%Y-%m-%d')

    schedule_date = self.scheduled_date.strftime('%Y-%m-%d')

        if ship_date > schedule_date

        record['x_studio_overdue'] = True

        else record['x_studio_overdue'] = False

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

I have input the code as shown below, and it is working.  Thanks for your help!

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,


Set x_studio_shipping_date and scheduled_date as dependencies and in the compute add the below code:

for record in self:

    if record.x_studio_shipping_date and record.scheduled_date:

    ship_date = record.x_studio_shipping_date

    schedule_date = record.scheduled_date.date()

    record['x_studio_overdue'] = ship_date > schedule_date

else:

    record['x_studio_overdue'] = False

Regards

Ảnh đại diện
Huỷ bỏ