跳至內容
選單
此問題已被標幟
1 回覆
7854 瀏覽次數

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.

頭像
捨棄
最佳答案

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})


頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
8月 25
2309
1
7月 25
830
1
8月 25
1150
0
5月 25
1281
2
4月 25
3493