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

class Model(models.TransientModel):
_name = "add.month"

exp_month = fields.Integer(string='Expiry Months Valid')
current_date = fields.Datetime(string='Current Date')
added_date = fields.Datetime(string='End of Life Date')

When i enter the no. of months in the exp_month field, it should add in the added_date.

I can't find it.

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

This is a simple python logic you could find by googling.

You can use relativedelta library for that.

from dateutil.relativedelta import relativedelta

# Convert string date value to datetime object
current_date = fields.Datetime.from_string(self.current_date)

# Increment the added_date by given months
added_date = current_date + relativedelta(months=self.exp_month)

self.write({'added_date': added_date})


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 25
2394
1
thg 7 25
897
1
thg 8 25
1151
0
thg 5 25
1338
2
thg 4 25
3555