Saurang Suthar(OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-calendar-phase1-email_templte-ssu into 
lp:~openerp-dev/openobject-addons/trunk-calendar-phase1.

Requested reviews:
  Jigar Amin  (OpenERP) (jam-openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-calendar-phase1-email_templte-ssu/+merge/91648

Hello sir,

I have improved the alarm notification and invitation notification for email 
template.

Thank you.
   SSU
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-calendar-phase1-email_templte-ssu/+merge/91648
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-calendar-phase1.
=== modified file 'base_calendar/calendar_alarm.py'
--- base_calendar/calendar_alarm.py	2012-02-01 06:01:25 +0000
+++ base_calendar/calendar_alarm.py	2012-02-06 12:58:25 +0000
@@ -67,7 +67,6 @@
         'interval_number': fields.integer('Duration', required=True),
         'action': fields.selection([('internal', 'Internal Request'), ('email', 'Email') ], 'Action', \
                 required=True, help="Defines the action to be invoked when an alarm is triggered"),
-
         'event_id': fields.many2one('calendar.event', 'Event', required=True, ondelete='cascade'),
         'user_id': fields.many2one('res.users', 'User', required=True, ondelete='cascade'),
      }
@@ -142,9 +141,10 @@
         """Scheduler for event reminder
         """
         request_obj = self.pool.get('res.request')
-        alarm = self.browse(cr, uid, alarm_id, context=context)
+        alarm = self.browse(cr, uid, alarm_id, context)
         event = alarm.event_id
-        message_pool = self.pool.get('mail.message')
+        email_template = self.pool.get('email.template')
+        
         if alarm.action == 'internal':
             value = {
                'name': event.name,
@@ -153,24 +153,18 @@
                'body': event.description,
                'trigger_date': event.date,
                'ref_doc1': event._name + ',' + str(event.id)
-            }
+                    }
             request_id = request_obj.create(cr, uid, value)
-
+    
         if alarm.action == 'email':
             subject = '[Reminder] %s' % (event.name)
             body = event.description
-            mail_to = [event.user_id.user_email]
-            mail_from = event.organizer_id and event.organizer_id.user_email or False
+            mail_to = [event.user_id.user_email or '']
+            mail_from = event.organizer_id or event.organizer_id.user_email or 'noreply@localhost'
+                
             if mail_to and mail_from:
-                message_pool.schedule_with_attach(cr, uid,
-                                                    mail_from,
-                                                    mail_to,
-                                                    subject,
-                                                    body,
-                                                    model='calendar.event',
-                                                    res_id=event.id,
-                                                    context=context)
-        self.unregister_cron(cr, uid, [alarm.id], context)
+                email_template.send_mail(cr, uid, event.alarm_email_template_id.id, event.id, force_send=True, context=context)
+        self.unregister_cron(cr, uid, [alarm.id], context=context)
         return True
 
 calendar_alarm()
@@ -180,9 +174,10 @@
     _columns = {
         'alarm_ids': fields.one2many('calendar.alarm', 'event_id', 'Alarms',
                         help="Set an alarm at this time, before the event occurs" ),
+        'alarm_email_template_id': fields.many2one('email.template', 'Alarm Email Template'),
     }
     def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
         # update alarm details if date of event changed
         return super(calendar_event, self).write(cr, uid, ids, vals, context=context, check=check, update_check=update_check)
 
-calendar_event()
+calendar_event()
\ No newline at end of file

=== modified file 'base_calendar/calendar_attendee.py'
--- base_calendar/calendar_attendee.py	2011-08-04 12:58:47 +0000
+++ base_calendar/calendar_attendee.py	2012-02-06 12:58:25 +0000
@@ -148,7 +148,8 @@
             'Attendee Request', type="many2one", multi='attendee_request_id', relation='calendar.attendee'),
         'attendee_request_state': fields.function(_compute, fnct_inv=_set_attendee, string='Request State', multi='attendee_request_state', type='selection', selection=ATTENDEE_STATE),
         'total_members': fields.function(_compute, fnct_inv=_set_attendee, string='Members', multi='total_members', type='integer'),
