Browse Source

Update messages author on partner creation

pull/1/head
Veronika Kotovich 9 years ago
parent
commit
aa5fc909d7
  1. 26
      mail_move_message_models.py
  2. 2
      mail_move_message_views.xml

26
mail_move_message_models.py

@ -189,11 +189,11 @@ class wizard(models.TransientModel):
model = self.env[relation]
message = self.env['mail.message'].browse(message_id)
if not partner_id and message_name_from:
partner_id = self.env['res.partner'].create({
partner_id = self.env['res.partner'].with_context({'update_message_author': True}).create({
'name': message_name_from,
'email': message_email_from
}).id
message.write({'author_id': partner_id})
context = {'partner_id': partner_id}
if model._rec_name:
context.update({'default_%s' % model._rec_name: message.subject})
@ -320,3 +320,25 @@ class mail_move_message_configuration(models.TransientModel):
for record in self:
model_names = ','.join([m.model for m in record.model_ids])
config_parameters.set_param('mail_relocation_models', model_names)
class res_partner(models.Model):
_inherit = 'res.partner'
@api.model
def create(self, vals):
res = super(res_partner, self).create(vals)
if 'update_message_author' in self.env.context and 'email' in vals:
mail_message_obj = self.env['mail.message']
# Escape special SQL characters in email_address to avoid invalid matches
email_address = (vals['email'].replace('\\', '\\\\').replace('%', '\\%').replace('_', '\\_'))
email_brackets = "<%s>" % email_address
messages = mail_message_obj.search([
'|',
('email_from', '=ilike', email_address),
('email_from', 'ilike', email_brackets),
('author_id', '=', False)
])
if messages:
messages.write({'author_id': res.id})
return res

2
mail_move_message_views.xml

@ -37,7 +37,7 @@
<div>
<field name="filter_by_partner"/>
<field name="partner_id" style="width:50%"/>
<button string="Create Partner" attrs="{'invisible':[('partner_id','!=',False)]}" class="oe_highlight" special="quick_create" field="partner_id" context="{'force_email':True,'default_email':message_email_from,'default_name':message_name_from}"/>
<button string="Create Partner" attrs="{'invisible':[('partner_id','!=',False)]}" class="oe_highlight" special="quick_create" field="partner_id" context="{'force_email':True,'default_email':message_email_from,'default_name':message_name_from, 'update_message_author':True}"/>
</div>
<label for="res_id"/>
<div>

Loading…
Cancel
Save