[MERGE] Forward-port of latest 7.0 bugfixes, up to rev. 9846 revid:dle@openerp.com...
[odoo/odoo.git] / addons / event / event.py
index 399d3d6..72894ea 100644 (file)
@@ -20,8 +20,8 @@
 ##############################################################################
 
 from datetime import datetime, timedelta
-from osv import fields, osv
-from tools.translate import _
+from openerp.osv import fields, osv
+from openerp.tools.translate import _
 from openerp import SUPERUSER_ID
 
 class event_type(osv.osv):
@@ -41,14 +41,13 @@ class event_type(osv.osv):
         'default_registration_max': 0,
     }
 
-event_type()
 
 class event_event(osv.osv):
     """Event"""
     _name = 'event.event'
     _description = __doc__
     _order = 'date_begin'
-    _inherit = ['mail.thread','ir.needaction_mixin']
+    _inherit = ['mail.thread', 'ir.needaction_mixin']
 
     def name_get(self, cr, uid, ids, context=None):
         if not ids:
@@ -67,11 +66,6 @@ class event_event(osv.osv):
             res.append((record['id'], display_name))
         return res
 
-    def create(self, cr, uid, vals, context=None):
-        obj_id = super(event_event, self).create(cr, uid, vals, context)
-        self.create_send_note(cr, uid, [obj_id], context=context)
-        return obj_id
-
     def copy(self, cr, uid, id, default=None, context=None):
         """ Reset the state and the registrations while copying an event
         """
@@ -84,7 +78,6 @@ class event_event(osv.osv):
         return super(event_event, self).copy(cr, uid, id, default=default, context=context)
 
     def button_draft(self, cr, uid, ids, context=None):
-        self.button_draft_send_note(cr, uid, ids, context=context)
         return self.write(cr, uid, ids, {'state': 'draft'}, context=context)
 
     def button_cancel(self, cr, uid, ids, context=None):
@@ -94,11 +87,9 @@ class event_event(osv.osv):
             if event_reg.state == 'done':
                 raise osv.except_osv(_('Error!'),_("You have already set a registration for this event as 'Attended'. Please reset it to draft if you want to cancel this event.") )
         registration.write(cr, uid, reg_ids, {'state': 'cancel'}, context=context)
-        self.button_cancel_send_note(cr, uid, ids, context=context)
         return self.write(cr, uid, ids, {'state': 'cancel'}, context=context)
 
     def button_done(self, cr, uid, ids, context=None):
-        self.button_done_send_note(cr, uid, ids, context=context)
         return self.write(cr, uid, ids, {'state': 'done'}, context=context)
 
     def check_registration_limits(self, cr, uid, ids, context=None):
@@ -131,7 +122,6 @@ class event_event(osv.osv):
         if isinstance(ids, (int, long)):
             ids = [ids]
         self.check_registration_limits(cr, uid, ids, context=context)
-        self.button_confirm_send_note(cr, uid, ids, context=context)
         return self.confirm_event(cr, uid, ids, context=context)
 
     def _get_register(self, cr, uid, ids, fields, args, context=None):
@@ -182,6 +172,12 @@ class event_event(osv.osv):
                         continue
         return res
 
+    def _get_visibility_selection(self, cr, uid, context=None):
+        return [('public', 'All Users'),
+                ('employees', 'Employees Only')]
+    # Lambda indirection method to avoid passing a copy of the overridable method when declaring the field
+    _visibility_selection = lambda self, *args, **kwargs: self._get_visibility_selection(*args, **kwargs)
+
     _columns = {
         'name': fields.char('Name', size=64, required=True, translate=True, readonly=False, states={'done': [('readonly', True)]}),
         'user_id': fields.many2one('res.users', 'Responsible User', readonly=False, states={'done': [('readonly', True)]}),
@@ -201,6 +197,7 @@ class event_event(osv.osv):
             ('confirm', 'Confirmed'),
             ('done', 'Done')],
             'Status', readonly=True, required=True,
