本文整理汇总了Python中odoo.exceptions.UserError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.UserError方法的具体用法?Python exceptions.UserError怎么用?Python exceptions.UserError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类odoo.exceptions
的用法示例。
在下文中一共展示了exceptions.UserError方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: callback_api_register
# 需要导入模块: from odoo import exceptions [as 别名]
# 或者: from odoo.exceptions import UserError [as 别名]
def callback_api_register(self):
"""
注册钉钉业务回调接口
"""
config = self.env['ir.config_parameter'].sudo()
# 回调Tag
call_back_tag = ['user_add_org']
# 生成Token
token = self.generate_random_str(16)
# 生成AESKey并进行Base64编码
aes_key = base64.b64encode(self.generate_random_str(32).encode()).decode().rstrip('=')
# 保存Token和AESKey
config.set_param('dingtalk_call_back_api_token', token)
config.set_param('dingtalk_call_back_api_aes_key', aes_key)
# 回调Url
call_back_url = request.httprequest.host_url + 'dingtalk/call_back'
try:
# 向钉钉接口发起回调接口注册请求
dingtalk = DingTalk(config.get_param('dingtalk_app_key'), config.get_param('dingtalk_app_secret'))
dingtalk.callback_api_register(call_back_tag, config.get_param('dingtalk_call_back_api_token'),
config.get_param('dingtalk_call_back_api_aes_key'), call_back_url)
except Exception as e:
raise UserError(
_('回调接口注册失败!\n\n错误原因:\n' + str(
e) + '\n\n请检查:\n(1)基本参数是否正确。\n(2)回调地址是否已注册。\n(3)Odoo服务器是否可以被外网访问。\n(4)钉钉后台权限设置是否正确。'))
示例2: export_stock_level
# 需要导入模块: from odoo import exceptions [as 别名]
# 或者: from odoo.exceptions import UserError [as 别名]
def export_stock_level(self, stock_location):
_logger.info('export stock level for %s',
stock_location.name)
import pdb; pdb.set_trace()
products = self.with_context(
location=stock_location.id).search([])
products = products.filtered('qty_available')
_logger.debug('%d products in the location',
len(products))
fname = join(EXPORTS_DIR, 'stock_level.txt')
try:
with open(fname, 'w') as fobj:
for prod in products:
fobj.write('%s\t%f\n' % (prod.name,
prod.qty_available))
except IOError:
_logger.exception(
'Error while writing to %s in %s',
'stock_level.txt', EXPORTS_DIR)
raise exceptions.UserError('unable to save file')
示例3: change_state
# 需要导入模块: from odoo import exceptions [as 别名]
# 或者: from odoo.exceptions import UserError [as 别名]
def change_state(self, new_state):
for book in self:
if book.is_allowed_transition(book.state, new_state):
book.state = new_state
else:
message = _('Moving from %s to %s is not allowd') % (book.state, new_state)
raise UserError(message)
示例4: create
# 需要导入模块: from odoo import exceptions [as 别名]
# 或者: from odoo.exceptions import UserError [as 别名]
def create(self, values):
if not self.user_has_groups('my_library.group_librarian'):
if 'manager_remarks' in values:
raise UserError(
'You are not allowed to modify '
'manager_remarks'
)
return super(LibraryBook, self).create(values)
示例5: write
# 需要导入模块: from odoo import exceptions [as 别名]
# 或者: from odoo.exceptions import UserError [as 别名]
def write(self, values):
if not self.user_has_groups('my_library.group_librarian'):
if 'manager_remarks' in values:
raise UserError(
'You are not allowed to modify '
'manager_remarks'
)
return super(LibraryBook, self).write(values)
示例6: book_rent
# 需要导入模块: from odoo import exceptions [as 别名]
# 或者: from odoo.exceptions import UserError [as 别名]
def book_rent(self):
self.ensure_one()
if self.state != 'available':
raise UserError(_('Book is not available for renting'))
rent_as_superuser = self.env['library.book.rent'].sudo()
rent_as_superuser.create({
'book_id': self.id,
'borrower_id': self.env.user.partner_id.id,
})
示例7: fetch_book_data
# 需要导入模块: from odoo import exceptions [as 别名]
# 或者: from odoo.exceptions import UserError [as 别名]
def fetch_book_data(self):
self.ensure_one()
if not self.isbn:
raise UserError("Please add ISBN number")
user_token = self.env['iap.account'].get('book_isbn')
params = {
'account_token': user_token.account_token,
'isbn_number': self.isbn
}
service_endpoint = 'http://localhost:8070'
result = jsonrpc(service_endpoint + '/get_book_data', params=params)
if result.get('status') == 'found':
self.write(self.process_result(result['data']))
return True
示例8: create
# 需要导入模块: from odoo import exceptions [as 别名]
# 或者: from odoo.exceptions import UserError [as 别名]
def create(self, vals):
# Code before create: should use the `vals` dict
if 'stage_id' in vals:
Stage = self.env['library.checkout.stage']
new_state = Stage.browse(vals['stage_id']).state
if new_state == 'open':
vals['checkout_date'] = fields.Date.today()
new_record = super().create(vals)
# Code after create: can use the `new_record` created
if new_record.state == 'done':
raise exceptions.UserError(
'Not allowed to create a checkout in the done state.')
return new_record
开发者ID:PacktPublishing,项目名称:Odoo-12-Development-Essentials-Fourth-Edition,代码行数:15,代码来源:library_checkout.py
示例9: button_send
# 需要导入模块: from odoo import exceptions [as 别名]
# 或者: from odoo.exceptions import UserError [as 别名]
def button_send(self):
import pudb; pu.db
self.ensure_one()
if not self.checkout_ids:
raise exceptions.UserError(
'Select at least one Checkout to send messages to.')
if not self.message_body:
raise exceptions.UserError(
'Write a message body to send.')
for checkout in self.checkout_ids:
checkout.message_post(
body=self.message_body,
subject=self.message_subject,
subtype='mail.mt_comment',
)
_logger.debug(
'Message on %d to followers: %s',
checkout.id,
checkout.message_follower_ids)
_logger.info(
'Posted %d messages to Checkouts: %s',
len(self.checkout_ids),
self.checkout_ids.ids,
)
return True
开发者ID:PacktPublishing,项目名称:Odoo-12-Development-Essentials-Fourth-Edition,代码行数:30,代码来源:checkout_mass_message.py
示例10: test_button_send_empty_body
# 需要导入模块: from odoo import exceptions [as 别名]
# 或者: from odoo.exceptions import UserError [as 别名]
def test_button_send_empty_body(self):
"Send button errors on empty body message"
wizard0 = self.Wizard.create({})
with self.assertRaises(exceptions.UserError) as e:
wizard0.button_send()
开发者ID:PacktPublishing,项目名称:Odoo-12-Development-Essentials-Fourth-Edition,代码行数:7,代码来源:test_checkout_mass_message.py