Thibault Delavallée (OpenERP) has proposed merging
lp:~openerp-dev/openobject-addons/trunk-message-sub-type-apa into
lp:openobject-addons.
Requested reviews:
OpenERP Core Team (openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-message-sub-type-apa/+merge/121822
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-message-sub-type-apa/+merge/121822
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-addons/trunk-message-sub-type-apa.
=== modified file 'crm/__openerp__.py'
--- crm/__openerp__.py 2012-08-22 13:02:32 +0000
+++ crm/__openerp__.py 2012-08-29 10:53:37 +0000
@@ -128,7 +128,8 @@
'test/process/segmentation.yml',
'test/ui/crm_demo.yml',
'test/ui/duplicate_lead.yml',
- 'test/ui/delete_lead.yml'
+ 'test/ui/delete_lead.yml',
+ 'test/process/crm_message_subtype.yml',
],
'installable': True,
'application': True,
=== modified file 'crm/crm_data.xml'
--- crm/crm_data.xml 2012-08-14 08:20:29 +0000
+++ crm/crm_data.xml 2012-08-29 10:53:37 +0000
@@ -56,7 +56,7 @@
<!-- notify all employees of module installation -->
<function model="mail.group" name="message_append_note">
- <!-- ids, subject, body, parent_id=False, type='notification', content_subtype='html' -->
+ <!-- ids, subject,subtype_id="other", body, parent_id=False, type='notification', content_subtype='html' -->
<value eval="[ref('mail.group_all_employees')]"/>
<value>Module CRM has been installed</value>
<value>From the top menu Sales, you can: trace leads and opportunities, get accurate forecast on your sales pipeline, plan meetings and phonecalls, get realtime statistics and efficiently organize the communication with your prospects.
=== modified file 'crm/crm_lead.py'
--- crm/crm_lead.py 2012-08-23 14:35:21 +0000
+++ crm/crm_lead.py 2012-08-29 10:53:37 +0000
@@ -278,6 +278,9 @@
def create(self, cr, uid, vals, context=None):
obj_id = super(crm_lead, self).create(cr, uid, vals, context)
+ record = self.browse(cr, uid, obj_id, context)
+ if record.user_id:
+ self.message_subscribe(cr, uid, [obj_id], [record.user_id.id], context = context)
self.create_send_note(cr, uid, [obj_id], context=context)
return obj_id
@@ -868,7 +871,7 @@
def stage_set_send_note(self, cr, uid, ids, stage_id, context=None):
""" Override of the (void) default notification method. """
stage_name = self.pool.get('crm.case.stage').name_get(cr, uid, [stage_id], context=context)[0][1]
- return self.message_append_note(cr, uid, ids, body= _("Stage changed to <b>%s</b>.") % (stage_name), context=context)
+ return self.message_append_note(cr, uid, ids, body= _("Stage changed to <b>%s</b>.") % (stage_name), subtype="stage change",context=context)
def case_get_note_msg_prefix(self, cr, uid, lead, context=None):
if isinstance(lead, (int, long)):
@@ -878,16 +881,16 @@
def create_send_note(self, cr, uid, ids, context=None):
for id in ids:
message = _("%s has been <b>created</b>.")% (self.case_get_note_msg_prefix(cr, uid, id, context=context))
- self.message_append_note(cr, uid, [id], body=message, context=context)
+ self.message_append_note(cr, uid, [id], body=message, subtype="new", context=context)
return True
def case_mark_lost_send_note(self, cr, uid, ids, context=None):
message = _("Opportunity has been <b>lost</b>.")
- return self.message_append_note(cr, uid, ids, body=message, context=context)
+ return self.message_append_note(cr, uid, ids, body=message,subtype="lost", context=context)
def case_mark_won_send_note(self, cr, uid, ids, context=None):
message = _("Opportunity has been <b>won</b>.")
- return self.message_append_note(cr, uid, ids, body=message, context=context)
+ return self.message_append_note(cr, uid, ids, body=message, subtype="won", context=context)
def schedule_phonecall_send_note(self, cr, uid, ids, phonecall_id, action, context=None):
phonecall = self.pool.get('crm.phonecall').browse(cr, uid, [phonecall_id], context=context)[0]
=== modified file 'crm/crm_lead_data.xml'
--- crm/crm_lead_data.xml 2012-08-14 08:20:29 +0000
+++ crm/crm_lead_data.xml 2012-08-29 10:53:37 +0000
@@ -154,5 +154,38 @@
<field name="object_id" search="[('model','=','crm.lead')]" model="ir.model"/>
</record>
+ <!-- mail subtype -->
+ <record id="mail_subtype_lead_new" model="mail.message.subtype">
+ <field name="name">new</field>
+ <field name="model_ids" eval="[(6, 0, [ref('crm.model_crm_lead')])]"/>
+ <field name="default" eval="False"/>
+ </record>
+ <record id="mail_subtype_lead_won" model="mail.message.subtype">
+ <field name="name">won</field>
+ <field name="model_ids" eval="[(6, 0, [ref('crm.model_crm_lead')])]"/>
+ </record>
+ <record id="mail_subtype_lead_lost" model="mail.message.subtype">
+ <field name="name">lost</field>
+ <field name="model_ids" eval="[(6, 0, [ref('crm.model_crm_lead')])]"/>
+ </record>
+ <record id="mail_subtype_lead_stage_change" model="mail.message.subtype">
+ <field name="name">stage change</field>
+ <field name="model_ids" eval="[(6, 0, [ref('crm.model_crm_lead')])]"/>
+ <field name="default" eval="False"/>
+ </record>
+ <record id="mail_subtype_lead_other" model="mail.message.subtype">
+ <field name="name">other</field>
+ <field name="model_ids" eval="[(6, 0, [ref('crm.model_crm_lead')])]"/>
+ <field name="default" eval="False"/>
+ </record>
+ <record id="mail_subtype_lead_email" model="mail.message.subtype">
+ <field name="name">email</field>
+ <field name="model_ids" eval="[(6, 0, [ref('crm.model_crm_lead')])]"/>
+ </record>
+ <record id="mail_subtype_lead_comment" model="mail.message.subtype">
+ <field name="name">comment</field>
+ <field name="model_ids" eval="[(6, 0, [ref('crm.model_crm_lead')])]"/>
+ <field name="default" eval="False"/>
+ </record>
</data>
</openerp>
=== added file 'crm/test/process/crm_message_subtype.yml'
--- crm/test/process/crm_message_subtype.yml 1970-01-01 00:00:00 +0000
+++ crm/test/process/crm_message_subtype.yml 2012-08-29 10:53:37 +0000
@@ -0,0 +1,48 @@
+-
+ I have add the sub_type name other with default false
+-
+ !record {model: mail.message.subtype, id: mail_subtype_lead_won }:
+ name: won
+ model_ids:
+ - crm.model_crm_lead
+ default: False
+-
+ I have add the sub_type name email with default true
+-
+ !record {model: mail.message.subtype, id: mail_subtype_lead_email }:
+ name: email
+ model_ids:
+ - crm.model_crm_lead
+ default: True
+-
+ I have add the sub_type name comment with default true
+-
+ !record {model: mail.message.subtype, id: mail_subtype_lead_comment }:
+ name: comment
+ model_ids:
+ - crm.model_crm_lead
+ default: True
+-
+ I have add the subtypes as won in feeds
+-
+ !python {model: mail.followers}: |
+ ids = self.search(cr, uid, [('res_model', '=', 'crm.lead'),('res_id', '=', ref('crm_case_1'))])
+ self.write(cr, uid, ids, {'subtype_ids': [(6,0,[ref('mail_subtype_lead_won')])]})
+-
+ I have change the lead into mark won
+-
+ !python {model: crm.lead}: |
+ self.convert_opportunity(cr, uid ,[ref("crm_case_1")], ref("base.res_partner_4"))
+ self.case_mark_won(cr, uid,[ref("crm_case_1")] )
+-
+ I have check the lead into mark won
+-
+ !assert {model: crm.lead, id: crm_case_1 ,string: 'The record is not in won state'}:
+ - state == 'done'
+-
+ I have check the subtype as won in feeds
+-
+ !python {model: mail.followers}: |
+ followers_ids =self.search(cr, uid, [('res_model', '=','crm.lead'),('res_id', '=', ref('crm_case_1')),('subtype_ids', 'in',[ref('mail_subtype_lead_won')])])
+ if len(followers_ids):
+ assert followers_ids, 'lead is in won'
=== modified file 'mail/__init__.py'
--- mail/__init__.py 2012-08-15 19:56:52 +0000
+++ mail/__init__.py 2012-08-29 10:53:37 +0000
@@ -19,6 +19,7 @@
#
##############################################################################
+import mail_message_subtype
import mail_alias
import mail_message
import mail_followers
=== modified file 'mail/__openerp__.py'
--- mail/__openerp__.py 2012-08-22 13:02:32 +0000
+++ mail/__openerp__.py 2012-08-29 10:53:37 +0000
@@ -62,6 +62,7 @@
'depends': ['base', 'base_tools', 'base_setup'],
'data': [
'wizard/mail_compose_message_view.xml',
+ 'mail_message_subtype.xml',
'res_config_view.xml',
'mail_message_view.xml',
'mail_followers_view.xml',
=== modified file 'mail/data/mail_group_data.xml'
--- mail/data/mail_group_data.xml 2012-08-14 15:26:34 +0000
+++ mail/data/mail_group_data.xml 2012-08-29 10:53:37 +0000
@@ -14,7 +14,7 @@
<!-- notify all employees of module installation -->
<function model="mail.group" name="message_append_note">
- <!-- ids, subject, body, parent_id=False, type='notification', content_subtype='html' -->
+ <!-- ids, subject,subtype_id="other", body, parent_id=False, type='notification', content_subtype='html' -->
<value eval="[ref('mail.group_all_employees')]"/>
<value>Welcome to OpenERP!</value>
<value>Your homepage is a summary of messages you received and key information about documents you follow.
=== modified file 'mail/mail_followers.py'
--- mail/mail_followers.py 2012-08-13 19:10:06 +0000
+++ mail/mail_followers.py 2012-08-29 10:53:37 +0000
@@ -45,6 +45,10 @@
help='Id of the followed resource'),
'user_id': fields.many2one('res.users', string='Related User',
ondelete='cascade', required=True, select=1),
+ 'subtype_ids': fields.many2many('mail.message.subtype',
+ 'mail_message_subtyp_rel',
+ 'subscription_id', 'subtype_id', 'Subtype',
+ help = "linking some subscription to several subtype for projet/task"),
}
class mail_notification(osv.Model):
=== modified file 'mail/mail_followers_view.xml'
--- mail/mail_followers_view.xml 2012-08-15 19:56:52 +0000
+++ mail/mail_followers_view.xml 2012-08-29 10:53:37 +0000
@@ -17,6 +17,28 @@
</field>
</record>
+ <record model="ir.ui.view" id="view_mail_subscription_form">
+ <field name="name">mail.followers.form</field>
+ <field name="model">mail.followers</field>
+ <field name="type">form</field>
+ <field name="arch" type="xml">
+ <form string="Followers Form" version="7.0">
+ <sheet>
+ <group>
+ <group>
+ <field name="res_model"/>
+ <field name="user_id"/>
+ </group>
+ <group>
+ <field name="res_id"/>
+ <field name="subtype_ids" widget="many2many_tags"/>
+ </group>
+ </group>
+ </sheet>
+ </form>
+ </field>
+ </record>
+
<!-- NOTIFICATION !-->
<record model="ir.ui.view" id="view_notification_tree">
<field name="name">mail.notification.tree</field>
=== modified file 'mail/mail_message.py'
--- mail/mail_message.py 2012-08-14 15:26:34 +0000
+++ mail/mail_message.py 2012-08-29 10:53:37 +0000
@@ -234,6 +234,7 @@
select=True, ondelete='set null',
help="Parent message, used for displaying as threads with hierarchy"),
'child_ids': fields.one2many('mail.message', 'parent_id', 'Child Messages'),
+ 'subtype_id': fields.many2one('mail.message.subtype', 'Subtype'),
}
_defaults = {
@@ -278,7 +279,7 @@
def create(self, cr, uid, values, context=None):
self.check(cr, uid, [], mode='create', context=context, values=values)
return super(mail_message, self).create(cr, uid, values, context)
-
+
def read(self, cr, uid, ids, fields_to_read=None, context=None, load='_classic_read'):
self.check(cr, uid, ids, 'read', context=context)
return super(mail_message, self).read(cr, uid, ids, fields_to_read, context, load)
=== added file 'mail/mail_message_subtype.py'
--- mail/mail_message_subtype.py 1970-01-01 00:00:00 +0000
+++ mail/mail_message_subtype.py 2012-08-29 10:53:37 +0000
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2009-today OpenERP SA (<http://www.openerp.com>)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+#
+##############################################################################
+
+from osv import osv
+from osv import fields
+
+class mail_message_subtype(osv.osv):
+
+ _name = 'mail.message.subtype'
+ _description = 'mail_message_subtype'
+ _columns = {
+ 'name': fields.char(' Message Subtype ', size = 128,
+ required = True, select = 1,
+ help = 'Subtype Of Message'),
+ 'model_ids': fields.many2many('ir.model',
+ 'mail_message_subtyp_message_rel',
+ 'message_subtype_id', 'model_id', 'Model',
+ help = "link some subtypes to several models, for projet/task"),
+ 'default': fields.boolean('Default', help = "When subscribing to the document, users will receive by default messages related to this subtype unless they uncheck this subtype"),
+ }
+ _defaults = {
+ 'default': True,
+ }
+ _sql_constraints = [
+ ('name_uniq', 'unique (name)', 'The name of the message subtype must be unique !')
+ ]
=== added file 'mail/mail_message_subtype.xml'
--- mail/mail_message_subtype.xml 1970-01-01 00:00:00 +0000
+++ mail/mail_message_subtype.xml 2012-08-29 10:53:37 +0000
@@ -0,0 +1,56 @@
+<?xml version="1.0"?>
+<openerp>
+ <data>
+
+ <!--
+ SUBTYPES
+ !-->
+
+ <record model="ir.ui.view" id="view_message_subtype_tree">
+ <field name="name">mail.message.subtype.tree</field>
+ <field name="model">mail.message.subtype</field>
+ <field name="type">tree</field>
+ <field name="priority">10</field>
+ <field name="arch" type="xml">
+ <tree string="Subtype">
+ <field name="name"/>
+ <field name="model_ids" invisible="1"/>
+ <field name="default"/>
+ </tree>
+ </field>
+ </record>
+
+ <record model="ir.ui.view" id="view_mail_message_subtype_form">
+ <field name="name">mail.message.subtype.form</field>
+ <field name="model">mail.message.subtype</field>
+ <field name="type">form</field>
+ <field name="arch" type="xml">
+ <form string="Email message" version="7.0">
+ <sheet>
+ <group>
+ <group>
+ <field name="name"/>
+ </group>
+ <group>
+ <field name="default"/>
+ </group>
+ </group>
+ <separator string="Models"/>
+ <field name="model_ids" widget="many2many"/>
+ </sheet>
+ </form>
+ </field>
+ </record>
+
+ <record id="action_view_message_subtype" model="ir.actions.act_window">
+ <field name="name">Subtypes</field>
+ <field name="res_model">mail.message.subtype</field>
+ <field name="view_type">form</field>
+ <field name="view_mode">tree,form</field>
+ </record>
+
+ <menuitem name="Subtypes" id="menu_message_subtype" parent="base.menu_email"
+ action="action_view_message_subtype"/>
+
+ </data>
+</openerp>
=== modified file 'mail/mail_message_view.xml'
--- mail/mail_message_view.xml 2012-08-14 13:10:03 +0000
+++ mail/mail_message_view.xml 2012-08-29 10:53:37 +0000
@@ -145,6 +145,7 @@
<group>
<field name="auto_delete"/>
<field name="type"/>
+ <field name="subtype_id"/>
<field name="content_subtype"/>
<field name="state" colspan="2"/>
<field name="mail_server_id"/>
=== modified file 'mail/mail_thread.py'
--- mail/mail_thread.py 2012-08-22 12:58:26 +0000
+++ mail/mail_thread.py 2012-08-29 10:53:37 +0000
@@ -260,7 +260,7 @@
# mail.message wrappers and tools
#------------------------------------------------------
- def message_create(self, cr, uid, thread_id, vals, context=None):
+ def message_create(self, cr, uid, thread_id, vals, context = None):
""" OpenChatter: wrapper of mail.message create method
- creates the mail.message
- automatically subscribe the message writer
@@ -268,7 +268,19 @@
"""
if context is None:
context = {}
-
+
+ notification_obj = self.pool.get('mail.notification')
+ followers_obj = self.pool.get('mail.followers')
+ subtype_obj = self.pool.get('mail.message.subtype')
+ subtype_name = vals.get('subtype')
+ subtype = False
+ body = vals.get('body_html', '') if vals.get('content_subtype') == 'html' else vals.get('body_text', '')
+ if subtype_name:
+ subtypes = subtype_obj.name_search(cr, uid, subtype_name)
+ if len(subtypes):
+ subtype = subtype_obj.browse(cr, uid, subtypes[0][0])
+ if self._name in [model.model for model in subtype.model_ids]:
+ vals['subtype_id']=subtype.id
# create message
msg_id = self.pool.get('mail.message').create(cr, uid, vals, context=context)
@@ -280,37 +292,48 @@
self.message_subscribe(cr, uid, [thread_id], [vals.get('user_id')], context=context)
# Set as unread if writer is not the document responsible
- self.message_create_set_unread(cr, uid, [thread_id], context=context)
+ self.message_create_set_unread(cr, uid, [thread_id], context = context)
# special: if install mode, do not push demo data
if context.get('install_mode', False):
return msg_id
# get users that will get a notification pushed
- notification_obj = self.pool.get('mail.notification')
- user_to_push_ids = self.message_get_user_ids_to_notify(cr, uid, [thread_id], vals, context=context)
- for id in user_to_push_ids:
- notification_obj.create(cr, uid, {'user_id': id, 'message_id': msg_id}, context=context)
+ subtype_id = subtype and subtype.id or False
+ user_to_push_ids = self.message_get_user_ids_to_notify(cr, uid, [thread_id], vals, subtype_id, context = context)
+
+ for user_id in user_to_push_ids:
+ notification_obj.create(cr, uid, {'user_id': user_id, 'message_id': msg_id}, context = context)
# create the email to send
self.message_create_notify_by_email(cr, uid, vals, user_to_push_ids, context=context)
return msg_id
-
- def message_get_user_ids_to_notify(self, cr, uid, thread_ids, new_msg_vals, context=None):
+
+ def message_get_user_ids_to_notify(self, cr, uid, thread_ids, new_msg_vals, subtype_id=None, context=None):
# get body
body = new_msg_vals.get('body_html', '') if new_msg_vals.get('content_subtype') == 'html' else new_msg_vals.get('body_text', '')
# get subscribers
subscr_obj = self.pool.get('mail.followers')
subscr_ids = subscr_obj.search(cr, uid, ['&', ('res_model', '=', self._name), ('res_id', 'in', thread_ids)], context=context)
- notif_user_ids = [sub['user_id'][0] for sub in subscr_obj.read(cr, uid, subscr_ids, ['user_id'], context=context)]
+ notif_user_ids = []
+ # check with subtype
+ is_subtype = False
+ for subscription in subscr_obj.browse(cr, uid, subscr_ids, context=context):
+ if subtype_id:
+ if subtype_id in [subtype.id for subtype in subscription.subtype_ids]:
+ is_subtype = True
+ notif_user_ids.append(subscription.user_id.id)
+ else:
+ notif_user_ids.append(subscription.user_id.id)
# add users requested to perform an action (need_action mechanism)
if hasattr(self, 'get_needaction_user_ids') and self._columns.get('user_id'):
user_ids_dict = self.get_needaction_user_ids(cr, uid, thread_ids, context=context)
for id, user_ids in user_ids_dict.iteritems():
- notif_user_ids += user_ids
+ if is_subtype:
+ notif_user_ids += user_ids
# add users notified of the parent messages (because: if parent message contains @login, login must receive the replies)
if new_msg_vals.get('parent_id'):
@@ -336,12 +359,12 @@
return ret_dict
def message_append(self, cr, uid, threads, subject, body_text=None, body_html=None,
- type='email', email_date=None, parent_id=False,
+ type = 'email', email_date = None, parent_id = False,
content_subtype='plain', state=None,
partner_ids=None, email_from=False, email_to=False,
email_cc=None, email_bcc=None, reply_to=None,
headers=None, message_id=False, references=None,
- attachments=None, original=None, context=None):
+ attachments=None, original=None, subtype = "other", context=None):
""" Creates a new mail.message through message_create. The new message
is attached to the current mail.thread, containing all the details
passed as parameters. All attachments will be attached to the
@@ -391,6 +414,8 @@
:param dict context: if a ``thread_model`` value is present in the
context, its value will be used to determine the model of the
thread to update (instead of the current model).
+ :param subtype: subtype of message: 'email', 'comment', 'notification';
+ other by default
"""
if context is None:
context = {}
@@ -433,9 +458,11 @@
if partner_ids is None:
partner_ids = []
mail_partner_ids = [(6, 0, partner_ids)]
-
+ if type in ['email', 'comment']:
+ subtype = type
data = {
'subject': subject,
+ 'subtype': subtype,
'body_text': body_text or thread._model._columns.get('description') and thread.description or '',
'body_html': body_html or '',
'parent_id': parent_id,
@@ -465,7 +492,8 @@
'references': references,
'headers': headers,
'reply_to': reply_to,
- 'original': original, })
+ 'original': original,
+ })
new_msg_ids.append(self.message_create(cr, uid, thread.id, data, context=context))
return new_msg_ids
@@ -507,6 +535,7 @@
attachments = msg_dict.get('attachments'),
headers = msg_dict.get('headers'),
original = msg_dict.get('original'),
+ subtype = msg_dict.get('subtype','other'),
context = context)
#------------------------------------------------------
@@ -990,16 +1019,16 @@
self.message_append_note(cr, uid, [id], 'res.log', message, context=context)
def message_append_note(self, cr, uid, ids, subject=None, body=None, parent_id=False,
- type='notification', content_subtype='html', context=None):
+ type='notification', content_subtype='html', subtype='other', context=None):
if content_subtype == 'html':
body_html = body
body_text = body
else:
body_html = body
body_text = body
- return self.message_append(cr, uid, ids, subject, body_html, body_text,
- type, parent_id=parent_id,
- content_subtype=content_subtype, context=context)
+ return self.message_append(cr, uid, ids, subject, body_text, body_html,
+ type, parent_id = parent_id,
+ content_subtype=content_subtype, subtype=subtype, context=context)
#------------------------------------------------------
# Subscription mechanism
@@ -1011,7 +1040,7 @@
"""
return []
- def message_subscribe(self, cr, uid, ids, user_ids = None, context=None):
+ def message_subscribe(self, cr, uid, ids, user_ids = None, subtype_ids = None, context = None):
""" Subscribe the user (or user_ids) to the current document.
:param user_ids: a list of user_ids; if not set, subscribe
@@ -1020,7 +1049,13 @@
"""
to_subscribe_uids = [uid] if user_ids is None else user_ids
write_res = self.write(cr, uid, ids, {'message_follower_ids': self.message_subscribe_get_command(cr, uid, to_subscribe_uids, context)}, context=context)
- return [follower.id for thread in self.browse(cr, uid, ids, context=context) for follower in thread.message_follower_ids]
+ follower_ids = [follower.id for thread in self.browse(cr, uid, ids, context=context) for follower in thread.message_follower_ids]
+ if not subtype_ids:
+ subtype_obj = self.pool.get('mail.message.subtype')
+ subtype_ids = subtype_obj.search(cr, uid, [('default', '=', 'true'),('model_ids.model', '=', self._name)])
+ if subtype_ids:
+ self.message_subscribe_udpate_subtypes(cr, uid, ids, to_subscribe_uids, subtype_ids, context=context)
+ return follower_ids
def message_subscribe_get_command(self, cr, uid, follower_ids, context=None):
""" Generate the many2many command to add followers. """
@@ -1158,10 +1193,25 @@
for obj in self.browse(cr, uid, ids, context=context):
if not obj.message_state and self._columns.get('user_id') and obj.user_id and obj.user_id.id == uid:
self.message_mark_as_read(cr, uid, [obj.id], context=context)
-
+
def message_mark_as_read(self, cr, uid, ids, context=None):
""" Set as read. """
return self.write(cr, uid, ids, {'message_state': True}, context=context)
-
+ def message_subscribe_udpate_subtypes(self, cr, uid, ids, user_id, subtype_ids,context=None):
+ subscription_obj = self.pool.get('mail.followers')
+ subscription_ids = subscription_obj.search(cr, uid, [('res_model', '=', self._name), ('res_id', 'in', ids),('user_id','in',user_id)])
+ return subscription_obj.write(cr, uid, subscription_ids, {'subtype_ids': [(6, 0 , subtype_ids)]}, context = context) #overright or add new one
+
+ def message_subscription_remove_subtype(self, cr, uid, ids, user_id, subtype_id):
+ subscription_obj = self.pool.get('mail.followers')
+ subscription_ids = subscription_obj.search(cr, uid, [('res_model', '=', self._name), ('res_id', 'in', ids)])
+ return subscription_obj.write(cr, uid, subscription_ids, {'subtype_ids': [3, subtype_id]}, context = context) # remove link
+
+ def message_subscription_remove_subtype_name(self, cr, uid, ids, user_id, subtype_name):
+ subtype_obj = self.pool.get('mail.message.subtype')
+ subtype_ids = subtype_obj.search(cr, uid, [('name', '=', subtype_name), ('model_ids', '=', self._name)])
+ if not subtype_ids:
+ return False
+ self.message_subscription_remove_subtype(cr, uid, ids, user_id, subtype_ids)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== modified file 'mail/security/ir.model.access.csv'
--- mail/security/ir.model.access.csv 2012-08-13 19:38:41 +0000
+++ mail/security/ir.model.access.csv 2012-08-29 10:53:37 +0000
@@ -7,3 +7,4 @@
access_mail_group,mail.group,model_mail_group,base.group_user,1,1,1,1
access_mail_alias_user,mail.alias,model_mail_alias,base.group_user,1,1,1,0
access_mail_alias_system,mail.alias,model_mail_alias,base.group_system,1,1,1,1
+access_mail_message_subtype,mail.message.subtype,model_mail_message_subtype,,1,1,1,1
\ No newline at end of file
=== modified file 'mail/static/src/js/mail_followers.js'
--- mail/static/src/js/mail_followers.js 2012-08-24 18:27:43 +0000
+++ mail/static/src/js/mail_followers.js 2012-08-29 10:53:37 +0000
@@ -31,7 +31,9 @@
this.params.display_control = this.node.attrs.display_control || false;
this.params.display_actions = this.node.attrs.display_actions || false;
this.ds_model = new session.web.DataSetSearch(this, this.view.model);
+ this.sub_model = new session.web.DataSetSearch(this,'mail.message.subtype')
this.ds_follow = new session.web.DataSetSearch(this, this.field.relation);
+ this.follower_model = new session.web.DataSetSearch(this,'mail.followers')
},
start: function() {
@@ -40,10 +42,18 @@
// any other method to know if the view is in create mode anymore
this.view.on("change:actual_mode", this, this._check_visibility);
this._check_visibility();
+ this.fetch_subtype();
+ this.$el.find('div.oe_mail_recthread_subtype').click(function () {self.update_subtype();})
this.$el.find('button.oe_mail_button_followers').click(function () { self.do_toggle_followers(); });
+
if (! this.params.display_control) {
- this.$el.find('button.oe_mail_button_followers').hide(); }
- this.$el.find('button.oe_mail_button_follow').click(function () { self.do_follow(); })
+ this.$el.find('button.oe_mail_button_followers').hide();
+ this.$el.find('div.oe_mail_recthread_subtype').hide()
+ }
+ this.$el.find('button.oe_mail_button_follow').click(function () {
+ self.do_follow();
+ self.fetch_subtype();
+ })
.mouseover(function () { $(this).html('Follow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); })
.mouseleave(function () { $(this).html('Not following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); });
this.$el.find('button.oe_mail_button_unfollow').click(function () { self.do_unfollow(); })
@@ -54,6 +64,7 @@
_check_visibility: function() {
this.$el.toggle(this.view.get("actual_mode") !== "create");
+ if (this.view.get("actual_mode") !== "create"){this.fetch_subtype();}
},
destroy: function () {
@@ -67,6 +78,7 @@
this.$el.find('button.oe_mail_button_followers').html('Hide followers')
this.$el.find('button.oe_mail_button_follow').hide();
this.$el.find('button.oe_mail_button_unfollow').hide();
+ this.$el.find('div.oe_mail_recthread_subtype').hide()
},
set_value: function(value_) {
@@ -89,6 +101,7 @@
display_subscribers: function (records) {
var self = this;
this.is_subscriber = false;
+ //if (self.view.get("actual_mode") === "edit"){self.fetch_subtype();}
var user_list = this.$el.find('ul.oe_mail_followers_display').empty();
this.$el.find('div.oe_mail_recthread_followers h4').html(this.params.title + ' (' + records.length + ')');
_(records).each(function (record) {
@@ -98,15 +111,55 @@
});
if (this.is_subscriber) {
this.$el.find('button.oe_mail_button_follow').hide();
- this.$el.find('button.oe_mail_button_unfollow').show(); }
+ this.$el.find('button.oe_mail_button_unfollow').show();
+ this.$el.find('div.oe_mail_recthread_subtype').show(); }
else {
this.$el.find('button.oe_mail_button_follow').show();
- this.$el.find('button.oe_mail_button_unfollow').hide(); }
- },
-
+ this.$el.find('button.oe_mail_button_unfollow').hide();
+ this.$el.find('div.oe_mail_recthread_subtype').hide() }
+ },
+ update_subtype: function (){
+ var self = this;
+ var cheklist = new Array();
+ _(this.$el.find('.oe_msg_subtype_check')).each(function(record){
+ if($(record).is(':checked')) {
+ cheklist.push(parseInt($(record).attr('id')))}
+ });
+ self.ds_model.call('message_subscribe_udpate_subtypes',[[self.view.datarecord.id],[self.session.uid],cheklist])
+ },
+ // Display the subtypes of each records.
+ display_subtype: function(records) {
+ var self = this
+ var subtype_list = this.$el.find('div.oe_mail_recthread_subtype').empty();
+ var follower_ids = this.follower_model.call('search',[[['res_model','=',this.ds_model.model],['res_id','=',this.view.datarecord.id],['user_id','=',this.session.uid]]])
+ follower_ids.then(function (record){
+ var follower_read = self.follower_model.call('read', [record,['subtype_ids']]);
+ follower_read.then(function (follower_record){
+ if(follower_record.length != 0){
+ _(follower_record[0].subtype_ids).each(function (subtype_id){
+ self.$el.find('.oe_msg_subtype_check[id=' + subtype_id + ']')[0].checked=true
+ });
+ }
+ })
+ });
+ _(records).each(function (record) {
+ record.name = record.name.toLowerCase().replace(/\b[a-z]/g, function(letter) {return letter.toUpperCase();});
+ $(session.web.qweb.render('mail.record_thread.subtype', {'record': record})).appendTo(subtype_list);
+ });
+ },
+
do_follow: function () {
return this.ds_model.call('message_subscribe', [[this.view.datarecord.id]]).pipe(this.proxy('set_value'));
},
+
+ //fetch subtype from subtype model
+ fetch_subtype: function () {
+ var self = this
+ var subtype_object = this.sub_model.call('search', [[['model_ids.model','=',this.view.model]]]);
+ subtype_object.then(function (subtype_ids){
+ self.sub_model.call('read', [subtype_ids || self.get_value(),['name', 'default']]).then(self.proxy('display_subtype'));
+ });
+ },
do_unfollow: function () {
return this.ds_model.call('message_unsubscribe', [[this.view.datarecord.id]]).pipe(this.proxy('set_value'));
=== modified file 'mail/static/src/xml/mail_followers.xml'
--- mail/static/src/xml/mail_followers.xml 2012-08-15 23:26:49 +0000
+++ mail/static/src/xml/mail_followers.xml 2012-08-29 10:53:37 +0000
@@ -3,7 +3,7 @@
<!--
followers main template
- Template used to display the followers and the actions in a record.
+ Template used to display the followers, the actions and the subtypes in a record.
-->
<div t-name="mail.followers" class="oe_mail_recthread_aside">
<div class="oe_mail_recthread_actions">
@@ -11,6 +11,7 @@
<button type="button" class="oe_mail_button_unfollow oe_mail_button_mouseout">Following</button>
<button type="button" class="oe_mail_button_followers">Show followers</button>
</div>
+ <div class="oe_mail_recthread_subtype"></div>
<div class="oe_mail_recthread_followers">
<t t-if="widget.params.title">
<h4><t t-raw="widget.params.title"/></h4>
@@ -26,6 +27,23 @@
<li t-name="mail.followers.partner">
<img class="oe_mail_thumbnail oe_mail_frame" t-attf-src="{record.avatar_url}"/>
<a t-attf-href="#model=res.users&id=#{record.id}"><t t-raw="record.name"/></a>
- </li>
+ </li>\
+
+ <!--
+ record_thread.subtype template
+ Template used to display subtype of record
+ -->
+ <div t-name="mail.record_thread.subtype">
+ <table width="50%">
+ <tr>
+ <td>
+ <a t-attf-href="#model=mail.message.subtype&id=#{record.id}"><t t-raw="record.name"/></a>
+ </td>
+ <td width="10%">
+ <input type="checkbox" t-att-id="record.id" t-att-name="record.name" class="oe_msg_subtype_check"/>
+ </td>
+ </tr>
+ </table>
+ </div>
</template>
=== modified file 'project/project.py'
--- project/project.py 2012-08-22 16:32:37 +0000
+++ project/project.py 2012-08-29 10:53:37 +0000
@@ -1117,6 +1117,10 @@
def create(self, cr, uid, vals, context=None):
task_id = super(task, self).create(cr, uid, vals, context=context)
+ task_record = self.browse(cr, uid, task_id, context=context)
+ if task_record.project_id:
+ project_follower_ids = [follower.id for follower in task_record.project_id.message_follower_ids]
+ self.message_subscribe(cr, uid, [task_id], project_follower_ids, context=context)
self._store_history(cr, uid, [task_id], context=context)
self.create_send_note(cr, uid, [task_id], context=context)
return task_id
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp