本文整理汇总了Python中tools.ustr函数的典型用法代码示例。如果您正苦于以下问题:Python ustr函数的具体用法?Python ustr怎么用?Python ustr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ustr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: email_send
def email_send(self, cr, uid, obj, emails, body, emailfrom=None, context=None):
""" send email
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param email: pass the emails
@param emailfrom: Pass name the email From else False
@param context: A standard dictionary for contextual values """
if not emailfrom:
emailfrom = tools.config.get('email_from', False)
if context is None:
context = {}
body = self.format_mail(obj, body)
if not emailfrom:
if hasattr(obj, 'user_id') and obj.user_id and obj.user_id.address_id and\
obj.user_id.address_id.email:
emailfrom = obj.user_id.address_id.email
name = '[%d] %s' % (obj.id, tools.ustr(obj.name))
emailfrom = tools.ustr(emailfrom)
reply_to = emailfrom
if not emailfrom:
raise osv.except_osv(_('Error!'),
_("No E-Mail ID Found for your Company address!"))
return tools.email_send(emailfrom, emails, name, body, reply_to=reply_to, openobject_id=str(obj.id))
开发者ID:goldenboy,项目名称:razvoj,代码行数:28,代码来源:base_action_rule.py
示例2: pull_continue_thread
def pull_continue_thread(self, cr, uid, ids, context=None):
_logger = logging.getLogger('pull.rw')
cr = pooler.get_db(cr.dbname).cursor()
try:
wizard = self.browse(cr, uid, ids[0])
#US-26: Added a check if the zip file has already been imported before
syncusb = self.pool.get('sync.usb.files')
md5 = syncusb.md5(wizard.pull_data)
self.write(cr, uid, ids, {'in_progress': True})
updates_pulled = update_pull_error = updates_ran = update_run_error = \
messages_pulled = message_pull_error = messages_ran = message_run_error = 0
try:
updates_pulled, update_pull_error, updates_ran, update_run_error, \
messages_pulled, message_pull_error, messages_ran, message_run_error = self.pool.get('sync.client.entity').usb_pull(cr, uid, wizard.pull_data, context=context)
except zipfile.BadZipfile:
raise osv.except_osv(_('Not a Zip File'), _('The file you uploaded was not a valid .zip file'))
#Update list of pulled files
syncusb.create(cr, uid, {
'sum': md5,
'date': datetime.datetime.now().isoformat(),
}, context=context)
# handle returned values
pull_result = ''
if not update_pull_error:
pull_result += 'Pulled %d update(s)' % updates_pulled
if not update_run_error:
pull_result += '\nRan %s update(s)' % updates_ran
else:
pull_result += '\nError while executing %s update(s): %s' % (updates_ran, update_run_error)
else:
pull_result += 'Got an error while pulling %d update(s): %s' % (updates_pulled, update_pull_error)
if not message_pull_error:
pull_result += '\nPulled %d message(s)' % messages_pulled
if not message_run_error:
pull_result += '\nRan %s message(s)' % messages_ran
else:
pull_result += '\nError while executing %s message(s): %s' % (messages_ran, message_run_error)
else:
pull_result += '\nGot an error while pulling %d message(s): %s' % (messages_pulled, message_pull_error)
# If the correct sequence is received, then update this value into the DB for this instance, and inform in the RW sync dialog
rw_pull_sequence = context.get('rw_pull_sequence', -1)
if rw_pull_sequence != -1:
entity = self._get_entity(cr, uid, context)
self.pool.get('sync.client.entity').write(cr, uid, entity.id, {'rw_pull_sequence': rw_pull_sequence}, context)
pull_result += '\n\nThe pulling file sequence is updated. The next expected sequence is %d' % (rw_pull_sequence + 1)
vals = {
'pull_result': pull_result,
'usb_sync_step': self._get_usb_sync_step(cr, uid, context=context),
'push_file_visible': False,
}
self.write(cr, uid, ids, vals, context=context)
except osv.except_osv, e:
self.write(cr, uid, ids, {'pull_result': "Error: %s" % e.value})
_logger.error("%s : %s" % (tools.ustr(e.value), tools.ustr(traceback.format_exc())))
开发者ID:hectord,项目名称:unifield,代码行数:60,代码来源:usb_synchronisation.py
示例3: default_get
def default_get(self, cr, uid, fields, context=None):
"""
This function gets default values
"""
res = super(project_task_delegate, self).default_get(cr, uid, fields, context=context)
if context is None:
context = {}
record_id = context and context.get('active_id', False) or False
task_pool = self.pool.get('project.task')
task = task_pool.browse(cr, uid, record_id, context=context)
task_name =tools.ustr(task.name)
if 'name' in fields:
if task_name.startswith(_('CHECK: ')):
newname = tools.ustr(task_name).replace(_('CHECK: '), '')
else:
newname = tools.ustr(task_name or '')
res.update({'name': newname})
if 'planned_hours' in fields:
res.update({'planned_hours': task.remaining_hours or 0.0})
if 'prefix' in fields:
if task_name.startswith(_('CHECK: ')):
newname = tools.ustr(task_name).replace(_('CHECK: '), '')
else:
newname = tools.ustr(task_name or '')
prefix = _('CHECK: %s') % newname
res.update({'prefix': prefix})
if 'new_task_description' in fields:
res.update({'new_task_description': task.description})
return res
开发者ID:goldenboy,项目名称:razvoj,代码行数:30,代码来源:project_task_delegate.py
示例4: _get_ids
def _get_ids(self, cr, uid, name, tt, lang, ids):
translations = dict.fromkeys(ids, False)
if ids:
cr.execute('select res_id,value ' \
'from ir_translation ' \
'where lang=%s ' \
'and type=%s ' \
'and name=%s ' \
'and res_id IN %s',
(lang,tt,name,tuple(ids)))
for res_id, value in cr.fetchall():
translations[res_id] = value
for res_id in translations.keys():
res_value = translations.get(res_id, False)
if not res_value:
res_model,res_field = name.split(',')
cr.execute('select '+res_field +' from '+ \
self.pool.get(res_model)._table +' where id=%s ',
(res_id,))
source = cr.fetchone()
source = source and source[0] or u''
cr.execute("""SELECT value
FROM ir_translation
WHERE lang=%s
AND lower(src)=lower(%s)""",
(lang or '', tools.ustr(source)))
res = cr.fetchone()
trad = res and res[0] or u''
if source and not trad:
trad = tools.ustr(source)
translations[res_id] = trad
return translations
开发者ID:raulhechavarria,项目名称:epic_business,代码行数:32,代码来源:df_translation.py
示例5: _process_text
def _process_text(self, txt):
if not self.localcontext:
return str2xml(txt)
if not txt:
return ''
result = ''
sps = _regex.split(txt)
while sps:
# This is a simple text to translate
to_translate = tools.ustr(sps.pop(0))
result += tools.ustr(self.localcontext.get('translate', lambda x:x)(to_translate))
if sps:
try:
txt = None
expr = sps.pop(0)
txt = eval(expr, self.localcontext)
if txt and isinstance(txt, basestring):
txt = tools.ustr(txt)
except Exception:
pass
if isinstance(txt, basestring):
result += txt
elif txt and (txt is not None) and (txt is not False):
result += ustr(txt)
return str2xml(result)
开发者ID:kevin-garnett,项目名称:openerp-from-oneyoung,代码行数:25,代码来源:utils.py
示例6: create
def create(self, cr, uid, vals, *args, **kwargs):
obj = self.pool.get('hr.analytic.timesheet')
vals_line = {}
obj_task = self.pool.get('project.task').browse(cr, uid, vals['task_id'])
result = self.get_user_related_details(cr, uid, vals.get('user_id', uid))
vals_line['name'] = '%s: %s' % (tools.ustr(obj_task.name), tools.ustr(vals['name']) or '/')
vals_line['user_id'] = vals['user_id']
vals_line['product_id'] = result['product_id']
vals_line['date'] = vals['date'][:10]
vals_line['unit_amount'] = vals['hours']
acc_id = obj_task.project_id.category_id.id
vals_line['account_id'] = acc_id
res = obj.on_change_account_id(cr, uid, False, acc_id)
if res.get('value'):
vals_line.update(res['value'])
vals_line['general_account_id'] = result['general_account_id']
vals_line['journal_id'] = result['journal_id']
vals_line['amount'] = 00.0
vals_line['product_uom_id'] = result['product_uom_id']
timeline_id = obj.create(cr, uid, vals_line, {})
vals_line['amount'] = (-1) * vals['hours'] * obj.browse(cr, uid, timeline_id).product_id.standard_price
obj.write(cr, uid,[timeline_id], vals_line, {})
vals['hr_analytic_timesheet_id'] = timeline_id
return super(project_work,self).create(cr, uid, vals, *args, **kwargs)
开发者ID:MarkNorgate,项目名称:addons-EAD,代码行数:25,代码来源:project_timesheet.py
示例7: write
def write(self, cr, uid, ids, vals, context=None):
vals_line = {}
task = self.pool.get('project.task.work').browse(cr, uid, ids)[0]
line_id = task.hr_analytic_timesheet_id
# in case,if a record is deleted from timesheet,but we change it from tasks!
list_avail_ids = self.pool.get('hr.analytic.timesheet').search(cr, uid, [])
if line_id in list_avail_ids:
obj = self.pool.get('hr.analytic.timesheet')
if 'name' in vals:
vals_line['name'] = '%s: %s' % (tools.ustr(task.task_id.name), tools.ustr(vals['name']) or '/')
if 'user_id' in vals:
vals_line['user_id'] = vals['user_id']
result = self.get_user_related_details(cr, uid, vals['user_id'])
vals_line['product_id'] = result['product_id']
vals_line['general_account_id'] = result['general_account_id']
vals_line['journal_id'] = result['journal_id']
vals_line['product_uom_id'] = result['product_uom_id']
if 'date' in vals:
vals_line['date'] = vals['date'][:10]
if 'hours' in vals:
vals_line['unit_amount'] = vals['hours']
vals_line['amount'] = (-1) * vals['hours'] * obj.browse(cr, uid, line_id).product_id.standard_price
obj.write(cr, uid, [line_id], vals_line, {})
return super(project_work,self).write(cr, uid, ids, vals, context)
开发者ID:MarkNorgate,项目名称:addons-EAD,代码行数:26,代码来源:project_timesheet.py
示例8: group_unlink_update_execution
def group_unlink_update_execution(obj, sdref_update_ids):
obj_ids = obj.find_sd_ref(cr, uid, sdref_update_ids.keys(), context=context)
done_ids = []
for sdref, id in obj_ids.items():
try:
update_id = sdref_update_ids[sdref]
secure_unlink_data(obj, [id])
except BaseException, e:
if isinstance(e, osv.except_osv):
error = '%s: %s' % (e.name, e.value)
else:
error = e
e = "Error during unlink on model %s!\nid: %s\nUpdate id: %s\nReason: %s\nSD ref:\n%s\n" \
% (obj._name, id, update_id, tools.ustr(error), update.sdref)
self.write(cr, uid, [update_id], {
'execution_date': datetime.now(),
'run' : False,
'log' : tools.ustr(e)
}, context=context)
########################################################################
#
# UFTP-116: Cannot raise the exception here, because it will stop the whole sync!!!! Just set this line to become not run, OR set it run but error message
# If we just set it not run, it will be again and again executed but never successfully, and thus it will remain for every not run, attempt to execute EVERYTIME!
# ???? So, just set it RUN?
########################################################################
# raise
else:
done_ids.append(update_id)
开发者ID:hectord,项目名称:unifield,代码行数:30,代码来源:update.py
示例9: create_xml
def create_xml(self,cr, uid, ids, datas, context=None):
pool= pooler.get_pool(cr.dbname)
lots = pool.get('auction.lots').browse(cr, uid, ids, context=context)
auction = lots[0].auction_id
xml = '''<?xml version="1.0" encoding="UTF-8"?>
<report>
<auction>
<name>%s</name>
<date-au1>%s</date-au1>
</auction>''' % (toxml(auction['name']), toxml(auction['auction1']))
i = 0
for l in lots:
if l['obj_price']==0:
price_french = u'retiré'
else:
price_french = int_to_text(int(l['obj_price'] or 0.0))+' eur'
i+=1
xml += ''' <object>
<number>%d</number>
<obj_num>%d</obj_num>
<lot_desc>%s</lot_desc>
<price>%s</price>
<obj_price>%s</obj_price>
</object>''' % (i, l['obj_num'], ustr(toxml(l['name'])), ustr(price_french), ustr(l['obj_price'] or '/'))
xml += '</report>'
return xml
开发者ID:BorgERP,项目名称:borg-erp-6of3,代码行数:29,代码来源:huissier.py
示例10: _get_source
def _get_source(self, cr, uid, name, tt, lang, source=None):
"""
Returns the translation for the given combination of name, type, language
and source. All values passed to this method should be unicode (not byte strings),
especially ``source``.
:param name: identification of the term to translate, such as field name
:param type: type of term to translate (see ``type`` field on ir.translation)
:param lang: language code of the desired translation
:param source: optional source term to translate (should be unicode)
:rtype: unicode
:return: the request translation, or an empty unicode string if no translation was
found and `source` was not passed
"""
if source:
cr.execute('select value ' \
'from ir_translation ' \
'where lang=%s ' \
'and type=%s ' \
'and name=%s ' \
'and src=%s',
(lang or '', tt, tools.ustr(name), source))
else:
cr.execute('select value ' \
'from ir_translation ' \
'where lang=%s ' \
'and type=%s ' \
'and name=%s',
(lang or '', tt, tools.ustr(name)))
res = cr.fetchone()
trad = res and res[0] or u''
if source and not trad:
return tools.ustr(source)
return trad
开发者ID:MarkNorgate,项目名称:addons-EAD,代码行数:34,代码来源:ir_translation.py
示例11: load_from_file
def load_from_file(self, path, dbname, key):
class_inst = None
expected_class = 'Parser'
try:
ad = os.path.abspath(os.path.join(tools.ustr(config['root_path']), u'addons'))
mod_path_list = map(lambda m: os.path.abspath(tools.ustr(m.strip())), config['addons_path'].split(','))
mod_path_list.append(ad)
mod_path_list = list(set(mod_path_list))
for mod_path in mod_path_list:
if os.path.lexists(mod_path+os.path.sep+path.split(os.path.sep)[0]):
filepath=mod_path+os.path.sep+path
filepath = os.path.normpath(filepath)
sys.path.append(os.path.dirname(filepath))
mod_name,file_ext = os.path.splitext(os.path.split(filepath)[-1])
mod_name = '%s_%s_%s' % (dbname,mod_name,key)
if file_ext.lower() == '.py':
py_mod = imp.load_source(mod_name, filepath)
elif file_ext.lower() == '.pyc':
py_mod = imp.load_compiled(mod_name, filepath)
if expected_class in dir(py_mod):
class_inst = py_mod.Parser
return class_inst
elif os.path.lexists(mod_path+os.path.sep+path.split(os.path.sep)[0]+'.zip'):
zimp = zipimport.zipimporter(mod_path+os.path.sep+path.split(os.path.sep)[0]+'.zip')
return zimp.load_module(path.split(os.path.sep)[0]).parser.Parser
except SyntaxError, e:
raise osv.except_osv(_('Syntax Error !'), e)
开发者ID:SetRac,项目名称:openerp-7.0,代码行数:32,代码来源:report_xml.py
示例12: create_normal_update
def create_normal_update(self, rule, context):
domain = eval(rule.domain or '[]')
included_fields = eval(rule.included_fields or '[]')
if not 'id' in included_fields:
included_fields.append('id')
ids_need_to_push = self.usb_need_to_push(cr, uid, context=context)
if not ids_need_to_push:
return 0
domain.append(('id', 'in', ids_need_to_push))
ids_to_compute = self.search_ext(cr, uid, domain, context=context)
if not ids_to_compute:
return 0
owners = self.get_destination_name(cr, uid, ids_to_compute, rule.owner_field, context)
datas = self.export_data(cr, uid, ids_to_compute, included_fields, context=context)['datas']
sdrefs = self.get_sd_ref(cr, uid, ids_to_compute, context=context)
versions = self.version(cr, uid, ids_to_compute, context=context)
ustr_included_fields = tools.ustr(included_fields)
for (id, row) in zip(ids_to_compute, datas):
for owner in (owners[id] if hasattr(owners[id], '__iter__') else [owners[id]]):
update_id = update.create(cr, uid, {
'session_id' : session_id,
'values' : tools.ustr(row),
'model' : self._name,
'version' : versions[id] + 1,
'rule_id' : rule.id,
'sdref' : sdrefs[id],
'fields' : ustr_included_fields,
'owner' : owner,
}, context=context)
update._logger.debug("Created 'normal' update model=%s id=%d (rule sequence=%d)" % (self._name, update_id, rule.id))
return len(ids_to_compute)
开发者ID:hectord,项目名称:unifield,代码行数:34,代码来源:update.py
示例13: _bom_explode
def _bom_explode(self, cr, uid, bom, factor, properties=[], addthis=False, level=0, routing_id=False):
""" Redefine native function - add product_id parameter
Finds Products and Work Centers for related BoM for manufacturing order.
@param bom: BoM of particular product.
@param factor: Factor of product UoM.
@param properties: A List of properties Ids.
@param addthis: If BoM found then True else False.
@param level: Depth level to find BoM lines starts from 10.
@param product_id: ID of product, which is producing.
@return: result: List of dictionaries containing product details.
result2: List of dictionaries containing Work Center details.
"""
routing_obj = self.pool.get('mrp.routing')
factor = factor / (bom.product_efficiency or 1.0)
factor = rounding(factor, bom.product_rounding)
if factor < bom.product_rounding:
factor = bom.product_rounding
result = []
result2 = []
phantom = False
if bom.type == 'phantom' and not bom.bom_lines:
newbom = self._bom_find(cr, uid, product.id, bom.product_uom.id, properties)
if newbom:
res = self._bom_explode(cr, uid, self.browse(cr, uid, [newbom])[0], factor*1, properties, addthis=True, level=level+10, product_id=product_id)
result = result + res[0]
result2 = result2 + res[1]
phantom = True
else:
phantom = False
if not phantom:
if addthis and not bom.bom_lines:
result.append(
{
'name': bom.template_id.name,
'template_id': bom.template_id.id,
'product_qty': factor * bom.product_qty,
'product_uom': bom.product_uom.id,
'product_uos_qty': bom.product_uos and bom.product_uos_qty * factor or False,
'product_uos': bom.product_uos and bom.product_uos.id or False,
})
routing = (routing_id and routing_obj.browse(cr, uid, routing_id)) or bom.routing_id or False
if routing:
for wc_use in routing.workcenter_lines:
wc = wc_use.workcenter_id
d, m = divmod(factor, wc_use.workcenter_id.capacity_per_cycle)
mult = (d + (m and 1.0 or 0.0))
cycle = mult * wc_use.cycle_nbr
result2.append({
'name': tools.ustr(wc_use.name) + ' - ' + tools.ustr(bom.template_id.name),
'workcenter_id': wc.id,
'sequence': level+(wc_use.sequence or 0),
'cycle': cycle,
'hour': float(wc_use.hour_nbr*mult + ((wc.time_start or 0.0)+(wc.time_stop or 0.0)+cycle*(wc.time_cycle or 0.0)) * (wc.time_efficiency or 1.0)),
})
for bom2 in bom.bom_lines:
res = self._bom_explode(cr, uid, bom2, factor, properties, addthis=True, level=level+10)
result = result + res[0]
result2 = result2 + res[1]
return result, result2
开发者ID:duh386,项目名称:product_variant_multi,代码行数:60,代码来源:mrp.py
示例14: do_check
def do_check(self, cr, uid, action, obj, context=None):
""" @param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param context: A standard dictionary for contextual values"""
ok = super(base_action_rule, self).do_check(cr, uid, action, obj, context=context)
if hasattr(obj, 'section_id'):
ok = ok and (not action.trg_section_id or action.trg_section_id.id==obj.section_id.id)
if hasattr(obj, 'categ_id'):
ok = ok and (not action.trg_categ_id or action.trg_categ_id.id==obj.categ_id.id)
#Cheking for history
regex = action.regex_history
result_history = True
if regex:
res = False
ptrn = re.compile(tools.ustr(regex))
for history in obj.message_ids:
_result = ptrn.search(tools.ustr(history.name))
if _result:
res = True
break
result_history = res
ok = ok and (not regex or result_history)
res_count = True
if action.trg_max_history:
res_count = False
history_ids = filter(lambda x: x.history, obj.message_ids)
if len(history_ids) <= action.trg_max_history:
res_count = True
ok = ok and res_count
return ok
开发者ID:lcrdcastro,项目名称:viaweb,代码行数:34,代码来源:crm_action_rule.py
示例15: email_send
def email_send(self, cr, uid, obj, emails, body, emailfrom=None, context=None):
""" send email
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param email: pass the emails
@param emailfrom: Pass name the email From else False
@param context: A standard dictionary for contextual values """
if not emailfrom:
emailfrom = tools.config.get("email_from", False)
if context is None:
context = {}
mail_message = self.pool.get("mail.message")
body = self.format_mail(obj, body)
if not emailfrom:
if hasattr(obj, "user_id") and obj.user_id and obj.user_id.user_email:
emailfrom = obj.user_id.user_email
name = "[%d] %s" % (obj.id, tools.ustr(obj.name))
emailfrom = tools.ustr(emailfrom)
reply_to = emailfrom
if not emailfrom:
raise osv.except_osv(_("Error!"), _("No E-Mail ID Found for your Company address!"))
return mail_message.schedule_with_attach(
cr, uid, emailfrom, emails, name, body, model="base.action.rule", reply_to=reply_to, res_id=obj.id
)
开发者ID:htom78,项目名称:Xero,代码行数:29,代码来源:base_action_rule.py
示例16: _render_tab
def _render_tab(self, cr, uid, export_file, template_part, localdict):
"""Render the output of this template in a tabular format"""
template = []
try:
delimiter = eval(export_file.delimiter)
except TypeError:
delimiter = export_file.delimiter
# Header & Footer
if getattr(export_file, template_part):
template.append(self._render(cr, uid, export_file, template_part, localdict))
# Header with fieldnames
if template_part == 'header' and export_file.fieldnames_in_header:
template.append(delimiter.join((tools.ustr(column.name) for column in export_file.column_ids)))
if export_file.extension == 'xls':
_render_func = _render_data
else:
_render_func = _render_unicode
# Body
if template_part == 'body':
sub_objects = localdict['object']
if export_file.refer_to_underlying_object:
sub_objects = eval(export_file.records, localdict)
if not isinstance(sub_objects, list):
sub_objects = [sub_objects]
for index, sub_object in enumerate(sub_objects):
localdict['line_number'] = index + 1
localdict['object'] = sub_object
line = []
for column in export_file.column_ids:
try:
column_value = _render_func(column.value or '', localdict)
if column.default_value and not column_value:
column_value = _render_func(column.default_value, localdict)
if column.column_validator:
validation = eval(column.column_validator, localdict)
if not validation:
try:
exception_msg = _render_unicode(column.exception_msg, localdict)
except Exception:
exception_msg = column.exception_msg
raise except_orm(_('Error'), exception_msg)
column_value = tools.ustr(column_value)
if column_value:
if column.min_width:
column_value = getattr(column_value, column.justify)(column.min_width, tools.ustr(column.fillchar))
if column.max_width:
column_value = column_value[:column.max_width]
if not column.not_string and export_file.extension != 'xls' and export_file.quotechar:
try:
quotechar = export_file.quotechar and eval(export_file.quotechar) or ''
except TypeError:
quotechar = export_file.quotechar
column_value = '%(quotechar)s%(column_value)s%(quotechar)s' % {
'column_value': quotechar and column_value.replace(quotechar, "\\" + quotechar) or column_value,
'quotechar': quotechar,
}
line.append(column_value)
except Exception, e:
raise except_orm(_('Error'), 'column %s: %s' % (column.name, e))
template.append(delimiter.join(line))
开发者ID:StefanRijnhart,项目名称:smile_openerp_addons_6.1,代码行数:60,代码来源:export_file.py
示例17: process_data
def process_data(field, value, fields_def):
if not value or field not in fields_def:
return
if '.' not in field:
# type datetime, date, bool, int, float
if fields_def[field]['type'] == 'boolean':
value = value.lower() not in ('0', 'false', 'off','-', 'no', 'n')
elif fields_def[field]['type'] == 'selection':
if impobj == 'product.product' and self._cache[dbname].get('product.product.%s.%s' % (field, value), False):
value = self._cache[dbname]['product.product.%s.%s' % (field, value)]
else:
for key, val in fields_def[field]['selection']:
if value.lower() in [tools.ustr(key).lower(), tools.ustr(val).lower()]:
value = key
if impobj == 'product.product':
self._cache[dbname].setdefault('product.product.%s' % field, {})
self._cache[dbname]['product.product.%s.%s' % (field, value)] = key
break
elif fields_def[field]['type'] == 'date':
dt = DateTime.strptime(value,"%d/%m/%Y")
value = dt.strftime("%Y-%m-%d")
elif fields_def[field]['type'] == 'float':
# remove space and unbreakable space
value = re.sub('[ ]+', '', value)
value = float(value.replace(',', '.'))
return value
else:
if fields_def[field.split('.')[0]]['type'] in 'many2one':
return _get_obj(field, value, fields_def)
raise osv.except_osv(_('Warning !'), _('%s does not exist')%(value,))
开发者ID:hectord,项目名称:unifield,代码行数:32,代码来源:import_data.py
示例18: email_send
def email_send(self, cr, uid, obj, emails, body, emailfrom=tools.config.get('email_from', False), context=None):
mail_message = self.pool.get('mail.message')
body = self.format_mail(obj, body)
if not emailfrom:
if hasattr(obj, 'user_id') and obj.user_id and obj.user_id.user_email:
emailfrom = obj.user_id.user_email
###dreis: customizable Subject line, specified in the first line of the "body"
# name = '[%d] %s' % (obj.id, tools.ustr(obj.name))
#
subject = body.splitlines()[0] #get first line of the body
if subject.startswith('Subject:'):
name = subject.split(':', 1)[1].lstrip() #subject is text after ':'; strip leading spaces
body = '\n'.join( body.splitlines()[1:] ) #body without the first line
else:
name = '[%d] %s' % (obj.id, tools.ustr(obj.name))
###dreis end
emailfrom = tools.ustr(emailfrom)
if hasattr(obj, 'section_id') and obj.section_id and obj.section_id.reply_to:
reply_to = obj.section_id.reply_to
else:
reply_to = emailfrom
if not emailfrom:
raise osv.except_osv(_('Error!'),
_("No E-Mail ID Found for your Company address!"))
#rint "...email_send:", emails ###, name ###reis###
return mail_message.schedule_with_attach(cr, uid, emailfrom, emails, name, body, model='base.action.rule', reply_to=reply_to, res_id=obj.id)
开发者ID:Mwatchorn26,项目名称:odoo-addons,代码行数:28,代码来源:reis_base_action_rule.py
示例19: do_check
def do_check(self, cr, uid, action, obj, context=None):
ok = super(base_action_rule, self).do_check(cr, uid, action, obj, context=context)
if 'section_id' in obj._model._all_columns:
ok = ok and (not action.trg_section_id or action.trg_section_id.id == obj.section_id.id)
if 'categ_id' in obj._model._all_columns:
ok = ok and (not action.trg_categ_id or action.trg_categ_id.id == obj.categ_id.id)
# Cheking for history
regex = action.regex_history
if regex:
res = False
ptrn = re.compile(ustr(regex))
for history in obj.message_ids:
_result = ptrn.search(ustr(history.subject))
if _result:
res = True
break
ok = ok and res
if action.trg_max_history:
res_count = False
history_ids = filter(lambda x: x.email_from, obj.message_ids)
if len(history_ids) <= action.trg_max_history:
res_count = True
ok = ok and res_count
return ok
开发者ID:iw3hxn,项目名称:addons,代码行数:27,代码来源:crm_action_rule.py
示例20: get_value
def get_value(self, cr, uid, model, res_id, context=None):
"""Returns a defaults-like dict with initial values for the composition
wizard when sending an email related to the document record identified
by ``model`` and ``res_id``.
Overrides the default implementation to provide more default field values
related to the corresponding CRM case.
:param str model: model name of the document record this mail is related to.
:param int res_id: id of the document record this mail is related to.
:param dict context: several context values will modify the behavior
of the wizard, cfr. the class description.
"""
result = super(mail_compose_message, self).get_value(cr, uid, model, res_id, context=context)
if model in SUPPORTED_MODELS and res_id:
model_obj = self.pool.get(model)
data = model_obj.browse(cr, uid, res_id, context)
user = self.pool.get("res.users").browse(cr, uid, uid, context=context)
result.update(
{
"subject": data.name or False,
"email_to": data.email_from or False,
"email_from": user.user_email or tools.config.get("email_from", False),
"body_text": "\n" + tools.ustr(user.signature or ""),
"email_cc": tools.ustr(data.email_cc or ""),
"model": model,
"res_id": res_id,
"subtype": "plain",
}
)
if hasattr(data, "section_id"):
result.update({"reply_to": data.section_id and data.section_id.reply_to or False})
return result
开发者ID:EnVenteLibre,项目名称:openerp,代码行数:33,代码来源:mail_compose_message.py
注:本文中的tools.ustr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论