2009-10-13 05:58:37 +00:00
# -*- coding: utf-8 -*-
2008-08-24 14:45:43 +00:00
##############################################################################
2009-11-26 12:30:42 +00:00
#
2008-11-18 10:56:11 +00:00
# OpenERP, Open Source Management Solution
2010-01-12 09:18:39 +00:00
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
2008-08-24 14:45:43 +00:00
#
2008-11-03 19:18:56 +00:00
# This program is free software: you can redistribute it and/or modify
2009-10-14 11:15:34 +00:00
# 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.
2008-08-24 14:45:43 +00:00
#
2008-11-03 19:18:56 +00:00
# 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
2009-10-14 11:15:34 +00:00
# GNU Affero General Public License for more details.
2008-08-24 14:45:43 +00:00
#
2009-10-14 11:15:34 +00:00
# You should have received a copy of the GNU Affero General Public License
2009-11-26 12:30:42 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2008-08-24 14:45:43 +00:00
#
##############################################################################
2010-10-12 12:31:26 +00:00
import time
2008-08-24 14:45:43 +00:00
from osv import fields , osv
2010-06-07 06:43:12 +00:00
from tools . translate import _
2010-07-15 13:41:44 +00:00
import decimal_precision as dp
2011-09-07 17:25:00 +00:00
2010-07-16 06:47:14 +00:00
class event_type ( osv . osv ) :
""" Event Type """
2008-08-24 14:45:43 +00:00
_name = ' event.type '
2010-06-07 06:43:12 +00:00
_description = __doc__
2008-08-24 14:45:43 +00:00
_columns = {
2010-07-16 06:47:14 +00:00
' name ' : fields . char ( ' Event type ' , size = 64 , required = True ) ,
2012-02-17 11:29:14 +00:00
' default_reply_to ' : fields . char ( ' Default Reply-To ' , size = 64 , help = " The email address of the organizer which is put in the ' Reply-To ' of all emails sent automatically at event or registrations confirmation. You can also put your email address of your mail gateway if you use one. " ) ,
2012-02-16 14:52:49 +00:00
' default_email_event ' : fields . many2one ( ' email.template ' , ' Event Confirmation Email ' , help = " It will select this default confirmation event mail value when you choose this event " ) ,
2012-02-23 10:18:10 +00:00
' default_email_registration ' : fields . many2one ( ' email.template ' , ' Registration Confirmation Email ' , help = " It will select this default confirmation registration mail value when you choose this event " ) ,
' default_registration_min ' : fields . integer ( ' Default Minimum Registration ' , help = " It will select this default minimum value when you choose this event " ) ,
' default_registration_max ' : fields . integer ( ' Default Maximum Registration ' , help = " It will select this default maximum value when you choose this event " ) ,
2008-08-24 14:45:43 +00:00
}
2012-02-13 13:21:27 +00:00
_defaults = {
2012-02-23 10:18:10 +00:00
' default_registration_min ' : 0 ,
2012-02-16 14:52:49 +00:00
' default_registration_max ' : 0 ,
2012-02-13 13:21:27 +00:00
}
2010-10-12 12:31:26 +00:00
2008-08-24 14:45:43 +00:00
event_type ( )
2010-07-16 06:47:14 +00:00
class event_event ( osv . osv ) :
""" Event """
2008-08-24 14:45:43 +00:00
_name = ' event.event '
2010-06-07 06:43:12 +00:00
_description = __doc__
2008-08-24 14:45:43 +00:00
_order = ' date_begin '
2010-07-16 06:47:14 +00:00
2012-02-13 08:17:54 +00:00
def name_get ( self , cr , uid , ids , context = None ) :
if not ids :
return [ ]
res = [ ]
2012-02-23 10:18:10 +00:00
for record in self . browse ( cr , uid , ids , context = context ) :
date = record . date_begin . split ( " " )
date = date [ 0 ]
2012-02-16 14:52:49 +00:00
registers = ' '
if record . register_max != 0 :
register_max = str ( record . register_max )
register_tot = record . register_current + record . register_prospect
register_tot = str ( register_tot )
registers = register_tot + ' / ' + register_max
name = record . name + ' ( ' + date + ' ) ' + registers
2012-02-13 08:17:54 +00:00
res . append ( ( record [ ' id ' ] , name ) )
return res
def _name_get_fnc ( self , cr , uid , ids , prop , unknow , context = None ) :
res = self . name_get ( cr , uid , ids , context = context )
return dict ( res )
2010-07-16 06:47:14 +00:00
def copy ( self , cr , uid , id , default = None , context = None ) :
2012-02-07 09:41:25 +00:00
""" Reset the state and the registrations while copying an event
2010-06-07 06:43:12 +00:00
"""
2010-06-26 10:13:40 +00:00
if not default :
default = { }
default . update ( {
2010-07-16 06:47:14 +00:00
' state ' : ' draft ' ,
' registration_ids ' : False ,
} )
2010-06-26 10:13:40 +00:00
return super ( event_event , self ) . copy ( cr , uid , id , default = default , context = context )
2010-10-26 12:40:14 +00:00
2010-06-26 10:13:40 +00:00
def button_draft ( self , cr , uid , ids , context = None ) :
return self . write ( cr , uid , ids , { ' state ' : ' draft ' } , context = context )
def button_cancel ( self , cr , uid , ids , context = None ) :
2012-02-24 15:50:59 +00:00
registration = self . pool . get ( ' event.registration ' )
reg_ids = registration . search ( cr , uid , [ ( ' event_id ' , ' in ' , ids ) ] , context = context )
for event_reg in registration . browse ( cr , uid , reg_ids , context = context ) :
if event_reg . state == ' done ' :
2012-02-27 11:58:09 +00:00
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. " ) )
2012-02-24 15:50:59 +00:00
registration . write ( cr , uid , reg_ids , { ' state ' : ' cancel ' } , context = context )
2010-06-26 10:13:40 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' cancel ' } , context = context )
def button_done ( self , cr , uid , ids , context = None ) :
return self . write ( cr , uid , ids , { ' state ' : ' done ' } , context = context )
2012-02-28 14:48:22 +00:00
def check_registration_limits ( self , cr , uid , ids , context = None ) :
2012-02-28 12:01:34 +00:00
register_pool = self . pool . get ( ' event.registration ' )
for self . event in self . browse ( cr , uid , ids , context = context ) :
total_confirmed = self . event . register_current
if total_confirmed < self . event . register_min or total_confirmed > self . event . register_max and self . event . register_max != 0 :
raise osv . except_osv ( _ ( ' Error! ' ) , _ ( " The total of confirmed registration for the event ' %s ' does not meet the expected minimum/maximum. You should maybe reconsider those limits before going further " ) % ( self . event . name ) )
2012-02-28 14:48:22 +00:00
def confirm_event ( self , cr , uid , ids , context = None ) :
2012-02-28 14:21:35 +00:00
register_pool = self . pool . get ( ' event.registration ' )
2012-02-28 12:01:34 +00:00
if self . event . email_confirmation_id :
#send reminder that will confirm the event for all the people that were already confirmed
reg_ids = register_pool . search ( cr , uid , [
( ' event_id ' , ' = ' , self . event . id ) ,
( ' state ' , ' not in ' , [ ' draft ' , ' cancel ' ] ) ] , context = context )
register_pool . mail_user_confirm ( cr , uid , reg_ids )
return self . write ( cr , uid , ids , { ' state ' : ' confirm ' } , context = context )
2012-02-07 09:41:25 +00:00
def button_confirm ( self , cr , uid , ids , context = None ) :
2010-07-15 13:41:44 +00:00
""" Confirm Event and send confirmation email to all register peoples
2010-07-16 06:47:14 +00:00
"""
2012-02-07 09:41:25 +00:00
if isinstance ( ids , ( int , long ) ) :
ids = [ ids ]
2012-02-28 14:48:22 +00:00
self . check_registration_limits ( cr , uid , ids , context = context )
return self . confirm_event ( cr , uid , ids , context = context )
2010-07-16 06:47:14 +00:00
def _get_register ( self , cr , uid , ids , fields , args , context = None ) :
2010-07-12 13:30:56 +00:00
""" Get Confirm or uncofirm register value.
2010-06-07 06:43:12 +00:00
@param ids : List of Event registration type ' s id
2010-06-26 10:13:40 +00:00
@param fields : List of function fields ( register_current and register_prospect ) .
2010-06-07 06:43:12 +00:00
@param context : A standard dictionary for contextual values
2010-07-16 06:47:14 +00:00
@return : Dictionary of function fields value .
2010-06-07 06:43:12 +00:00
"""
2010-06-26 10:13:40 +00:00
register_pool = self . pool . get ( ' event.registration ' )
2010-06-07 06:43:12 +00:00
res = { }
2010-10-11 06:07:52 +00:00
for event in self . browse ( cr , uid , ids , context = context ) :
2010-05-17 13:31:14 +00:00
res [ event . id ] = { }
2012-02-27 11:57:32 +00:00
reg_open = reg_done = reg_draft = 0
2012-02-27 09:47:46 +00:00
for registration in event . registration_ids :
2012-02-27 11:57:32 +00:00
if registration . state == ' open ' :
reg_open + = registration . nb_register
elif registration . state == ' done ' :
reg_done + = registration . nb_register
elif registration . state == ' draft ' :
reg_draft + = registration . nb_register
for field in fields :
number = 0
if field == ' register_current ' :
number = reg_open
elif field == ' register_attended ' :
number = reg_done
elif field == ' register_prospect ' :
number = reg_draft
2012-03-06 06:49:02 +00:00
elif field == ' register_avail ' :
number = event . register_max - reg_open
2012-02-27 11:57:32 +00:00
res [ event . id ] [ field ] = number
2008-08-24 14:45:43 +00:00
return res
2012-03-06 06:49:02 +00:00
def _subscribe_fnc ( self , cr , uid , ids , fields , args , context = None ) :
""" Get Confirm or uncofirm register value.
@param ids : List of Event registration type ' s id
@param fields : List of function fields ( register_current and register_prospect ) .
@param context : A standard dictionary for contextual values
@return : Dictionary of function fields value .
"""
register_pool = self . pool . get ( ' event.registration ' )
res = { }
for event in self . browse ( cr , uid , ids , context = context ) :
curr_reg_id = register_pool . search ( cr , uid , [ ( ' user_id ' , ' = ' , uid ) , ( ' event_id ' , ' = ' , event . id ) ] )
if not curr_reg_id : res [ event . id ] = False
if curr_reg_id :
for reg in register_pool . browse ( cr , uid , curr_reg_id , context = context ) :
if not reg . subscribe :
res [ event . id ] = False
else :
res [ event . id ] = True
return res
2008-08-24 14:45:43 +00:00
_columns = {
2012-02-24 16:29:04 +00:00
' name ' : fields . char ( ' Name ' , size = 64 , required = True , translate = True , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
2010-07-15 13:41:44 +00:00
' user_id ' : fields . many2one ( ' res.users ' , ' Responsible User ' , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
2012-02-16 14:52:49 +00:00
' type ' : fields . many2one ( ' event.type ' , ' Type of Event ' , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
' register_max ' : fields . integer ( ' Maximum Registrations ' , help = " You can for each event define a maximum registration level. If you have too much registrations you are not able to confirm your event. (put 0 to ignore this rule ) " , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
' register_min ' : fields . integer ( ' Minimum Registrations ' , help = " You can for each event define a minimum registration level. If you do not enough registrations you are not able to confirm your event. (put 0 to ignore this rule ) " , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
2012-02-27 11:57:32 +00:00
' register_current ' : fields . function ( _get_register , string = ' Confirmed Registrations ' , multi = ' register_numbers ' ) ,
2012-03-06 06:49:02 +00:00
' register_avail ' : fields . function ( _get_register , string = ' Available Registrations ' , multi = ' register_numbers ' , type = ' integer ' ) ,
2012-02-27 11:57:32 +00:00
' register_prospect ' : fields . function ( _get_register , string = ' Unconfirmed Registrations ' , multi = ' register_numbers ' ) ,
' register_attended ' : fields . function ( _get_register , string = ' Attended Registrations ' , multi = ' register_numbers ' ) ,
2010-07-15 13:41:44 +00:00
' registration_ids ' : fields . one2many ( ' event.registration ' , ' event_id ' , ' Registrations ' , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
2012-02-28 18:00:11 +00:00
' date_begin ' : fields . datetime ( ' Start Date ' , required = True , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
' date_end ' : fields . datetime ( ' End Date ' , required = True , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
2010-07-15 13:41:44 +00:00
' state ' : fields . selection ( [
2010-07-16 06:47:14 +00:00
( ' draft ' , ' Draft ' ) ,
( ' confirm ' , ' Confirmed ' ) ,
( ' done ' , ' Done ' ) ,
( ' cancel ' , ' Cancelled ' ) ] ,
' State ' , readonly = True , required = True ,
help = ' If event is created, the state is \' Draft \' .If event is confirmed for the particular dates the state is set to \' Confirmed \' . If the event is over, the state is set to \' Done \' .If event is cancelled the state is set to \' Cancelled \' . ' ) ,
2012-02-28 18:00:11 +00:00
' 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. ' ) ,
2012-02-13 10:49:10 +00:00
' 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. " ) ,
2012-02-13 08:17:54 +00:00
' full_name ' : fields . function ( _name_get_fnc , type = " char " , string = ' Name ' ) ,
2012-02-23 10:18:10 +00:00
' reply_to ' : fields . char ( ' Reply-To Email ' , size = 64 , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } , help = " The email address of the organizer is likely to be put here, with the effect to be in the ' Reply-To ' of the mails sent automatically at event or registrations confirmation. You can also put the email address of your mail gateway if you use one. " ) ,
2011-04-15 06:29:18 +00:00
' main_speaker_id ' : fields . many2one ( ' res.partner ' , ' Main Speaker ' , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } , help = " Speaker who will be giving speech at the event. " ) ,
2010-10-11 06:07:52 +00:00
' speaker_ids ' : fields . many2many ( ' res.partner ' , ' event_speaker_rel ' , ' speaker_id ' , ' partner_id ' , ' Other Speakers ' , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
2010-07-15 13:41:44 +00:00
' address_id ' : fields . many2one ( ' res.partner.address ' , ' Location Address ' , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
2012-03-01 11:39:44 +00:00
' speaker_confirmed ' : fields . boolean ( ' Speaker Confirmed ' , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
2010-07-02 08:32:50 +00:00
' country_id ' : fields . related ( ' address_id ' , ' country_id ' ,
2010-07-15 13:41:44 +00:00
type = ' many2one ' , relation = ' res.country ' , string = ' Country ' , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
' note ' : fields . text ( ' Description ' , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
2010-10-07 12:49:31 +00:00
' company_id ' : fields . many2one ( ' res.company ' , ' Company ' , required = False , change_default = True , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
2012-03-06 06:49:02 +00:00
' subscribe ' : fields . function ( _subscribe_fnc , type = " boolean " , string = ' Subscribe ' ) ,
2008-08-24 14:45:43 +00:00
}
2008-12-08 17:08:40 +00:00
2008-08-24 14:45:43 +00:00
_defaults = {
2010-07-16 06:47:14 +00:00
' state ' : ' draft ' ,
2012-02-24 11:19:05 +00:00
' company_id ' : lambda self , cr , uid , c : self . pool . get ( ' res.company ' ) . _company_default_get ( cr , uid , ' event.event ' , context = c ) ,
2010-07-16 06:47:14 +00:00
' user_id ' : lambda obj , cr , uid , context : uid ,
2008-08-24 14:45:43 +00:00
}
2012-03-06 06:49:02 +00:00
def subscribe_to_event ( self , cr , uid , ids , context = None ) :
register_pool = self . pool . get ( ' event.registration ' )
2012-03-21 05:21:26 +00:00
user_pool = self . pool . get ( ' res.users ' )
2012-03-06 06:49:02 +00:00
curr_reg_id = register_pool . search ( cr , uid , [ ( ' user_id ' , ' = ' , uid ) , ( ' event_id ' , ' = ' , ids [ 0 ] ) ] )
2012-03-21 05:21:26 +00:00
user = user_pool . browse ( cr , uid , uid , context )
2012-03-06 06:49:02 +00:00
if not curr_reg_id :
2012-03-21 05:43:56 +00:00
curr_reg_id = register_pool . create ( cr , uid , { ' event_id ' : ids [ 0 ] ,
' email ' : user . user_email ,
' name ' : user . name ,
' subscribe ' : True ,
} )
2012-03-06 06:49:02 +00:00
else :
register_pool . write ( cr , uid , curr_reg_id , { ' state ' : ' open ' , ' subscribe ' : True ,
' event_id ' : ids [ 0 ] ,
} )
2012-03-21 05:43:56 +00:00
if isinstance ( curr_reg_id , ( int , long ) ) :
curr_reg_id = [ curr_reg_id ]
register_pool . confirm_registration ( cr , uid , curr_reg_id , context )
2012-03-06 06:49:02 +00:00
self . write ( cr , uid , ids , { ' subscribe ' : True } )
return True
def unsubscribe_to_event ( self , cr , uid , ids , context = None ) :
register_pool = self . pool . get ( ' event.registration ' )
curr_reg_id = register_pool . search ( cr , uid , [ ( ' user_id ' , ' = ' , uid ) , ( ' event_id ' , ' = ' , ids [ 0 ] ) ] )
if curr_reg_id :
2012-03-21 05:43:56 +00:00
if isinstance ( curr_reg_id , ( int , long ) ) :
curr_reg_id = [ curr_reg_id ]
register_pool . write ( cr , uid , curr_reg_id , { ' event_id ' : ids [ 0 ] ,
2012-03-06 06:49:02 +00:00
' subscribe ' : False
} )
2012-03-21 05:43:56 +00:00
register_pool . button_reg_cancel ( cr , uid , curr_reg_id , context )
self . write ( cr , uid , ids , { ' subscribe ' : False } )
2012-03-06 06:49:02 +00:00
return True
2010-05-17 13:31:14 +00:00
2010-11-19 13:48:01 +00:00
def _check_closing_date ( self , cr , uid , ids , context = None ) :
for event in self . browse ( cr , uid , ids , context = context ) :
2010-10-13 09:33:37 +00:00
if event . date_end < event . date_begin :
return False
return True
2010-07-15 13:41:44 +00:00
_constraints = [
2010-10-13 09:33:37 +00:00
( _check_closing_date , ' Error ! Closing Date cannot be set before Beginning Date. ' , [ ' date_end ' ] ) ,
2010-07-15 13:41:44 +00:00
]
2010-06-30 14:21:59 +00:00
2012-02-28 11:58:03 +00:00
def onchange_event_type ( self , cr , uid , ids , type_event , context = None ) :
2012-02-13 13:21:27 +00:00
if type_event :
type_info = self . pool . get ( ' event.type ' ) . browse ( cr , uid , type_event , context )
dic = {
2012-02-28 11:58:03 +00:00
' reply_to ' : type_info . default_reply_to ,
' email_registration_id ' : type_info . default_email_registration . id ,
' email_confirmation_id ' : type_info . default_email_event . id ,
' register_min ' : type_info . default_registration_min ,
' register_max ' : type_info . default_registration_max ,
2012-02-13 13:21:27 +00:00
}
2012-02-28 11:58:03 +00:00
return { ' value ' : dic }
2010-06-26 10:13:40 +00:00
event_event ( )
2010-07-16 06:47:14 +00:00
class event_registration ( osv . osv ) :
2010-07-15 13:41:44 +00:00
""" Event Registration """
2010-06-26 10:13:40 +00:00
_name = ' event.registration '
_description = __doc__
2012-01-16 13:58:02 +00:00
_inherit = [ ' mail.thread ' , ' res.partner.address ' ]
2010-06-26 10:13:40 +00:00
_columns = {
2011-11-14 22:08:36 +00:00
' id ' : fields . integer ( ' ID ' ) ,
2012-02-17 11:29:14 +00:00
' origin ' : fields . char ( ' Origin ' , size = 124 , readonly = True , help = " Name of the sale order which create the registration " ) ,
' nb_register ' : fields . integer ( ' Number of Participants ' , required = True , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
2010-10-05 13:06:14 +00:00
' event_id ' : fields . many2one ( ' event.event ' , ' Event ' , required = True , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
2010-07-20 06:22:14 +00:00
' partner_id ' : fields . many2one ( ' res.partner ' , ' Partner ' , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
2012-02-23 10:18:10 +00:00
' partner_address_id ' : fields . many2one ( ' res.partner.address ' , ' Partner ' , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
" contact_id " : fields . many2one ( ' res.partner.address ' , ' Partner Contact ' , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
2012-02-17 11:29:14 +00:00
' create_date ' : fields . datetime ( ' Creation Date ' , readonly = True ) ,
2012-02-23 10:18:10 +00:00
' date_closed ' : fields . datetime ( ' Attended Date ' , readonly = True ) ,
2012-02-16 14:52:49 +00:00
' date_open ' : fields . datetime ( ' Registration Date ' , readonly = True ) ,
2012-02-23 10:18:10 +00:00
' reply_to ' : fields . related ( ' event_id ' , ' reply_to ' , string = ' Reply-to Email ' , type = ' char ' , size = 128 , readonly = True , ) ,
2011-08-22 17:16:59 +00:00
' log_ids ' : fields . one2many ( ' mail.message ' , ' res_id ' , ' Logs ' , domain = [ ( ' email_from ' , ' = ' , False ) , ( ' model ' , ' = ' , _name ) ] ) ,
2012-02-23 10:18:10 +00:00
' 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 ) ,
2010-07-20 06:22:14 +00:00
' user_id ' : fields . many2one ( ' res.users ' , ' Responsible ' , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
2010-07-15 13:41:44 +00:00
' company_id ' : fields . related ( ' event_id ' , ' company_id ' , type = ' many2one ' , relation = ' res.company ' , string = ' Company ' , store = True , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
2012-02-07 09:41:25 +00:00
' state ' : fields . selection ( [ ( ' draft ' , ' Unconfirmed ' ) ,
( ' open ' , ' Confirmed ' ) ,
2010-07-20 06:22:14 +00:00
( ' cancel ' , ' Cancelled ' ) ,
2012-02-23 10:18:10 +00:00
( ' done ' , ' Attended ' ) ] , ' State ' ,
2012-03-06 06:49:02 +00:00
size = 16 , readonly = True ) ,
' subscribe ' : fields . boolean ( ' Subscribe ' ) ,
2010-06-26 10:13:40 +00:00
}
2012-02-17 11:29:14 +00:00
2010-06-26 10:13:40 +00:00
_defaults = {
2010-07-16 06:47:14 +00:00
' nb_register ' : 1 ,
2010-10-13 10:50:12 +00:00
' state ' : ' draft ' ,
2010-07-20 06:22:14 +00:00
' user_id ' : lambda self , cr , uid , ctx : uid ,
2010-06-26 10:13:40 +00:00
}
2012-02-24 16:32:11 +00:00
_order = ' name, create_date desc '
2012-02-17 11:29:14 +00:00
2012-02-24 15:50:59 +00:00
2012-02-09 10:33:57 +00:00
def do_draft ( self , cr , uid , ids , context = None ) :
return self . write ( cr , uid , ids , { ' state ' : ' draft ' } , context = context )
2012-02-28 13:48:41 +00:00
2012-02-28 14:48:22 +00:00
def confirm_registration ( self , cr , uid , ids , context = None ) :
2012-02-29 10:04:33 +00:00
self . message_append ( cr , uid , ids , _ ( ' State set to open ' ) , body_text = _ ( ' Open ' ) )
2012-02-28 14:48:22 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' open ' } , context = context )
2012-02-28 12:01:34 +00:00
2012-02-23 10:18:10 +00:00
2012-02-16 14:52:49 +00:00
def registration_open ( self , cr , uid , ids , context = None ) :
2010-07-15 13:41:44 +00:00
""" Open Registration
"""
2012-02-28 14:48:22 +00:00
res = self . confirm_registration ( cr , uid , ids , context = context )
2012-02-28 18:00:11 +00:00
self . mail_user ( cr , uid , ids , context = context )
2012-02-28 14:48:22 +00:00
return res
2010-07-15 13:41:44 +00:00
2012-02-27 15:17:35 +00:00
def button_reg_close ( self , cr , uid , ids , context = None ) :
2010-07-15 13:41:44 +00:00
""" Close Registration
"""
2010-11-23 07:05:05 +00:00
if context is None :
2010-07-15 13:41:44 +00:00
context = { }
2012-03-01 11:20:26 +00:00
today = fields . datetime . now ( )
for registration in self . browse ( cr , uid , ids , context = context ) :
if today > = registration . event_id . date_begin :
values = { ' state ' : ' done ' , ' date_closed ' : today }
self . write ( cr , uid , ids , values )
self . message_append ( cr , uid , ids , _ ( ' State set to Done ' ) , body_text = _ ( ' Done ' ) )
2012-03-01 10:23:17 +00:00
else :
2012-03-01 11:20:26 +00:00
raise osv . except_osv ( _ ( ' Error! ' ) , _ ( " You must wait the event starting day to do this action. " ) )
return True
2012-02-27 15:17:35 +00:00
def button_reg_cancel ( self , cr , uid , ids , context = None , * args ) :
2012-02-29 10:04:33 +00:00
self . message_append ( cr , uid , ids , _ ( ' State set to Cancel ' ) , body_text = _ ( ' Cancel ' ) )
2011-12-22 17:02:05 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' cancel ' } )
2012-02-07 09:41:25 +00:00
2012-02-28 18:00:11 +00:00
def mail_user ( self , cr , uid , ids , context = None ) :
2010-06-21 06:02:20 +00:00
"""
2012-01-24 12:38:06 +00:00
Send email to user with email_template when registration is done
2012-02-07 09:41:25 +00:00
"""
2011-09-07 17:25:00 +00:00
for registration in self . browse ( cr , uid , ids , context = context ) :
2012-02-28 18:00:11 +00:00
if registration . event_id . state == ' confirm ' and registration . event_id . email_confirmation_id . id :
self . mail_user_confirm ( cr , uid , ids , context = context )
else :
template_id = registration . event_id . email_registration_id . id
if template_id :
mail_message = self . pool . get ( ' email.template ' ) . send_mail ( cr , uid , template_id , registration . id )
2010-06-26 10:13:40 +00:00
return True
2008-10-07 09:26:12 +00:00
2010-06-26 10:13:40 +00:00
def mail_user_confirm ( self , cr , uid , ids , context = None ) :
2010-06-07 06:43:12 +00:00
"""
2012-02-28 18:00:11 +00:00
Send email to user when the event is confirmed
2010-06-07 06:43:12 +00:00
"""
2012-01-24 12:38:06 +00:00
for registration in self . browse ( cr , uid , ids , context = context ) :
template_id = registration . event_id . email_confirmation_id . id
if template_id :
mail_message = self . pool . get ( ' email.template ' ) . send_mail ( cr , uid , template_id , registration . id )
return True
2008-08-24 14:45:43 +00:00
2012-02-07 09:41:25 +00:00
def onchange_contact_id ( self , cr , uid , ids , contact , partner , context = None ) :
2008-08-24 14:45:43 +00:00
data = { }
2008-10-07 09:26:12 +00:00
if not contact :
2008-08-24 14:45:43 +00:00
return data
2010-07-12 13:30:56 +00:00
addr_obj = self . pool . get ( ' res.partner.address ' )
2012-02-23 10:18:10 +00:00
contact_id = addr_obj . browse ( cr , uid , contact , context = context )
2012-02-13 13:21:27 +00:00
data = {
' email ' : contact_id . email ,
' contact_id ' : contact_id . id ,
' name ' : contact_id . name ,
' phone ' : contact_id . phone ,
}
2010-05-17 13:31:14 +00:00
return { ' value ' : data }
2008-08-24 14:45:43 +00:00
2012-02-07 09:41:25 +00:00
def onchange_event ( self , cr , uid , ids , event_id , context = None ) :
2010-07-12 13:30:56 +00:00
""" This function returns value of Product Name, Unit Price based on Event.
"""
2012-02-07 09:41:25 +00:00
if context is None :
context = { }
2008-08-24 14:45:43 +00:00
if not event_id :
2012-02-07 09:41:25 +00:00
return { }
2010-07-12 13:30:56 +00:00
event_obj = self . pool . get ( ' event.event ' )
2012-02-07 09:41:25 +00:00
data_event = event_obj . browse ( cr , uid , event_id , context = context )
return { ' value ' :
2012-02-23 10:18:10 +00:00
{ ' event_begin_date ' : data_event . date_begin ,
' event_end_date ' : data_event . date_end ,
2012-02-07 09:41:25 +00:00
' company_id ' : data_event . company_id and data_event . company_id . id or False ,
}
}
def onchange_partner_id ( self , cr , uid , ids , part , context = None ) :
2010-07-12 13:30:56 +00:00
res_obj = self . pool . get ( ' res.partner ' )
2010-07-15 13:41:44 +00:00
data = { }
2008-08-24 14:45:43 +00:00
if not part :
2010-05-17 13:31:14 +00:00
return { ' value ' : data }
2011-12-18 21:14:59 +00:00
addr = res_obj . address_get ( cr , uid , [ part ] ) . get ( ' default ' , False )
2008-10-07 09:26:12 +00:00
if addr :
2012-02-07 09:41:25 +00:00
d = self . onchange_contact_id ( cr , uid , ids , addr , part , context )
2011-12-18 21:14:59 +00:00
data . update ( d [ ' value ' ] )
2010-05-17 13:31:14 +00:00
return { ' value ' : data }
2008-08-24 14:45:43 +00:00
event_registration ( )
2012-03-01 10:23:17 +00:00
2011-03-02 17:49:20 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: