Foram Katharotiya (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-message-sub-type-apa-mail-subtype-fka 
into lp:~openerp-dev/openobject-addons/trunk-message-sub-type-apa.

Requested reviews:
  Amit Patel (OpenERP) (apa-tiny)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-message-sub-type-apa-mail-subtype-fka/+merge/119346

hello sir,

 - I have create  mail.message.subtype model & views.
 - Add a subtype_ids in mail_subscription model & views.
 - Add subtype_id in mail.message model & views.
 - In mail_thread add add message_subscribe_udpate_subtypes,add 
message_subscription_remove_subtype, add 
message_subscription_remove_subtype_name methods.
 - Add data in crm_lead

Thanks,
FKA
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-message-sub-type-apa-mail-subtype-fka/+merge/119346
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-message-sub-type-apa.
=== modified file 'crm/crm_lead.py'
--- crm/crm_lead.py	2012-08-08 17:02:15 +0000
+++ crm/crm_lead.py	2012-08-13 13:22:47 +0000
@@ -278,6 +278,9 @@
 
     def create(self, cr, uid, vals, context=None):
         obj_id = super(crm_lead, self).create(cr, uid, vals, context)
+        obj = self.browse(cr, uid, obj_id, context)
+        if obj.user_id:
+            self.message_subscribe(cr, uid, [obj_id], [obj.user_id.id], context = context)
         self.create_send_note(cr, uid, [obj_id], context=context)
         return obj_id
 
@@ -859,18 +862,12 @@
     # OpenChatter methods and notifications
     # ----------------------------------------
 
-    def message_get_subscribers(self, cr, uid, ids, context=None):
-        """ Override to add the salesman. """
-        user_ids = super(crm_lead, self).message_get_subscribers(cr, uid, ids, context=context)
-        for obj in self.browse(cr, uid, ids, context=context):
-            if obj.user_id and not obj.user_id.id in user_ids:
-                user_ids.append(obj.user_id.id)
-        return user_ids
-
     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)
+        res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm', 'mail_subtype_lead_stage_change')
+        res_id = res[1]
+        return self.message_append_note(cr, uid, ids, body= _("Stage changed to <b>%s</b>.") % (stage_name), subtype_id=res_id,context=context)
 
     def case_get_note_msg_prefix(self, cr, uid, lead, context=None):
         if isinstance(lead, (int, long)):
@@ -880,33 +877,45 @@
     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)
+            res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm', 'mail_subtype_lead_new')
+            res_id = res[1]
+            self.message_append_note(cr, uid, [id], body=message, subtype_id=res_id, 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)
+        res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm', 'mail_subtype_lead_lost')
+        res_id = res[1]
+        return self.message_append_note(cr, uid, ids, body=message,subtype_id=res_id, 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)
+        res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm', 'mail_subtype_lead_won')
+        res_id = res[1]
+        return self.message_append_note(cr, uid, ids, body=message, subtype_id=res_id, 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]
         if action == 'log': prefix = 'Logged'
         else: prefix = 'Scheduled'
         message = _("<b>%s a call</b> for the <em>%s</em>.") % (prefix, phonecall.date)
-        return self.message_append_note(cr, uid, ids, body=message, context=context)
+        res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm', 'mail_subtype_lead_other')
+        res_id = res[1]
+        return self.message_append_note(cr, uid, ids, body=message, subtype_id=res_id, context=context)
 
     def _lead_set_partner_send_note(self, cr, uid, ids, context=None):
         for lead in self.browse(cr, uid, ids, context=context):
             message = _("%s <b>partner</b> is now set to <em>%s</em>." % (self.case_get_note_msg_prefix(cr, uid, lead, context=context), lead.partner_id.name))
-            lead.message_append_note(body=message)
+            res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm', 'mail_subtype_lead_other')
+            res_id = res[1]
+            lead.message_append_note(body=message, subtype_id=res_id)
         return True
 
     def convert_opportunity_send_note(self, cr, uid, lead, context=None):
         message = _("Lead has been <b>converted to an opportunity</b>.")
-        lead.message_append_note(body=message)
+        res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm', 'mail_subtype_lead_other')
+        res_id = res[1]
+        lead.message_append_note(body=message, subtype_id=res_id)
         return True
 
 crm_lead()

=== modified file 'crm/crm_lead_data.xml'
--- crm/crm_lead_data.xml	2012-08-07 06:06:05 +0000
+++ crm/crm_lead_data.xml	2012-08-13 13:22:47 +0000
@@ -156,5 +156,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>

=== modified file 'mail/__init__.py'
--- mail/__init__.py	2012-07-05 10:22:19 +0000
+++ mail/__init__.py	2012-08-13 13:22:47 +0000
@@ -19,6 +19,7 @@
 #
 ##############################################################################
 
