Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
3134 Представления

Hello guys

I'm getting a datetime from a .js file. This datetime have a random time, and I want to modify it
to be 14:00:00 at first time. I have to be able to modify this time later. I'm doing it with an @api.onchange, but then I can't modify the hour. It always return to 14:00:00. 

The best way to do it I think is to execute @api.onchange only once, is it a way to do this? I've tried depends and model to, but doesn't work.

Here es my code


@api.onchange('checkin')
def _get_checkin(self):
if self.checkin:
self.checkin = self.checkin.strftime("%Y-%m-%d 14:00:00")

checkin = fields.Datetime(
"Expected-Date-Arrival",
required=True,
readonly=True,
states={"draft": [("readonly", False)]},
store=True,
)


Аватар
Отменить
Лучший ответ

On way of achieving this could be to create an additional field

field_updated = fields.Boolean(default=False)

After the on_change is called you update this field to True and if this field is True you won't update the value. So that would look something like this

@api.onchange('checkin')
def _get_checkin(self):
if not self.field_updated:
self.checkin = self.checkin.strftime("%Y-%m-%d 14:00:00")
field.field_updated = True
return True

I hope this helps

Аватар
Отменить
Related Posts Ответы Просмотры Активность
2
дек. 24
2155
1
февр. 22
3969
1
февр. 22
6875
0
нояб. 21
4410
4
янв. 20
6474