本文整理汇总了Python中openerp.exceptions.ValidationError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.ValidationError方法的具体用法?Python exceptions.ValidationError怎么用?Python exceptions.ValidationError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openerp.exceptions
的用法示例。
在下文中一共展示了exceptions.ValidationError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from openerp import exceptions [as 别名]
# 或者: from openerp.exceptions import ValidationError [as 别名]
def create(self, vals):
product_tmpl = self.env['product.template'].browse(
vals.get('product_tmpl_id')).exists()
if product_tmpl:
default_val_ids = product_tmpl.attribute_line_ids.filtered(
lambda l: l.default_val).mapped('default_val').ids
value_ids = vals.get('value_ids')
if value_ids:
default_val_ids += value_ids[0][2]
valid_conf = product_tmpl.validate_configuration(
default_val_ids, final=False)
# TODO: Remove if cond when PR with raise error on github is merged
if not valid_conf:
raise ValidationError(
_('Default values provided generate an invalid '
'configuration')
)
vals.update({'value_ids': [(6, 0, default_val_ids)]})
return super(ProductConfigSession, self).create(vals)
示例2: unique_attribute
# 需要导入模块: from openerp import exceptions [as 别名]
# 或者: from openerp.exceptions import ValidationError [as 别名]
def unique_attribute(self):
if len(self.cfg_session_id.custom_value_ids.filtered(
lambda x: x.attribute_id == self.attribute_id)) > 1:
raise ValidationError(
_("Configuration cannot have the same value inserted twice")
)
# @api.constrains('cfg_session_id.value_ids')
# def custom_only(self):
# """Verify that the attribute_id is not present in vals as well"""
# import ipdb;ipdb.set_trace()
# if self.cfg_session_id.value_ids.filtered(
# lambda x: x.attribute_id == self.attribute_id):
# raise ValidationError(
# _("Configuration cannot have a selected option and a custom "
# "value with the same attribute")
# )
示例3: validate_custom_val
# 需要导入模块: from openerp import exceptions [as 别名]
# 或者: from openerp.exceptions import ValidationError [as 别名]
def validate_custom_val(self, val):
""" Pass in a desired custom value and ensure it is valid.
Probaly should check type, etc, but let's assume fine for the moment.
"""
self.ensure_one()
if self.custom_type in ('int', 'float'):
minv = self.min_val
maxv = self.max_val
val = literal_eval(val)
if minv and maxv and (val < minv or val > maxv):
raise ValidationError(
_("Selected custom value '%s' must be between %s and %s"
% (self.name, self.min_val, self.max_val))
)
elif minv and val < minv:
raise ValidationError(
_("Selected custom value '%s' must be at least %s" %
(self.name, self.min_val))
)
elif maxv and val > maxv:
raise ValidationError(
_("Selected custom value '%s' must be lower than %s" %
(self.name, self.max_val + 1))
)
示例4: _check_ident_num
# 需要导入模块: from openerp import exceptions [as 别名]
# 或者: from openerp.exceptions import ValidationError [as 别名]
def _check_ident_num(self):
"""
This function checks the content of the identification fields: Type of
document and number cannot be empty.
There are two document types that permit letters in the identification
field: 21 and 41. The rest does not permit any letters
@return: void
"""
for item in self:
if item.doctype is not 1:
if item.xidentification is not False and \
item.doctype != 21 and \
item.doctype != 41:
if re.match("^[0-9]+$", item.xidentification) is None:
msg = _('Error! Identification number can only '
'have numbers')
raise exceptions.ValidationError(msg)
示例5: _check_names
# 需要导入模块: from openerp import exceptions [as 别名]
# 或者: from openerp.exceptions import ValidationError [as 别名]
def _check_names(self):
"""
Double check: Although validation is checked within the frontend (xml)
we check it again to get sure
"""
if self.is_company is True:
if self.personType is 1:
if self.x_name1 is False or self.x_name1 == '':
msg = _('Error! Please enter the persons name')
raise exceptions.ValidationError(msg)
elif self.personType is 2:
if self.companyName is False:
msg = _('Error! Please enter the companys name')
raise exceptions.ValidationError(msg)
elif self.type == 'delivery':
if self.pos_name is False or self.pos_name == '':
msg = _('Error! Please enter the persons name')
raise exceptions.ValidationError(msg)
else:
if self.x_name1 is False or self.x_name1 == '':
msg = _('Error! Please enter the name of the person')
raise exceptions.ValidationError(msg)
示例6: _check_librarian_not_in_asstlibrarian
# 需要导入模块: from openerp import exceptions [as 别名]
# 或者: from openerp.exceptions import ValidationError [as 别名]
def _check_librarian_not_in_asstlibrarian(self):
for r in self:
if r.librarian_id in r.asstlibrarian_id:
raise exceptions.ValidationError("An assistant librarian can't be a librarian")
示例7: create
# 需要导入模块: from openerp import exceptions [as 别名]
# 或者: from openerp.exceptions import ValidationError [as 别名]
def create(self, values):
_logger.info('wx.corpuser create >>> %s'%str(values))
if not (values.get('weixinid', '') or values.get('mobile', '') or values.get('email', '') ):
raise ValidationError('??????????????????')
from_subscribe = False
if '_from_subscribe' in values:
from_subscribe = True
values.pop('_from_subscribe')
obj = super(wx_corpuser, self).create(values)
if not from_subscribe:
arg = {}
for k,v in values.items():
if v!=False and k in ['mobile', 'email', 'weixinid', 'gender']:
arg[k] = v
arg['department'] = 1
if 'weixinid' in arg:
arg['weixin_id'] = arg.pop('weixinid')
corp_client.client.user.create(values['userid'], values['name'], **arg)
return obj
示例8: send_signal_to_pabiweb
# 需要导入模块: from openerp import exceptions [as 别名]
# 或者: from openerp.exceptions import ValidationError [as 别名]
def send_signal_to_pabiweb(self, signal, comment=''):
alfresco = self._get_alfresco_connect()
if alfresco is False:
return False
arg = {
'action': signal,
'by': self.env.user.login,
'comment': comment,
}
result = False
if self.is_employee_advance:
arg.update({'avNo': self.number})
result = alfresco.brw.action(arg)
else:
arg.update({'exNo': self.number})
result = alfresco.use.action(arg)
if not result['success']:
raise ValidationError(
_("Can't send data to PabiWeb : %s" % (result['message'],))
)
return result
示例9: send_comment_to_pabiweb
# 需要导入模块: from openerp import exceptions [as 别名]
# 或者: from openerp.exceptions import ValidationError [as 别名]
def send_comment_to_pabiweb(self, status, status_th, comment):
alfresco = self._get_alfresco_connect()
if alfresco is False:
return False
arg = {
'by': self.env.user.login,
'task': 'Finance',
'task_th': u'???????',
'status': status,
'status_th': status_th,
'comment': comment,
}
result = False
if self.is_employee_advance:
arg.update({'avNo': self.number})
result = alfresco.brw.history(arg)
else:
arg.update({'exNo': self.number})
result = alfresco.use.history(arg)
if not result['success']:
raise ValidationError(
_("Can't send data to PabiWeb : %s" % (result['message'],))
)
return result
示例10: _send_comment_onchange_date_value
# 需要导入模块: from openerp import exceptions [as 别名]
# 或者: from openerp.exceptions import ValidationError [as 别名]
def _send_comment_onchange_date_value(self):
try:
for voucher in self:
if not voucher.date_value:
continue
status = u'Payment Approved'
status_th = u'???????????'
comment = u'??????????/??? %s' % (voucher.date_value,)
for voucher in self:
for line in voucher.line_ids:
exp = line.move_line_id.invoice.expense_id
if not exp:
continue
exp.send_comment_to_pabiweb(status,
status_th,
comment)
except Exception, e:
self._cr.rollback()
raise ValidationError(str(e))
return
示例11: action_done
# 需要导入模块: from openerp import exceptions [as 别名]
# 或者: from openerp.exceptions import ValidationError [as 别名]
def action_done(self):
for rec in self:
assets = rec.request_asset_ids.mapped('asset_id')
assets.validate_asset_to_request()
if self.env.user != rec.approve_user_id:
raise ValidationError(
_('Only %s can approve this document!') %
(rec.approve_user_id.name,))
for line in rec.request_asset_ids:
line.asset_id.write({
'doc_request_id': rec.id,
'date_request': rec.date_request,
'responsible_user_id': rec.responsible_user_id.id,
'location_id': line.location_id.id,
'room': line.room,
})
self.write({'state': 'done'})
示例12: write
# 需要导入模块: from openerp import exceptions [as 别名]
# 或者: from openerp.exceptions import ValidationError [as 别名]
def write(self, vals):
Status = self.env['account.asset.status']
# Status follow state
if 'state' in vals and vals.get('state', False):
if vals.get('state') == 'close':
vals['status'] = Status.search([('code', '=', 'expire')]).id
if vals.get('state') == 'open':
vals['status'] = Status.search([('code', '=', 'normal')]).id
if vals.get('state') == 'draft':
vals['status'] = Status.search([('code', '=', 'cancel')]).id
# For removed, the state will be set in remove wizard
# Validate status change must be within status map
elif 'status' in vals and vals.get('status', False):
status = Status.browse(vals.get('status'))
for asset in self:
if status.map_state != asset.state:
raise ValidationError(_('Invalid change of asset status'))
return super(AccountAsset, self).write(vals)
示例13: create
# 需要导入模块: from openerp import exceptions [as 别名]
# 或者: from openerp.exceptions import ValidationError [as 别名]
def create(self, vals):
# Case Parent Assets, AIT, AUC, ATM
type = vals.get('type', False)
ptype = vals.get('parent_type', False)
if ptype and type == 'view':
sequence_code = 'parent.asset.%s' % (ptype)
vals['name'] = self.env['ir.sequence'].next_by_code(sequence_code)
if vals.get('code', '/') == '/':
# Normal Case
product_id = vals.get('product_id', False)
if product_id:
product = self.env['product.product'].browse(product_id)
sequence = product.sequence_id
if not sequence:
raise ValidationError(
_('No asset sequence setup for selected product!'))
vals['code'] = self.env['ir.sequence'].next_by_id(sequence.id)
asset = super(AccountAsset, self).create(vals)
asset.update_related_dimension(vals)
# Init Salvage Value from Category
if self._context.get('create_asset_from_move_line', False):
if not asset.profile_id.no_depreciation:
asset.salvage_value = asset.profile_id.salvage_value
return asset
示例14: _move_budget_check
# 需要导入模块: from openerp import exceptions [as 别名]
# 或者: from openerp.exceptions import ValidationError [as 别名]
def _move_budget_check(self):
Budget = self.env['account.budget']
AnalyticLine = self.env['account.analytic.line']
for move in self:
if move.state == 'posted':
analytic_lines = AnalyticLine.search([
('move_id', 'in', move.line_id._ids)
])
if not analytic_lines:
continue
doc_date = move.date
doc_lines = Budget.convert_lines_to_doc_lines(analytic_lines)
res = Budget.post_commit_budget_check(doc_date, doc_lines)
if not res['budget_ok']:
raise ValidationError(res['message'])
return True
示例15: _validate_account_user_type_vs_org
# 需要导入模块: from openerp import exceptions [as 别名]
# 或者: from openerp.exceptions import ValidationError [as 别名]
def _validate_account_user_type_vs_org(self):
"""
* Profit & Loss must have org_id
* Balance Sheet must not have org_id
"""
error1 = _('%s is Balance Sheet\nOrg is NOT required!')
error2 = _('%s is Profit & Loss\nOrg is required!')
for move_line in self:
err_msg = False
report_type = move_line.account_id.user_type.report_type
# 1) Balance Sheet but have Org
if report_type in ('asset', 'liability') and move_line.org_id:
err_msg = error1 % (move_line.account_id.name_get()[0][1],)
# 2) Profit & Loss but no Org
if report_type not in ('asset', 'liability') and \
not move_line.org_id:
err_msg = error2 % (move_line.account_id.name_get()[0][1],)
if err_msg:
raise ValidationError(err_msg)