コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
7267 ビュー

i have integer field and date field

i want when user set any number in integer field added this value 

to date field 

EX: if user add 3 days and field date is 22/04/2018

the date will be 25/04/2018

any solution to fix it when i don't know what is the integer value ?? 

アバター
破棄
最善の回答

Hi,

Write and onchange function for the integer field and using the time Delta you can add this integer to the date.

Suppose if you have a date field date_1 then in on change of the integer field field_1 add the integer to date by timedelta.

In on change of field_1,


New_date = date_1 +timedelta(days=self.field_1)


Thanks

アバター
破棄
最善の回答

Hi,

You can write as following:

@api.onchange('integer_field')
def onchange_next_order_date(self):
	if self.date_field : 
		next_order_d1_obj = datetime.datetime.strptime(self.date_field, "%Y-%m-%d")
		next_date = next_order_d1_obj + datetime.timedelta(days=self.integer_field)
		self.date_field  = next_date.strftime("%Y-%m-%d")

Thanks



アバター
破棄
関連投稿 返信 ビュー 活動
2
3月 22
3483
2
5月 21
4034
2
1月 24
2670
2
6月 22
4601
2
6月 18
6142