我目前有一个onchange函数,每次我更改用户时都可以工作,但我想知道这个函数是否可以使用OR在2个字段上工作?例如:如果在故障单中更改了用户OR状态,则将文本添加到描述字段。
@api.onchange('responsible_id' or 'state')
def _update_resolution(self):
fmt = "%Y-%m-%d %H:%M:%S %Z%z" #datetime format
user = self.env.user
context_tz = pytz.utc
if (user.partner_id.tz):
context_tz = pytz.timezone(user.partner_id.tz)
now_utc = datetime.datetime.now(pytz.utc)
now_user_dt = now_utc.astimezone(context_tz)
resolution = ""
resolution_format = "** {0:s}: {1:s}:-\n{2:s}"
if (self.resolution):
resolution = self.resolution
resolution_format = "** {0:s}: {1:s}:-\n\n\n{2:s}"
self.resolution = resolution_format.format(user.name, str(now_user_dt.strftime(fmt)), resolution)
没有收到任何错误但是没有按预期工作
答案 0 :(得分:2)
尝试以下,
@api.onchange('responsible_id','state')
def _update_resolution(self):
fmt = "%Y-%m-%d %H:%M:%S %Z%z" #datetime format
user = self.env.user
context_tz = pytz.utc
if (user.partner_id.tz):
context_tz = pytz.timezone(user.partner_id.tz)
now_utc = datetime.datetime.now(pytz.utc)
now_user_dt = now_utc.astimezone(context_tz)
resolution = ""
resolution_format = "** {0:s}: {1:s}:-\n{2:s}"
if (self.resolution):
resolution = self.resolution
resolution_format = "** {0:s}: {1:s}:-\n\n\n{2:s}"
self.resolution = resolution_format.format(user.name, str(now_user_dt.strftime(fmt)), resolution)