[FIX] mail: unify message_post calls, fix typos, various lint cleanup

bzr revid: odo@openerp.com-20120822113439-aoy7v4njs6o34tu5
This commit is contained in:
Olivier Dony 2012-08-22 13:34:39 +02:00
parent 49596ebe91
commit 406e58399f
19 changed files with 87 additions and 78 deletions

View File

@ -430,7 +430,7 @@ class account_bank_statement(osv.osv):
'name': st_number,
'balance_end_real': st.balance_end
}, context=context)
self.message_post(cr, uid, [st.id], body=_('Statement %s is confirmed, journal items are created.') % (st_number,), context=context)
self.message_post(cr, uid, [st.id], body=_('Statement %s confirmed, journal items were created.') % (st_number,), context=context)
return self.write(cr, uid, ids, {'state':'confirm'}, context=context)
def button_cancel(self, cr, uid, ids, context=None):

View File

@ -1288,24 +1288,25 @@ class account_invoice(osv.osv):
def _get_document_type(self, type):
type_dict = {
'out_invoice': 'Customer invoice',
'in_invoice': 'Supplier invoice',
'out_refund': 'Customer Refund',
'in_refund': 'Supplier Refund',
# Translation markers will have no effect at runtime, only used to properly flag export
'out_invoice': _('Customer invoice'),
'in_invoice': _('Supplier invoice'),
'out_refund': _('Customer Refund'),
'in_refund': _('Supplier Refund'),
}
return type_dict.get(type, 'Invoice')
def create_send_note(self, cr, uid, ids, context=None):
for obj in self.browse(cr, uid, ids, context=context):
self.message_post(cr, uid, [obj.id],body=_("%s <b>created</b>.") % (self._get_document_type(obj.type)), context=context)
self.message_post(cr, uid, [obj.id], body=_("%s <b>created</b>.") % (_(self._get_document_type(obj.type))), context=context)
def confirm_paid_send_note(self, cr, uid, ids, context=None):
for obj in self.browse(cr, uid, ids, context=context):
self.message_post(cr, uid, [obj.id], body=_("%s <b>paid</b>.") % (self._get_document_type(obj.type)), context=context)
for obj in self.browse(cr, uid, ids, context=context):
self.message_post(cr, uid, [obj.id], body=_("%s <b>paid</b>.") % (_(self._get_document_type(obj.type))), context=context)
def invoice_cancel_send_note(self, cr, uid, ids, context=None):
for obj in self.browse(cr, uid, ids, context=context):
self.message_post(cr, uid, [obj.id], body=_("%s <b>cancelled</b>.") % (self._get_document_type(obj.type)), context=context)
self.message_post(cr, uid, [obj.id], body=_("%s <b>cancelled</b>.") % (_(self._get_document_type(obj.type))), context=context)
account_invoice()

View File

@ -78,9 +78,9 @@ class crm_meeting(base_state, osv.Model):
return 'Meeting'
def case_open_send_note(self, cr, uid, ids, context=None):
return self.message_post(cr, uid, ids, body=_("Meeting has been <b>confirmed</b>."), context=context)
return self.message_post(cr, uid, ids, body=_("Meeting <b>confirmed</b>."), context=context)
def case_close_send_note(self, cr, uid, ids, context=None):
return self.message_post(cr, uid, ids, body=_("Meeting has been <b>done</b>."), context=context)
return self.message_post(cr, uid, ids, body=_("Meeting <b>completed</b>."), context=context)

View File

@ -428,5 +428,5 @@ class base_stage(object):
msg = '%s has been <b>escalated</b> to <b>%s</b>.' % (self.case_get_note_msg_prefix(cr, uid, id, context=context), new_section.name)
else:
msg = '%s has been <b>escalated</b>.' % (self.case_get_note_msg_prefix(cr, uid, id, context=context))
self.message_post(cr, uid, [id], 'System Notification', msg, context=context)
self.message_post(cr, uid, [id], body=msg, context=context)
return True

View File

@ -179,9 +179,9 @@ class base_state(object):
# Notifications
# ******************************
def case_get_note_msg_prefix(self, cr, uid, id, context=None):
return ''
def case_get_note_msg_prefix(self, cr, uid, id, context=None):
return ''
def case_open_send_note(self, cr, uid, ids, context=None):
for id in ids:
msg = _('%s has been <b>opened</b>.') % (self.case_get_note_msg_prefix(cr, uid, id, context=context))
@ -194,7 +194,7 @@ class base_state(object):
msg = '%s has been <b>escalated</b> to <b>%s</b>.' % (self.case_get_note_msg_prefix(cr, uid, id, context=context), new_section.name)
else:
msg = '%s has been <b>escalated</b>.' % (self.case_get_note_msg_prefix(cr, uid, id, context=context))
self.message_post(cr, uid, [id], 'System Notification', msg, context=context)
self.message_post(cr, uid, [id], body=msg, context=context)
return True
def case_close_send_note(self, cr, uid, ids, context=None):