+            track_visibility='onchange',
             help='If event is created, the status is \'Draft\'.If event is confirmed for the particular dates the status is set to \'Confirmed\'. If the event is over, the status is set to \'Done\'.If event is cancelled the status is set to \'Cancelled\'.'),
         'email_registration_id' : fields.many2one('email.template','Registration Confirmation Email', help='This field contains the template of the mail that will be automatically sent each time a registration for this event is confirmed.'),
         'email_confirmation_id' : fields.many2one('email.template','Event Confirmation Email', help="If you set an email template, each participant will receive this email announcing the confirmation of the event."),
@@ -218,11 +215,14 @@ class event_event(osv.osv):
         'note': fields.text('Description', readonly=False, states={'done': [('readonly', True)]}),
         'company_id': fields.many2one('res.company', 'Company', required=False, change_default=True, readonly=False, states={'done': [('readonly', True)]}),
         'is_subscribed' : fields.function(_subscribe_fnc, type="boolean", string='Subscribed'),
+        'visibility': fields.selection(_visibility_selection, 'Privacy / Visibility',
+            select=True, required=True),
     }
     _defaults = {
         'state': 'draft',
         'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'event.event', context=c),
         'user_id': lambda obj, cr, uid, context: uid,
+        'visibility': 'employees',
     }
 
     def subscribe_to_event(self, cr, uid, ids, context=None):
@@ -256,6 +256,7 @@ class event_event(osv.osv):
     ]
 
     def onchange_event_type(self, cr, uid, ids, type_event, context=None):
+        values = {}
         if type_event:
             type_info =  self.pool.get('event.type').browse(cr,uid,type_event,context)
             dic ={
@@ -265,7 +266,8 @@ class event_event(osv.osv):
               'register_min': type_info.default_registration_min,
               'register_max': type_info.default_registration_max,
             }
-            return {'value': dic}
+            values.update(dic)
+        return values
 
     def on_change_address_id(self, cr, uid, ids, address_id, context=None):
         values = {}
@@ -292,45 +294,15 @@ class event_event(osv.osv):
             res['value'] = {'date_end': date_end.strftime("%Y-%m-%d %H:%M:%S")}
         return res
 
-    # ----------------------------------------
-    # OpenChatter methods and notifications
-    # ----------------------------------------
-
-    def create_send_note(self, cr, uid, ids, context=None):
-        message = _("Event has been <b>created</b>.")
-        self.message_post(cr, uid, ids, body=message, context=context)
-        return True
-
-    def button_cancel_send_note(self, cr, uid, ids, context=None):
-        message = _("Event has been <b>cancelled</b>.")
-        self.message_post(cr, uid, ids, body=message, context=context)
-        return True
-
-    def button_draft_send_note(self, cr, uid, ids, context=None):
-        message = _("Event has been set to <b>draft</b>.")
-        self.message_post(cr, uid, ids, body=message, context=context)
-        return True
-
-    def button_done_send_note(self, cr, uid, ids, context=None):
-        message = _("Event has been <b>done</b>.")
-        self.message_post(cr, uid, ids, body=message, context=context)
-        return True
-
-    def button_confirm_send_note(self, cr, uid, ids, context=None):
-        message = _("Event has been <b>confirmed</b>.")
-        self.message_post(cr, uid, ids, body=message, context=context)
-        return True
-
-event_event()
 
 class event_registration(osv.osv):
     """Event Registration"""
     _name= 'event.registration'
     _description = __doc__
