當前位置: 首頁>>代碼示例>>Python>>正文


Python exceptions.UserError方法代碼示例

本文整理匯總了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)釘釘後台權限設置是否正確。')) 
開發者ID:ocubexo,項目名稱:odoo-dingtalk-connector,代碼行數:27,代碼來源:res_config_settings.py

示例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') 
開發者ID:PacktPublishing,項目名稱:Odoo-11-Development-Coobook-Second-Edition,代碼行數:22,代碼來源:models.py

示例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) 
開發者ID:PacktPublishing,項目名稱:Odoo-12-Development-Cookbook-Third-Edition,代碼行數:9,代碼來源:library_book.py

示例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) 
開發者ID:PacktPublishing,項目名稱:Odoo-12-Development-Cookbook-Third-Edition,代碼行數:10,代碼來源:library_book.py

示例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) 
開發者ID:PacktPublishing,項目名稱:Odoo-12-Development-Cookbook-Third-Edition,代碼行數:10,代碼來源:library_book.py

示例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,
        }) 
開發者ID:PacktPublishing,項目名稱:Odoo-12-Development-Cookbook-Third-Edition,代碼行數:11,代碼來源:library_book.py

示例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 
開發者ID:PacktPublishing,項目名稱:Odoo-12-Development-Cookbook-Third-Edition,代碼行數:17,代碼來源:library_book.py

示例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


注:本文中的odoo.exceptions.UserError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。