View File

@ -105,8 +105,8 @@ class base_action_rule(osv.osv):
write['email_cc'] = obj.act_email_cc
# Put state change by rule in communication history
if hasattr(obj, 'state') and hasattr(obj, 'message_append') and action.act_state:
model_obj.message_post(cr, uid, [obj], _(action.act_state))
if hasattr(obj, 'state') and hasattr(obj, 'message_post') and action.act_state:
model_obj.message_post(cr, uid, [obj], _(action.act_state), context=context)
model_obj.write(cr, uid, [obj.id], write, context)
super(base_action_rule, self).do_action(cr, uid, action, model_obj, obj, context=context)

View File

@ -19,7 +19,6 @@
#
##############################################################################
import binascii
from base_status.base_stage import base_stage
import crm
from datetime import datetime
@ -476,7 +475,7 @@ class crm_lead(base_stage, osv.osv):
subject = subject[0] + ", ".join(subject[1:])
details = "\n\n".join(details)
return self.message_post(cr, uid, [opportunity_id], subject=subject, body=details)
return self.message_post(cr, uid, [opportunity_id], body=details, subject=subject, context=context)
def _merge_opportunity_history(self, cr, uid, opportunity_id, opportunities, context=None):
message = self.pool.get('mail.message')

View File

@ -53,7 +53,7 @@ class crm_meeting(osv.Model):
if meeting.opportunity_id: # meeting can be create from phonecalls or opportunities, therefore checking for the parent
lead = meeting.opportunity_id
message = _("Meeting linked to the opportunity <em>%s</em> has been <b>created</b> and <b>scheduled</b> on <em>%s</em>.") % (lead.name, meeting_date_tz)
lead.message_post(_('System Notification'), message)
lead.message_post(body=message)
elif meeting.phonecall_id:
phonecall = meeting.phonecall_id
message = _("Meeting linked to the phonecall <em>%s</em> has been <b>created</b> and <b>scheduled</b> on <em>%s</em>.") % (phonecall.name, meeting_date_tz)

View File

