是否可以将 onchange 与 2 个字段一起使用? -Odoo 8
Is it possible to use onchange with 2 fields? -Odoo 8
我目前有一个 onchange 函数,每次我更改用户时它都会起作用,但我想知道这个函数是否可以使用 OR 在 2 个字段上起作用?例如:如果在工单中更改了用户或状态,则将文本添加到描述字段。
@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)
没有收到任何错误,但它没有像我预期的那样工作
尝试关注,
@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)
我目前有一个 onchange 函数,每次我更改用户时它都会起作用,但我想知道这个函数是否可以使用 OR 在 2 个字段上起作用?例如:如果在工单中更改了用户或状态,则将文本添加到描述字段。
@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)
没有收到任何错误,但它没有像我预期的那样工作
尝试关注,
@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)