+import mail_message_subtype
 import mail_alias
 import mail_message
 import mail_thread

=== modified file 'mail/__openerp__.py'
--- mail/__openerp__.py	2012-08-08 15:46:48 +0000
+++ mail/__openerp__.py	2012-08-13 13:22:47 +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_subscription_view.xml',

=== modified file 'mail/mail_message.py'
--- mail/mail_message.py	2012-07-20 12:57:29 +0000
+++ mail/mail_message.py	2012-08-13 13:22:47 +0000
@@ -230,6 +230,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', select = True),
     }
         
     _defaults = {
@@ -274,7 +275,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-13 13:22:47 +0000
@@ -0,0 +1,41 @@
+# -*- 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,
+    }

=== 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-13 13:22:47 +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-09 16:35:29 +0000
+++ mail/mail_message_view.xml	2012-08-13 13:22:47 +0000
@@ -150,6 +150,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_subscription.py'
--- mail/mail_subscription.py	2012-07-17 11:02:51 +0000
+++ mail/mail_subscription.py	2012-08-13 13:22:47 +0000
@@ -42,6 +42,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.osv):

=== modified file 'mail/mail_subscription_view.xml'
--- mail/mail_subscription_view.xml	2012-07-17 11:02:51 +0000
+++ mail/mail_subscription_view.xml	2012-08-13 13:22:47 +0000
@@ -20,6 +20,27 @@
             </field>
         </record>
 
+        <record model="ir.ui.view" id="view_mail_subscription_form">
+            <field name="name">mail.subscription.form</field>
+            <field name="model">mail.subscription</field>
+            <field name="type">form</field>
+            <field name="arch" type="xml">
+                <form string="Subscription 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
                 !-->

=== modified file 'mail/mail_thread.py'
--- mail/mail_thread.py	2012-08-07 12:03:35 +0000
+++ mail/mail_thread.py	2012-08-13 13:22:47 +0000
@@ -229,7 +229,7 @@
         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', subtype_id = False, 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,
@@ -335,6 +335,7 @@
                 'parent_id': parent_id,
                 'date': email_date or fields.datetime.now(),
                 'type': type,
+                'subtype_id' : subtype_id,
                 'content_subtype': content_subtype,
                 'state': state,
                 'message_id': message_id,
@@ -386,6 +387,7 @@
                             body_html= msg_dict.get('body_html'),
                             parent_id = msg_dict.get('parent_id', False),
                             type = msg_dict.get('type', 'email'),
+                            subtype_id = msg_dict.get('subtype_id', False),
                             content_subtype = msg_dict.get('content_subtype'),
                             state = msg_dict.get('state'),
                             partner_ids = msg_dict.get('partner_ids'),
@@ -865,7 +867,7 @@
                         now deprecated res.log.")
         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,
+    def message_append_note(self, cr, uid, ids, subject=None, subtype_id=False, body=None, parent_id=False,
                             type='notification', content_subtype='html', context=None):
         if content_subtype == 'html':
             body_html = body
@@ -874,7 +876,7 @@
             body_html = body
             body_text = body
         return self.message_append(cr, uid, ids, subject, body_html, body_text,
-                                    type, parent_id=parent_id,
+                                    type, subtype_id = subtype_id, parent_id = parent_id,
                                     content_subtype=content_subtype, context=context)
 
     #------------------------------------------------------
@@ -913,7 +915,7 @@
             return True
         return False
 
-    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
@@ -925,8 +927,13 @@
         for id in ids:
             already_subscribed_user_ids = self.message_get_subscribers(cr, uid, [id], context=context)
             for user_id in to_subscribe_uids:
-                if user_id in already_subscribed_user_ids: continue
-                create_ids.append(subscription_obj.create(cr, uid, {'res_model': self._name, 'res_id': id, 'user_id': user_id}, context=context))
+                res = {'res_model': self._name, 'res_id': id, 'user_id': user_id}
+                res['subtype_ids'] = [0, 0, {'res_model': self._name, 'default': True}]
+                if user_id in already_subscribed_user_ids:
+                    if subtype_ids:
+                        res['subtype_ids'] = [(6, 0, subtype_ids)]
+                    else: continue
+                create_ids.append(subscription_obj.create(cr, uid, res, context = context))
         return create_ids
 
     def message_unsubscribe(self, cr, uid, ids, user_ids = None, context=None):
@@ -1066,10 +1073,25 @@
         for obj in self.browse(cr, uid, ids, context=context):
             if not obj.message_state and hasattr(obj, '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):
+        subscription_obj = self.pool.get('mail.subscription')
+        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': [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.subscription')
+        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:

_______________________________________________
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

Reply via email to