@ -19,10 +19,8 @@
#
##############################################################################
import time
from osv import fields, osv
from tools.translate import _
import decimal_precision as dp
from openerp import SUPERUSER_ID
class event_type(osv.osv):
@ -53,7 +51,7 @@ class event_event(osv.osv):
def name_get(self, cr, uid, ids, context=None):
if not ids:
return []
return []
res = []
for record in self.browse(cr, uid, ids, context=context):
date = record.date_begin.split(" ")[0]
@ -99,7 +97,6 @@ class event_event(osv.osv):
return self.write(cr, uid, ids, {'state': 'done'}, context=context)
def check_registration_limits(self, cr, uid, ids, context=None):
register_pool = self.pool.get('event.registration')
for self.event in self.browse(cr, uid, ids, context=context):
total_confirmed = self.event.register_current
if total_confirmed < self.event.register_min or total_confirmed > self.event.register_max and self.event.register_max!=0:
@ -109,7 +106,7 @@ class event_event(osv.osv):
for event in self.browse(cr, uid, ids, context=context):
available_seats = event.register_avail
if available_seats and no_of_registration > available_seats:
raise osv.except_osv(_('Warning!'),_("Only %d Seats are Available!") % (available_seats))
raise osv.except_osv(_('Warning!'),_("Only %d Seats are Available!") % (available_seats))
elif available_seats == 0:
raise osv.except_osv(_('Warning!'),_("No Tickets Available!"))
@ -139,7 +136,6 @@ class event_event(osv.osv):
@param context: A standard dictionary for contextual values
@return: Dictionary of function fields value.
"""
register_pool = self.pool.get('event.registration')
res = {}
for event in self.browse(cr, uid, ids, context=context):
res[event.id] = {}
@ -334,7 +330,7 @@ class event_registration(osv.osv):
return self.write(cr, uid, ids, {'state': 'draft'}, context=context)
def confirm_registration(self, cr, uid, ids, context=None):
self.message_post(cr, uid, ids, body=_('State set to open'))
self.message_post(cr, uid, ids, body=_('State set to open'), context=context)
return self.write(cr, uid, ids, {'state': 'open'}, context=context)
def create(self, cr, uid, vals, context=None):
@ -364,13 +360,13 @@ class event_registration(osv.osv):
if today >= registration.event_id.date_begin:
values = {'state': 'done', 'date_closed': today}
self.write(cr, uid, ids, values)
self.message_post(cr, uid, ids, body=_('State set to Done'))
self.message_post(cr, uid, ids, body=_('State set to Done'), context=context)
else:
raise osv.except_osv(_('Error!'),_("You must wait for the starting day of the event to do this action.") )
return True
def button_reg_cancel(self, cr, uid, ids, context=None, *args):
self.message_post(cr, uid, ids,body = _('State set to Cancel'))
self.message_post(cr, uid, ids, body=_('State set to Cancel'), context=context)
return self.write(cr, uid, ids, {'state': 'cancel'})
def mail_user(self, cr, uid, ids, context=None):

View File

@ -212,7 +212,7 @@ class hr_employee(osv.osv):
try:
(model, mail_group_id) = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'mail', 'group_all_employees')
employee = self.browse(cr, uid, employee_id, context=context)
self.pool.get('mail.group').message_post(cr, uid, [mail_group_id], body='Welcome to %s! Please help him make its first steps in OpenERP!' % (employee.name), context=context)
self.pool.get('mail.group').message_post(cr, uid, [mail_group_id], body='Welcome to %s! Please help them take the first steps with OpenERP!' % (employee.name), context=context)
except:
pass # group deleted: do not push a message
return employee_id

View File

@ -367,14 +367,14 @@ class hr_holidays(osv.osv):
def create_notificate(self, cr, uid, ids, context=None):
for obj in self.browse(cr, uid, ids, context=context):
self.message_post(cr, uid, ids,
_("The %s request has been <b>created</b> and is waiting confirmation.")
_("The %s request has been <b>created</b> and is waiting for confirmation.")
% ('leave' if obj.type == 'remove' else 'allocation',), context=context)
return True
def holidays_confirm_notificate(self, cr, uid, ids, context=None):
for obj in self.browse(cr, uid, ids):
self.message_post(cr, uid, [obj.id], _("The %s request has been <b>confirmed</b> and is waiting for validation by the manager.")
% ('leave' if obj.type == 'remove' else 'allocation',))
% ('leave' if obj.type == 'remove' else 'allocation',), context=context)
def holidays_validate_notificate(self, cr, uid, ids, context=None):
for obj in self.browse(cr, uid, ids):

View File

@ -45,7 +45,6 @@ class mail_mail(osv.Model):
_columns = {
'mail_message_id': fields.many2one('mail.message', 'Message', required=True, ondelete='cascade'),
'mail_server_id': fields.many2one('ir.mail_server', 'Outgoing mail server', readonly=1),
'subject': fields.char('Subject', size=128),
'state': fields.selection([
('outgoing', 'Outgoing'),
('sent', 'Sent'),

View File

@ -19,7 +19,6 @@
#
##############################################################################
import base64
import dateutil
import email
import logging
@ -27,7 +26,6 @@ from email.utils import parsedate
from email.message import Message
from osv import osv, fields
from mail_message import decode
import re
import time
import tools
from tools.translate import _
@ -313,7 +311,7 @@ class mail_thread(osv.Model):
model_pool.message_update(cr, user_id, [thread_id], msg, context=context)
else:
thread_id = model_pool.message_new(cr, user_id, msg, custom_values, context=context)
self.message_post(cr, uid, thread_id, context=context, **msg)
self.message_post(cr, uid, [thread_id], msg_txt['body'], context=context, **msg)
return True
def message_new(self, cr, uid, msg_dict, custom_values=None, context=None):
@ -421,7 +419,7 @@ class mail_thread(osv.Model):
if save_original:
msg_original = message.as_string() if isinstance(message, Message) \
else message
attachments.append(('email.eml', msg_original))
attachments.append(('original_email.eml', msg_original))
if not message_id:
# Very unusual situation, be we should be fault-tolerant here
@ -451,11 +449,11 @@ class mail_thread(osv.Model):
msg['partner_ids'] = partner_ids
if 'Date' in msg_fields:
date_hdr = decode(msg_txt.get('Date'))
# convert from email timezone to server timezone
date_server_datetime = dateutil.parser.parse(date_hdr).astimezone(pytz.timezone(tools.get_server_timezone()))
date_server_datetime_str = date_server_datetime.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
msg['date'] = date_server_datetime_str
date_hdr = decode(msg_txt.get('Date'))
# convert from email timezone to server timezone
date_server_datetime = dateutil.parser.parse(date_hdr).astimezone(pytz.timezone(tools.get_server_timezone()))
date_server_datetime_str = date_server_datetime.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
msg['date'] = date_server_datetime_str
#if 'Content-Transfer-Encoding' in msg_fields:
# msg['encoding'] = msg_txt.get('Content-Transfer-Encoding')
@ -507,38 +505,53 @@ class mail_thread(osv.Model):
module instead of by the res.log mechanism. Please \
use the mail.thread OpenChatter API instead of the \
now deprecated res.log.")
self.message_post(cr, uid, id, message, context=context)
self.message_post(cr, uid, [id], message, context=context)
def message_post(self, cr, uid, res_id, body, subject=False,
mtype='notification', parent_id=False, attachments=None, context=None, **kwargs):
def message_post(self, cr, uid, thread_id, body, subject=False,
msg_type='notification', parent_id=False, attachments=None, context=None, **kwargs):
"""Post a new message in an existing message thread, returning the new mail.message ID.
Extra keyword arguments will be used as default column values for the new
mail.message record.
:param int thread_id: thread ID to post into, or list with one ID
:param str body: body of the message, usually raw HTML
:param str subject: optional subject
:param str msg_type: message type, out of the possible values for mail_message.type,
currently one of ``email, 'comment', 'notification'``.
:param int parent_id: optional ID of parent message in this thread
:param tuple(str,str) attachments: list of attachment tuples in the form ``(name,content)``
:return: ID of newly created mail.message
"""
context = context or {}
attachments = attachments or {}
if type(res_id) in (list, tuple):
res_id = res_id and res_id[0] or False
assert (not thread_id) or isinstance(thread_id, (int,long)) or \
(isinstance(thread_id, (list, tuple)) and len(thread_id) == 1), "Invalid thread_id"
if isinstance(thread_id, (list, tuple)):
thread_id = thread_id and thread_id[0]
to_attach = []
for fname, fcontent in attachments:
if isinstance(fcontent, unicode):
fcontent = fcontent.encode('utf-8')
for name, content in attachments:
if isinstance(content, unicode):
content = content.encode('utf-8')
data_attach = {
'name': fname,
'datas': fcontent,
'datas_fname': fname,
'description': _('email attachment'),
'name': name,
'datas': content,
'datas_fname': name,
'description': name,
}
to_attach.append((0,0, data_attach))
value = kwargs
value.update( {
'model': res_id and self._name or False,
'res_id': res_id,
values = kwargs
values.update( {
'model': thread_id and self._name or False,
'thread_id': thread_id or False,
'body': body,
'subject': subject,
'type': mtype,
'type': msg_type,
'parent_id': parent_id,
'attachment_ids': to_attach
})
return self.pool.get('mail.message').create(cr, uid, value, context=context)
return self.pool.get('mail.message').create(cr, uid, values, context=context)
#------------------------------------------------------

View File

@ -110,9 +110,9 @@ class res_users(osv.Model):
def _create_welcome_message(self, cr, uid, user, context=None):
company_name = user.company_id.name if user.company_id else _('the company')
body = '''%s has joined %s.''' % (user.name, company_name)
# TODO change 1 into user.id but catch errors
return self.pool.get('res.partner').message_post(cr, 1, [user.partner_id.id],
body = _('%s has joined %s.') % (user.name, company_name)
# TODO change SUPERUSER_ID into user.id but catch errors
return self.pool.get('res.partner').message_post(cr, SUPERUSER_ID, [user.partner_id.id],
body=body, context=context)
def write(self, cr, uid, ids, vals, context=None):

View File

@ -254,9 +254,9 @@ class mail_compose_message(osv.TransientModel):
context = {}
formatting = context.get('formatting')
# FIXME TODO: mass_mail_mode unused?
mass_mail_mode = context.get('mail.compose.message.mode') == 'mass_mail'
mail_message_obj = self.pool.get('mail.message')
for mail_wiz in self.browse(cr, uid, ids, context=context):
attachment = {}
for attach in mail_wiz.attachment_ids:
@ -264,6 +264,7 @@ class mail_compose_message(osv.TransientModel):
# default values, according to the wizard options
subject = mail_wiz.subject if formatting else False
# FIXME TODO: partner_ids not used??
partner_ids = [partner.id for partner in mail_wiz.dest_partner_ids]
body = mail_wiz.body_html if mail_wiz.content_subtype == 'html' else mail_wiz.body
@ -274,7 +275,7 @@ class mail_compose_message(osv.TransientModel):
active_model_pool = self.pool.get(active_model)
subject = self.render_template(cr, uid, subject, active_model, active_id)
body = self.render_template(cr, uid, mail_wiz.body_html, active_model, active_id)
active_model_pool.message_post(cr, uid, active_id, body, subject, 'comment',
active_model_pool.message_post(cr, uid, [active_id], body=body, subject=subject, msg_type='comment',
attachments=attachment, context=context)
return {'type': 'ir.actions.act_window_close'}

View File

@ -101,15 +101,15 @@ class plugin_handler(osv.osv_memory):
notify = "Email already pushed"
elif res_id == 0:
if model == 'res.partner':
notify = 'User the button Partner to create a new partner'
notify = 'User the Partner button to create a new partner'
else:
res_id = model_obj.message_new(cr, uid, msg)
notify = "Mail succefully pushed, a new %s has been created " % model
notify = "Mail succesfully pushed, a new %s has been created " % model
else:
if model == 'res.partner':
model_obj = self.pool.get('mail.thread')
model_obj.message_post(cr, uid, [res_id], body=msg)
notify = "Mail succefully pushed"
notify = "Mail succesfully pushed"
url = self._make_url(cr, uid, res_id, model)
return (model, res_id, url, notify)

View File

@ -389,7 +389,7 @@ class procurement_order(osv.osv):
ok = ok and self.pool.get('stock.move').action_assign(cr, uid, [id])
order_point_id = self.pool.get('stock.warehouse.orderpoint').search(cr, uid, [('product_id', '=', procurement.product_id.id)], context=context)
if not order_point_id and not ok:
message = _("Not enough stock and no minimum orderpoint rule defined.")
message = _("Not enough stock and no minimum orderpoint rule defined.")
elif not order_point_id:
message = _("No minimum orderpoint rule defined.")
elif not ok:

View File

@ -507,21 +507,21 @@ class project_issue(base_stage, osv.osv):
return 'Project issue'
def convert_to_task_send_note(self, cr, uid, ids, context=None):
message = _("Project issue has been <b>converted</b> into task.")
message = _("Project issue <b>converted</b> to task.")
return self.message_post(cr, uid, ids, body=message, context=context)
def create_send_note(self, cr, uid, ids, context=None):
message = _("Project issue has been <b>created</b>.")
message = _("Project issue <b>created</b>.")
return self.message_post(cr, uid, ids, body=message, context=context)
def case_escalate_send_note(self, cr, uid, ids, context=None):
for obj in self.browse(cr, uid, ids, context=context):
if obj.project_id:
message = _("has been <b>escalated</b> to <em>'%s'</em>.") % (obj.project_id.name)
obj.message_post(body=message, context=context)
message = _("<b>escalated</b> to <em>'%s'</em>.") % (obj.project_id.name)
obj.message_post(body=message)
else:
message = _("has been <b>escalated</b>.")
obj.message_post(body=message, context=context)
message = _("<b>escalated</b>.")
obj.message_post(body=message)
return True
project_issue()

View File

@ -1027,7 +1027,7 @@ class sale_order(osv.osv):
def create_send_note(self, cr, uid, ids, context=None):
for obj in self.browse(cr, uid, ids, context=context):
self.message_post(cr, uid, [obj.id], body=_("Quotation for <em>%s</em> has been <b>created</b>.") % (obj.partner_id.name), context=context)
self.message_post(cr, uid, [obj.id], body=_("Quotation for <em>%s</em> <b>created</b>.") % (obj.partner_id.name), context=context)
def confirm_send_note(self, cr, uid, ids, context=None):
for obj in self.browse(cr, uid, ids, context=context):
@ -1058,7 +1058,7 @@ class sale_order(osv.osv):
self.message_post(cr, uid, [order.id], body=_("Draft Invoice of %s %s <b>waiting for validation</b>.") % (invoice.amount_total, invoice.currency_id.symbol), context=context)
def action_cancel_draft_send_note(self, cr, uid, ids, context=None):
return self.message_post(cr, uid, ids, body='Sale order has been set in draft.', context=context)
return self.message_post(cr, uid, ids, body=_('Sale order set to draft.'), context=context)
sale_order()