-        'notification': fields.boolean('Send Notification', help="Send email to all attendee if any update on event")
+        'notification': fields.boolean('Send Notification', help="Send email to all attendee if any update on event"),
+        'attendee_notification_email_template_id': fields.many2one('email.template', 'Attendee Notification Email Template'),
     }
     _defaults = {
         'notification': True,
@@ -156,13 +157,21 @@
     
     def write(self, cr, uid, ids, vals, context=None):
         res = super(calendar_event, self).write(cr, uid, ids, vals, context=context)
+        email_template = self.pool.get('email.template')
+        event = self.pool.get('calendar.event')
         if res:
             # Modify status of Events Invitation if Time changed
             attendee_pool = self.pool.get('calendar.attendee')
+
             for event in self.browse(cr, uid, ids, context=context):
                 for attendee in event.attendee_ids:
                     if filter(lambda x: x in ['date', 'date_deadline', 'duration'], vals.keys()):
                         attendee_pool.write(cr, uid, [attendee.id], {'state': 'draft'}, context)
+                for attendee in event.attendee_ids:
+                    email = attendee_pool.browse(cr, uid, event.attendee_ids, context)
+                    if filter(lambda x: x in ['date', 'date_deadline', 'location'], vals.keys()):
+                        if email:
+                            email_template.send_mail(cr, uid, event.attendee_notification_email_template_id.id, attendee.id, force_send=False, context=context)
         return res
     
     def do_attendee_request_accept(self, cr, uid, ids, context=None):
@@ -171,7 +180,6 @@
         """
         return self.write(cr, uid, ids, {'attendee_request_state': 'accepted'}, context)
 
-
     def do_attendee_request_decline(self, cr, uid, ids, context=None):
         """ Marks event invitation as Declined
         """

=== modified file 'base_calendar/calendar_data.xml'
--- base_calendar/calendar_data.xml	2012-02-01 08:57:49 +0000
+++ base_calendar/calendar_data.xml	2012-02-06 12:58:25 +0000
@@ -61,4 +61,33 @@
         </record>
 
     </data>
+    
+	<data>
+		<!-- Calendar Attendee -->
+        <record id="calendar_attendee_email_template" model="email.template">
+        	<field name="name">Attendee Invitation</field>
+            <field name="subject">Invitation : ${object.event_id.name}</field>
+            <field name="email_from">${object.event_id.organizer_id.user_email or 'noreply'}</field>
+            <field name="email_to">${object.event_id.user_id.user_email or ''}</field>
+            <field name="model_id" ref="model_calendar_attendee"/>
+            <field eval="0" name="user_signature"/>
+            <field name="body_text">Hello  ${object.partner_id.name} ,
+You are invited to attend meeting '${object.event_id.name}' scheduled on ${object.event_id.date}.
+Kindly confirm your invitation.
+Thank you</field>
+        </record>
+
+       <!-- Calendar Alarm -->        
+        <record id="calendar_alarm_email_template" model="email.template">
+        	<field name="name">Event Alarm</field>
+            <field name="subject">[${object.id}]Event Alarm:${object.name}</field>
+            <field name="email_from">${object.organizer_id.user_email or '''noreply@localhost'''}</field>
+            <field name="email_to">${object.user_id.user_email or '''False'''}</field>
+            <field name="model_id" ref="model_calendar_event"/>
+            <field eval="0" name="user_signature"/>
+            <field name="body_text">Hello ,
+Your event reminder for meeting '${object.name}', kindly check your invitation and meeting details.
+Thank you.</field>  
+        </record>
+	</data>
 </openerp>

=== modified file 'base_calendar/calendar_event_recurrent.py'
--- base_calendar/calendar_event_recurrent.py	2012-02-01 06:01:25 +0000
+++ base_calendar/calendar_event_recurrent.py	2012-02-06 12:58:25 +0000
@@ -117,13 +117,13 @@
         """
         if not context:
             context = {}
-        virtual_id = context and context.get('virtual_id', False) or False
+        virtual_id = context and context.get('virtual_id', True) or False
         if isinstance(select, (str, int, long)):
             ids = [select]
         else:
             ids = select
         result = []
-        if ids and virtual_id:
+        if ids and context.get('virtual_id', True):
             datas = super(calendar_event, self).read(cr, uid, ids, context=context)
             result = recurrent_tools.compute_recurrent_ids(datas, base_start_date, base_until_date)
         if result:

=== modified file 'base_calendar/calendar_event_view.xml'
--- base_calendar/calendar_event_view.xml	2012-02-01 05:14:17 +0000
+++ base_calendar/calendar_event_view.xml	2012-02-06 12:58:25 +0000
@@ -111,7 +111,14 @@
                         <separator colspan="4" string="" />
                         </page>
                         <page string="Reminders">
+<<<<<<< TREE
                                 <field name="alarm_ids"  nolabel="1"  widget="one2many" mode="tree,form">
+=======
+                        		<group col="6" colspan="4">
+                        			<field name="alarm_email_template_id" attrs="{'readonly':[('notification','=', False)]}"/>
+                        		</group>
+                                <field name="alarm_ids"  nolabel="1"  widget="one2many" mode="tree,form" attrs="{'readonly': ['|', ('state', '=', 'done'), ('state', '=', 'cancel')]}">
+>>>>>>> MERGE-SOURCE
                                 <tree string="Reminder details" editable="top">
                                     <field name="interval_type" />
                                     <field name="interval_number"/>
@@ -131,7 +138,14 @@
                                 </form>
                         </field>
                         </page>
+<<<<<<< TREE
                         <page string="Attendees">
+=======
+                        <page string="Attendees"  attrs="{'readonly': ['|', ('state', '=', 'done'), ('state', '=', 'cancel')]}">
+                        	<group col="6" colspan="4">
+                        		<field name="attendee_notification_email_template_id" attrs="{'readonly':[('notification','=', False)]}"/>
+                        	</group>
+>>>>>>> MERGE-SOURCE
                             <field name="notification"/>
                             <button
                                 name="%(action_calendar_event_add_attendee_wizard)d"

_______________________________________________
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