本文整理匯總了Python中openerp.osv.osv.except_osv方法的典型用法代碼示例。如果您正苦於以下問題:Python osv.except_osv方法的具體用法?Python osv.except_osv怎麽用?Python osv.except_osv使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類openerp.osv.osv
的用法示例。
在下文中一共展示了osv.except_osv方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: action_grant_badge
# 需要導入模塊: from openerp.osv import osv [as 別名]
# 或者: from openerp.osv.osv import except_osv [as 別名]
def action_grant_badge(self, cr, uid, ids, context=None):
"""Wizard action for sending a badge to a chosen user"""
badge_user_obj = self.pool.get('gamification.badge.user')
for wiz in self.browse(cr, uid, ids, context=context):
if uid == wiz.user_id.id:
raise osv.except_osv(_('Warning!'), _('You can not grant a badge to yourself'))
#create the badge
values = {
'user_id': wiz.user_id.id,
'sender_id': uid,
'badge_id': wiz.badge_id.id,
'comment': wiz.comment,
}
badge_user = badge_user_obj.create(cr, uid, values, context=context)
result = badge_user_obj._send_badge(cr, uid, badge_user, context=context)
return result
示例2: _check_domain_validity
# 需要導入模塊: from openerp.osv import osv [as 別名]
# 或者: from openerp.osv.osv import except_osv [as 別名]
def _check_domain_validity(self, cr, uid, ids, context=None):
# take admin as should always be present
superuser = self.pool['res.users'].browse(cr, uid, SUPERUSER_ID, context=context)
for definition in self.browse(cr, uid, ids, context=context):
if definition.computation_mode not in ('count', 'sum'):
continue
obj = self.pool[definition.model_id.model]
try:
domain = safe_eval(definition.domain, {'user': superuser})
# demmy search to make sure the domain is valid
obj.search(cr, uid, domain, context=context, count=True)
except (ValueError, SyntaxError), e:
msg = e.message or (e.msg + '\n' + e.text)
raise osv.except_osv(_('Error!'),_("The domain for the definition %s seems incorrect, please check it.\n\n%s" % (definition.name, msg)))
return True
示例3: write
# 需要導入模塊: from openerp.osv import osv [as 別名]
# 或者: from openerp.osv.osv import except_osv [as 別名]
def write(self, cr, uid, ids, vals, context=None):
"""Overwrite the write method to update the last_update field to today
If the current value is changed and the report frequency is set to On
change, a report is generated
"""
if context is None:
context = {}
vals['last_update'] = fields.date.today()
result = super(gamification_goal, self).write(cr, uid, ids, vals, context=context)
for goal in self.browse(cr, uid, ids, context=context):
if goal.state != "draft" and ('definition_id' in vals or 'user_id' in vals):
# avoid drag&drop in kanban view
raise osv.except_osv(_('Error!'), _('Can not modify the configuration of a started goal'))
if vals.get('current'):
if 'no_remind_goal' in context:
# new goals should not be reported
continue
if goal.challenge_id and goal.challenge_id.report_message_frequency == 'onchange':
self.pool.get('gamification.challenge').report_progress(cr, SUPERUSER_ID, goal.challenge_id, users=[goal.user_id], context=context)
return result
示例4: getDiff
# 需要導入模塊: from openerp.osv import osv [as 別名]
# 或者: from openerp.osv.osv import except_osv [as 別名]
def getDiff(self, cr, uid, v1, v2, context=None):
history_pool = self.pool.get('blog.post.history')
text1 = history_pool.read(cr, uid, [v1], ['content'])[0]['content']
text2 = history_pool.read(cr, uid, [v2], ['content'])[0]['content']
line1 = line2 = ''
if text1:
line1 = text1.splitlines(1)
if text2:
line2 = text2.splitlines(1)
if (not line1 and not line2) or (line1 == line2):
raise osv.except_osv(_('Warning!'), _('There are no changes in revisions.'))
diff = difflib.HtmlDiff()
return diff.make_table(line1, line2, "Revision-%s" % (v1), "Revision-%s" % (v2), context=True)
示例5: get_diff
# 需要導入模塊: from openerp.osv import osv [as 別名]
# 或者: from openerp.osv.osv import except_osv [as 別名]
def get_diff(self, cr, uid, context=None):
if context is None:
context = {}
history = self.pool.get('blog.post.history')
ids = context.get('active_ids', [])
diff = ""
if len(ids) == 2:
if ids[0] > ids[1]:
diff = history.getDiff(cr, uid, ids[1], ids[0])
else:
diff = history.getDiff(cr, uid, ids[0], ids[1])
elif len(ids) == 1:
old = history.browse(cr, uid, ids[0])
nids = history.search(cr, uid, [('post_id', '=', old.post_id.id)])
nids.sort()
diff = history.getDiff(cr, uid, ids[0], nids[-1])
else:
raise osv.except_osv(_('Warning!'), _('You need to select minimum one or maximum two history revisions!'))
return diff
示例6: action_cancel
# 需要導入模塊: from openerp.osv import osv [as 別名]
# 或者: from openerp.osv.osv import except_osv [as 別名]
def action_cancel(self, cr, uid, ids, context=None):
pick_obj = self.pool.get('stock.picking')
for invoice in self.browse(cr, uid, ids, context=context):
if invoice.picking_id.state == 'done':
new_picking = self.create_returns(cr, uid, invoice, context=context)
if pick_obj.browse(cr, uid, new_picking, context=context).state != 'done':
raise osv.except_osv('Error!', _('You cannot cancel an invoice that has a picking without reversing.'))
invoice.write({'picking_id': False}, context=context)
return super(account_invoice, self).action_cancel(cr, uid, ids, context=context)
# class sale_configuration(osv.TransientModel):
# _inherit = 'sale.config.settings'
#
# _columns = {
# 'picking_automatic': fields.boolean('Create picking automatically', implied_group='account_invoice_picking.group_picking_automatic', help='Allows create picking automatically to validate invoice'),
# }
示例7: action_asignado
# 需要導入模塊: from openerp.osv import osv [as 別名]
# 或者: from openerp.osv.osv import except_osv [as 別名]
def action_asignado(self):
if not self.asignacion:
raise osv.except_osv(('Error'),('Debes llenar el campo: asignado a'))
self.fecha_asignado_a=datetime.today()
diferencia=self.calcular_dias(self.fecha_recibido, self.fecha_asignado_a)
self.dia_asignado_a=diferencia.days
self.state='asignado'
self.enviar_mensaje_status()
self.message_subscribe_users(user_ids=[self.asignacion.id])
# PARA ENVIAR E-MAIL
cuerpo_mensaje = """Se le ha asignado una Ticket en Help Desk:<br>
Codigo: %s,<br>
Asunto: %s,<br>
Descripcion: %s,<br> """ % (self.codigo, self.denominacion, self.descripcion)
const_mail = {'email_from' : self.solicitante_id.email,
'email_to' : self.asignacion.login,
#'partner_ids' : [(0,0,{'res_partner_id':self.asignacion.partner_id, 'mail_message_id': ids_mail})],
'subject' : "Re: %s" % self.codigo,
'body_html' : cuerpo_mensaje}
ids_mail = self.env['mail.mail'].create(const_mail).send()
return True
# FIN DE EMAIL
示例8: act_update_automatically
# 需要導入模塊: from openerp.osv import osv [as 別名]
# 或者: from openerp.osv.osv import except_osv [as 別名]
def act_update_automatically(self, cr, uid, ids, context=None):
# _logger.warning("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
# this = self.browse(cr, uid, ids)[0]
# lang_name = self._get_lang_name(cr, uid, 'vi_VN')
# _logger.warning(lang_name)
# _logger.warning(this.lang)
try:
_logger.warning("<<<<<<<<<<<<<<<<<<<< Syn <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
vn_ids = self.pool['res.lang'].search(cr, uid,[('iso_code','=','vi_VN')],context={})
if len(vn_ids) == 0:
raise osv.except_osv(_('Error!'), _('No language found'))
return {'type': 'ir.actions.act_window_close'}
vn_string = self.pool['res.lang'].read(cr, uid, vn_ids, ['name'],context={})[0]
_logger.warning(vn_string)
_logger.warning("<<<<<<<<<<<<<<<<<<<< Syn <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
buf = cStringIO.StringIO()
tools.trans_export('vi_VN', ['all'], buf, 'csv', cr)
tools.trans_load_data(cr, buf, 'csv', 'vi_VN', lang_name=vn_string['name'])
buf.close()
except:
return {'type': 'ir.actions.act_window_close'}
return {'type': 'ir.actions.act_window_close'}
示例9: action_button_send_doc
# 需要導入模塊: from openerp.osv import osv [as 別名]
# 或者: from openerp.osv.osv import except_osv [as 別名]
def action_button_send_doc(self):
attachment = self.env['ir.attachment']
doc_ids = attachment.search(
[('res_model', '=', 'purchase.contract'),
('res_id', '=', self.id)])
if doc_ids:
Employees = self.env["hr.employee"]
Emp = Employees.search([['user_id', '=', self._uid]],
limit=1)
if Emp:
self.send_doc_uid = Emp.id
else:
self.send_doc_uid = SUPERUSER_ID
self.send_doc_date = datetime.datetime.now(timezone('UTC'))
if self.verify_date:
self.state = CLOSE
else:
self.state = SEND
else:
raise osv.except_osv(_(u'Error!!'),
_('Please attachment(s) contract.'))
return True
示例10: action_button_close
# 需要導入模塊: from openerp.osv import osv [as 別名]
# 或者: from openerp.osv.osv import except_osv [as 別名]
def action_button_close(self):
if self.collateral_remand_date and self.collateral_remand_date:
Employees = self.env["hr.employee"]
Emp = Employees.search([['user_id', '=', self._uid]],
limit=1)
if Emp:
self.close_uid = Emp.id
else:
self.close_uid = SUPERUSER_ID
self.close_date = datetime.datetime.now(timezone('UTC'))
self.state = CLOSE
else:
raise osv.except_osv(
_(u'Error!!'),
_("""Please enter
\"Collateral Received Date\" and
\"Collateral Remand Date\"."""))
return True
示例11: check_access_rule
# 需要導入模塊: from openerp.osv import osv [as 別名]
# 或者: from openerp.osv.osv import except_osv [as 別名]
def check_access_rule(self, cr, uid, ids, operation, context=None):
""" Add Access rules of mail.message for non-employee user:
- read:
- raise if the type is comment and subtype NULL (internal note)
"""
if uid != SUPERUSER_ID:
group_ids = self.pool.get('res.users').browse(cr, uid, uid, context=context).groups_id
group_user_id = self.pool.get("ir.model.data").get_object_reference(cr, uid, 'base', 'group_public')[1]
if group_user_id in [group.id for group in group_ids]:
cr.execute('SELECT id FROM "%s" WHERE website_published IS FALSE AND id = ANY (%%s)' % (self._table), (ids,))
if cr.fetchall():
raise osv.except_osv(
_('Access Denied'),
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') % (self._description, operation))
return super(MailMessage, self).check_access_rule(cr, uid, ids=ids, operation=operation, context=context)
示例12: action_apply
# 需要導入模塊: from openerp.osv import osv [as 別名]
# 或者: from openerp.osv.osv import except_osv [as 別名]
def action_apply(self, cr, uid, ids, context=None):
error_msg = self.get_error_messages(cr, uid, ids, context=context)
if error_msg:
raise osv.except_osv(_('Contacts Error'), "\n\n".join(error_msg))
for wizard_user in self.browse(cr, SUPERUSER_ID, ids, context):
portal = wizard_user.wizard_id.portal_id
user = self._retrieve_user(cr, SUPERUSER_ID, wizard_user, context)
if wizard_user.partner_id.email != wizard_user.email:
wizard_user.partner_id.write({'email': wizard_user.email})
if wizard_user.in_portal:
# create a user if necessary, and make sure it is in the portal group
if not user:
user = self._create_user(cr, SUPERUSER_ID, wizard_user, context)
if (not user.active) or (portal not in user.groups_id):
user.write({'active': True, 'groups_id': [(4, portal.id)]})
# prepare for the signup process
user.partner_id.signup_prepare()
self._send_email(cr, uid, wizard_user, context)
wizard_user.refresh()
else:
# remove the user (if it exists) from the portal group
if user and (portal in user.groups_id):
# if user belongs to portal only, deactivate it
if len(user.groups_id) <= 1:
user.write({'groups_id': [(3, portal.id)], 'active': False})
else:
user.write({'groups_id': [(3, portal.id)]})
示例13: _assert
# 需要導入模塊: from openerp.osv import osv [as 別名]
# 或者: from openerp.osv.osv import except_osv [as 別名]
def _assert(self, condition, error_message, context=None):
"""Raise a user error with the given message if condition is not met.
The error_message should have been translated with _().
"""
if not condition:
raise osv.except_osv(_('Sharing access cannot be created.'), error_message)
示例14: go_step_1
# 需要導入模塊: from openerp.osv import osv [as 別名]
# 或者: from openerp.osv.osv import except_osv [as 別名]
def go_step_1(self, cr, uid, ids, context=None):
wizard_data = self.browse(cr,uid,ids,context)[0]
if wizard_data.user_type == 'emails' and not self.has_email(cr, uid, context=context):
raise osv.except_osv(_('No email address configured'),
_('You must configure your email address in the user preferences before using the Share button.'))
model, res_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'share', 'action_share_wizard_step1')
action = self.pool[model].read(cr, uid, [res_id], context=context)[0]
action['res_id'] = ids[0]
action.pop('context', '')
return action
示例15: send_invite_email
# 需要導入模塊: from openerp.osv import osv [as 別名]
# 或者: from openerp.osv.osv import except_osv [as 別名]
def send_invite_email(self, cr, uid, wizard_data, context=None):
# TDE Note: not updated because will disappear
message_obj = self.pool.get('mail.message')
notification_obj = self.pool.get('mail.notification')
user = self.pool.get('res.users').browse(cr, UID_ROOT, uid)
if not user.email:
raise osv.except_osv(_('Email Required'), _('The current user must have an email address configured in User Preferences to be able to send outgoing emails.'))
# TODO: also send an HTML version of this mail
for result_line in wizard_data.result_line_ids:
email_to = result_line.user_id.email
if not email_to:
continue
subject = _('Invitation to collaborate about %s') % (wizard_data.record_name)
body = _("Hello,\n\n")
body += _("I have shared %s (%s) with you!\n\n") % (wizard_data.record_name, wizard_data.name)
if wizard_data.message:
body += "%s\n\n" % (wizard_data.message)
if result_line.newly_created:
body += _("The documents are not attached, you can view them online directly on my Odoo server at:\n %s\n\n") % (result_line.share_url)
body += _("These are your credentials to access this protected area:\n")
body += "%s: %s" % (_("Username"), result_line.user_id.login) + "\n"
body += "%s: %s" % (_("Password"), result_line.password) + "\n"
body += "%s: %s" % (_("Database"), cr.dbname) + "\n"
body += _("The documents have been automatically added to your subscriptions.\n\n")
body += '%s\n\n' % ((user.signature or ''))
body += "--\n"
body += _("Odoo is a powerful and user-friendly suite of Business Applications (CRM, Sales, HR, etc.)\n"
"It is open source and can be found on https://www.odoo.com.")
msg_id = message_obj.schedule_with_attach(cr, uid, user.email, [email_to], subject, body, model='', context=context)
notification_obj.create(cr, uid, {'user_id': result_line.user_id.id, 'message_id': msg_id}, context=context)