-    _inherit = ['ir.needaction_mixin','mail.thread']
+    _inherit = ['mail.thread', 'ir.needaction_mixin']
     _columns = {
         'id': fields.integer('ID'),
-        'origin': fields.char('Source', size=124,readonly=True,help="Name of the sale order which create the registration"),
+        'origin': fields.char('Source Document', size=124,readonly=True,help="Reference of the sales order which created the registration"),
         'nb_register': fields.integer('Number of Participants', required=True, readonly=True, states={'draft': [('readonly', False)]}),
         'event_id': fields.many2one('event.event', 'Event', required=True, readonly=True, states={'draft': [('readonly', False)]}),
         'partner_id': fields.many2one('res.partner', 'Partner', states={'done': [('readonly', True)]}),
@@ -338,7 +310,7 @@ class event_registration(osv.osv):
         'date_closed': fields.datetime('Attended Date', readonly=True),
         'date_open': fields.datetime('Registration Date', readonly=True),
         'reply_to': fields.related('event_id','reply_to',string='Reply-to Email', type='char', size=128, readonly=True,),
-        'log_ids': fields.one2many('mail.message', 'res_id', 'Logs', domain=[('email_from', '=', False),('model','=',_name)]),
+        'log_ids': fields.one2many('mail.message', 'res_id', 'Logs', domain=[('model','=',_name)]),
         'event_end_date': fields.related('event_id','date_end', type='datetime', string="Event End Date", readonly=True),
         'event_begin_date': fields.related('event_id', 'date_begin', type='datetime', string="Event Start Date", readonly=True),
         'user_id': fields.many2one('res.users', 'User', states={'done': [('readonly', True)]}),
@@ -347,6 +319,7 @@ class event_registration(osv.osv):
                                     ('cancel', 'Cancelled'),
                                     ('open', 'Confirmed'),
                                     ('done', 'Attended')], 'Status',
+                                    track_visibility='onchange',
                                     size=16, readonly=True),
         'email': fields.char('Email', size=64),
         'phone': fields.char('Phone', size=64),
@@ -359,19 +332,12 @@ class event_registration(osv.osv):
     _order = 'name, create_date desc'
 
     def do_draft(self, cr, uid, ids, context=None):
-        self.do_draft_send_note(cr, uid, ids, context=context)
         return self.write(cr, uid, ids, {'state': 'draft'}, context=context)
 
     def confirm_registration(self, cr, uid, ids, context=None):
         for reg in self.browse(cr, uid, ids, context=context or {}):
             self.pool.get('event.event').message_post(cr, uid, [reg.event_id.id], body=_('New registration confirmed: %s.') % (reg.name or '', ),subtype="event.mt_event_registration", context=context)
-        self.message_post(cr, uid, ids, body=_('Registration confirmed.'), context=context)
-        return self.write(cr, uid, ids, {'state': 'open'},context=context)
-
-    def create(self, cr, uid, vals, context=None):
-        obj_id = super(event_registration, self).create(cr, uid, vals, context)
-        self.create_send_note(cr, uid, [obj_id], context=context)
-        return obj_id
+        return self.write(cr, uid, ids, {'state': 'open'}, context=context)
 
     def registration_open(self, cr, uid, ids, context=None):
         """ Open Registration
@@ -395,13 +361,11 @@ class event_registration(osv.osv):
             if today >= registration.event_id.date_begin:
                 values = {'state': 'done', 'date_closed': today}
                 self.write(cr, uid, ids, values)
-                self.message_post(cr, uid, ids, body=_('State set to Done'), context=context)
             else:
                 raise osv.except_osv(_('Error!'), _("You must wait for the starting day of the event to do this action."))
         return True
 
     def button_reg_cancel(self, cr, uid, ids, context=None, *args):
-        self.message_post(cr, uid, ids, body=_('State set to Cancel'), context=context)
         return self.write(cr, uid, ids, {'state': 'cancel'})
 
     def mail_user(self, cr, uid, ids, context=None):
@@ -449,20 +413,4 @@ class event_registration(osv.osv):
             data.update(d['value'])
         return {'value': data}
 
-    # ----------------------------------------
-    # OpenChatter methods and notifications
-    # ----------------------------------------
-
-    def create_send_note(self, cr, uid, ids, context=None):
-        message = _("Registration has been <b>created</b>.")
-        self.message_post(cr, uid, ids, body=message, context=context)
-        return True
-
-    def do_draft_send_note(self, cr, uid, ids, context=None):
-        message = _("Registration has been set as <b>draft</b>.")
-        self.message_post(cr, uid, ids, body=message, context=context)
-        return True
-
-event_registration()
-
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: