From 93ba65f5ca8c6cf86b45884041047132cd89295e Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Wed, 14 Jul 2010 13:42:48 +0200 Subject: [PATCH] [IMP] crm, mail_gateway: switch history message fields to read-only, they are only updated programmatically. + minor cleanup bzr revid: odo@openerp.com-20100714114248-ish7w76i2dt8t6t6 --- addons/crm/crm_lead.py | 4 ++-- addons/crm/wizard/crm_send_email.py | 31 ++++++++++++++--------------- addons/mail_gateway/mail_gateway.py | 28 +++++++++++++------------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index bffb1fc53b8..606895e27a6 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -152,8 +152,8 @@ and users"), \nIf the case is in progress the state is set to \'Open\'.\ \nWhen the case is over, the state is set to \'Done\'.\ \nIf the case needs to be reviewed then the state is set to \'Pending\'.'), - 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('history', '=', True),('model','=',_name)]), - 'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False),('model','=',_name)]), + 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('history', '=', True),('model','=',_name)], readonly=True), + 'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False),('model','=',_name)], readonly=True), } _defaults = { diff --git a/addons/crm/wizard/crm_send_email.py b/addons/crm/wizard/crm_send_email.py index 27bc9328b61..bc2b5357c15 100644 --- a/addons/crm/wizard/crm_send_email.py +++ b/addons/crm/wizard/crm_send_email.py @@ -120,22 +120,21 @@ class crm_send_new_email(osv.osv_memory): if not flag: raise osv.except_osv(_('Error!'), _('Unable to send mail. Please check SMTP is configured properly.')) - if flag: - case_pool.history(cr, uid, [case], _('Send'), history=True, \ - email=obj.email_to, details=body, \ - subject=obj.subject, email_from=email_from, \ - email_cc=email_cc, message_id=message_id, \ - references=ref_id or message_id, attach=attach) - if obj.state == 'unchanged': - pass - elif obj.state == 'done': - case_pool.case_close(cr, uid, [case.id]) - elif obj.state == 'draft': - case_pool.case_reset(cr, uid, [case.id]) - elif obj.state in ['cancel', 'open', 'pending']: - act = 'case_' + obj.state - getattr(case_pool, act)(cr, uid, [case.id]) - cr.commit() + + case_pool.history(cr, uid, [case], _('Send'), history=True, \ + email=obj.email_to, details=body, \ + subject=obj.subject, email_from=email_from, \ + email_cc=email_cc, message_id=message_id, \ + references=ref_id or message_id, attach=attach) + if obj.state == 'unchanged': + pass + elif obj.state == 'done': + case_pool.case_close(cr, uid, [case.id]) + elif obj.state == 'draft': + case_pool.case_reset(cr, uid, [case.id]) + elif obj.state in ['cancel', 'open', 'pending']: + act = 'case_' + obj.state + getattr(case_pool, act)(cr, uid, [case.id]) return {} diff --git a/addons/mail_gateway/mail_gateway.py b/addons/mail_gateway/mail_gateway.py index 7187de5d1a5..1abda444116 100644 --- a/addons/mail_gateway/mail_gateway.py +++ b/addons/mail_gateway/mail_gateway.py @@ -41,8 +41,8 @@ class mailgate_thread(osv.osv): _description = 'Mailgateway Thread' _columns = { - 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('history', '=', True)]), - 'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False)]), + 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('history', '=', True)], readonly=True), + 'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False)], readonly=True), } def message_new(self, cr, uid, msg, context): @@ -149,23 +149,23 @@ class mailgate_message(osv.osv): _description = 'Mailgateway Message' _order = 'id desc' _columns = { - 'name':fields.text('Subject'), - 'model': fields.char('Object Name', size=128, select=1), - 'res_id': fields.integer('Resource ID', select=1), + 'name':fields.text('Subject', readonly=True), + 'model': fields.char('Object Name', size=128, select=1, readonly=True), + 'res_id': fields.integer('Resource ID', select=1, readonly=True), 'ref_id': fields.char('Reference Id', size=256, readonly=True, help="Message Id in Email Server.", select=True), - 'date': fields.datetime('Date'), - 'history': fields.boolean('Is History?'), + 'date': fields.datetime('Date', readonly=True), + 'history': fields.boolean('Is History?', readonly=True), 'user_id': fields.many2one('res.users', 'User Responsible', readonly=True), - 'message': fields.text('Description'), - 'email_from': fields.char('From', size=128, help="Email From"), - 'email_to': fields.char('To', help="Email Recipients", size=256), - 'email_cc': fields.char('Cc', help="Carbon Copy Email Recipients", size=256), - 'email_bcc': fields.char('Bcc', help='Blind Carbon Copy Email Recipients', size=256), + 'message': fields.text('Description', readonly=True), + 'email_from': fields.char('From', size=128, help="Email From", readonly=True), + 'email_to': fields.char('To', help="Email Recipients", size=256, readonly=True), + 'email_cc': fields.char('Cc', help="Carbon Copy Email Recipients", size=256, readonly=True), + 'email_bcc': fields.char('Bcc', help='Blind Carbon Copy Email Recipients', size=256, readonly=True), 'message_id': fields.char('Message Id', size=1024, readonly=True, help="Message Id on Email.", select=True), 'references': fields.text('References', readonly=True, help="References emails."), - 'description': fields.text('Description'), + 'description': fields.text('Description', readonly=True), 'partner_id': fields.many2one('res.partner', 'Partner', required=False), - 'attachment_ids': fields.many2many('ir.attachment', 'message_attachment_rel', 'message_id', 'attachment_id', 'Attachments'), + 'attachment_ids': fields.many2many('ir.attachment', 'message_attachment_rel', 'message_id', 'attachment_id', 'Attachments', readonly=True), } def init(self, cr):