[IMP] event: labels improvements
[odoo/odoo.git] / addons / event / event.py
index f3402b0..cf2b3f7 100644 (file)
@@ -100,6 +100,9 @@ class event_event(osv.osv):
         @param context: A standard dictionary for contextual values
         @return: True
         """
+        if not context:
+            context = {}
+        res = False
         if type(ids) in (int, long,):
             ids = [ids]
         data_pool = self.pool.get('ir.model.data')
@@ -107,7 +110,7 @@ class event_event(osv.osv):
         for event in self.browse(cr, uid, ids, context=context):
             total_confirmed = event.register_current
             if total_confirmed >= event.register_min or event.register_max == 0:
-                self.do_confirm(cr, uid, [event.id], context=context)
+                res = self.do_confirm(cr, uid, [event.id], context=context)
             else:
                 unconfirmed_ids.append(event.id)
         if unconfirmed_ids:
@@ -126,8 +129,8 @@ class event_event(osv.osv):
                 'target': 'new',
                 'context': context,
                 'nodestroy': True
-            }
-        return True
+            }        
+        return res
 
 
     def _get_register(self, cr, uid, ids, fields, args, context=None):
@@ -192,7 +195,7 @@ class event_event(osv.osv):
         return res
 
     _columns = {
-        'name': fields.char('Name', size=64, required=True, translate=True, readonly=False, states={'done': [('readonly', True)]}),
+        'name': fields.char('Summary', 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)]}),
         'parent_id': fields.many2one('event.event', 'Parent Event', readonly=False, states={'done': [('readonly', True)]}),
         'section_id': fields.many2one('crm.case.section', 'Sale Team', readonly=False, states={'done': [('readonly', True)]}),
@@ -219,10 +222,10 @@ class event_event(osv.osv):
         'mail_auto_confirm': fields.boolean('Mail Auto Confirm', readonly=False, states={'done': [('readonly', True)]}, help='Check this box if you want ot use the automatic confirmation emailing or the reminder'),
         'mail_registr': fields.text('Registration Email', readonly=False, states={'done': [('readonly', True)]}, help='This email will be sent when someone subscribes to the event.'),
         'mail_confirm': fields.text('Confirmation Email', readonly=False, states={'done': [('readonly', True)]}, help="This email will be sent when the event gets confimed or when someone subscribes to a confirmed event. This is also the email sent to remind someone about the event."),
-        'product_id': fields.many2one('product.product', 'Product', required=True, readonly=True, states={'draft': [('readonly', False)]}, help="Product which is provided cost of event. Invoice of event will be created with this Product."),
+        'product_id': fields.many2one('product.product', 'Product', required=True, readonly=True, states={'draft': [('readonly', False)]}, help="The invoices of this event registration will be created with this Product. Thus it allows you to set the default label and the accounting info you want by default on these invoices."),
         'note': fields.text('Notes', help="Description or Summary of Event", readonly=False, states={'done': [('readonly', True)]}),
         'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', readonly=True, states={'draft': [('readonly', False)]}, help="Pricelist version for current event."),
-        'unit_price': fields.related('product_id', 'list_price', type='float', string='Registration Cost', readonly=True, states={'draft':[('readonly',False)]}),
+        'unit_price': fields.related('product_id', 'list_price', type='float', string='Registration Cost', readonly=True, states={'draft':[('readonly',False)]}, help="This will be the default price used as registration cost when invoicing this event. Note that you can specify for each registration a specific amount if you want to"),
         'main_speaker_id': fields.many2one('res.partner','Main Speaker', readonly=False, states={'done': [('readonly', True)]}),
         'speaker_ids':fields.many2many('res.partner', 'event_speaker_rel', 'speaker_id', 'partner_id', 'Other Speakers', readonly=False, states={'done': [('readonly', True)]}),
         'address_id': fields.many2one('res.partner.address','Location Address', readonly=False, states={'done': [('readonly', True)]}),
@@ -311,15 +314,16 @@ class event_registration(osv.osv):
         'date_closed': fields.datetime('Closed', readonly=True),
         'ref': fields.reference('Reference', selection=crm._links_get, size=128),
         'ref2': fields.reference('Reference 2', selection=crm._links_get, size=128),
-        'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('history', '=', True),('model','=',_name)]),
+        'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
         'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False),('model','=',_name)]),
+        'date_deadline': fields.related('event_id','date_end', type='datetime', string="End Date", readonly=True, store=True),
+        'date': fields.related('event_id', 'date_begin', type='datetime', string="Start Date", readonly=True, store=True),
         'section_id': fields.related('event_id', 'section_id', type='many2one', relation='crm.case.section', string='Sale Team', store=True, readonly=True, states={'draft':[('readonly',False)]}),
         'company_id': fields.related('event_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True, states={'draft':[('readonly',False)]}),
     }
     _defaults = {
         'nb_register': 1,
         'tobe_invoiced':  True,
-        'date': time.strftime('%Y-%m-%d %H:%M:%S')
     }
 
     def _make_invoice(self, cr, uid, reg, lines, context=None):
@@ -441,6 +445,8 @@ class event_registration(osv.osv):
         @param context: A standard dictionary for contextual values
         @return: True
         """
+        if not context:
+            context = {}
         data_pool = self.pool.get('ir.model.data')
         unconfirmed_ids = []
         for registration in self.browse(cr, uid, ids, context=context):
@@ -505,29 +511,7 @@ class event_registration(osv.osv):
         registrations = self.browse(cr, uid, ids)
         self._history(cr, uid, registrations, _('Cancel'))
         self.write(cr, uid, ids, {'state': 'cancel'})
-        return True
-
-    def create(self, cr, uid, values, context=None):
-        """ Overrides orm create method.
-        """
-        event_obj = self.pool.get('event.event')
-        event = event_obj.browse(cr, uid, values['event_id'], context=context)
-        values['date_deadline']= event.date_begin
-        values['description']= event.mail_confirm
-        res = super(event_registration, self).create(cr, uid, values, context=context)
-        registrations = self.browse(cr, uid, [res], context=context)
-        self._history(cr, uid, registrations, _('Created'))
-        return res
-
-    def write(self, cr, uid, ids, values, context=None):
-        """ Overrides orm write method.
-        """
-        event_obj = self.pool.get('event.event')
-        if 'event_id' in values:
-            event = event_obj.browse(cr, uid, values['event_id'], context=context)
-            values['date_deadline']= event.date_begin
-            values['description']= event.mail_confirm
-        return super(event_registration, self).write(cr, uid, ids, values, context=context)
+        return True    
 
     def mail_user(self, cr, uid, ids, confirm=False, context=None):
         """
@@ -618,10 +602,11 @@ class event_registration(osv.osv):
 
         event_obj = self.pool.get('event.event')
         prod_obj = self.pool.get('product.product')
-        res_obj = self.pool.get('res.partner')
+        res_obj = self.pool.get('res.partner') 
 
         data_event =  event_obj.browse(cr, uid, event_id)
-        res = {'value': {'unit_price': False, 'event_product': False, 'user_id': False}}
+        res = {'value': {'unit_price': False, 'event_product': False, 'user_id': False, 
+                        'date': data_event.date_begin, 'date_deadline': data_event.date_end, 'description': data_event.note, 'name': data_event.name}}
         if data_event.user_id.id:
             res['value'].update({'user_id':data_event.user_id.id})
         if data_event.product_id: