Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1 Responder
7863 Visualizações

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.

Avatar
Cancelar
Melhor resposta

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


Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
2
ago. 25
2332
1
jul. 25
852
1
ago. 25
1150
0
mai. 25
1316
2
abr. 25
3509