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-06-07 06:43:12 +00:00
from crm import crm
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 _
2008-08-24 14:45:43 +00:00
import netsvc
import pooler
2010-06-07 06:43:12 +00:00
import time
2008-08-24 14:45:43 +00:00
import tools
class event_type ( osv . osv ) :
2010-06-07 06:43:12 +00:00
""" 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-05-17 13:31:14 +00:00
' name ' : fields . char ( ' Event type ' , size = 64 , required = True ) ,
2008-08-24 14:45:43 +00:00
}
2010-06-07 06:43:12 +00:00
2008-08-24 14:45:43 +00:00
event_type ( )
class event ( osv . osv ) :
2010-06-07 06:43:12 +00:00
""" Event """
2008-08-24 14:45:43 +00:00
_name = ' event.event '
2010-06-07 06:43:12 +00:00
_description = __doc__
_inherit = ' crm.case.section '
2008-08-24 14:45:43 +00:00
_order = ' date_begin '
def copy ( self , cr , uid , id , default = None , context = None ) :
2010-06-07 06:43:12 +00:00
"""
Copy record of Given id
@param self : The object pointer
@param cr : the current row , from the database cursor ,
@param uid : the current user ’ s ID for security checks ,
@param id : Id of Event Registration type record .
@param context : A standard dictionary for contextual values
"""
2010-05-17 13:31:14 +00:00
return super ( event , self ) . copy ( cr , uid , id , default = { ' code ' : self . pool . get ( ' ir.sequence ' ) . get ( cr , uid , ' event.event ' ) , ' state ' : ' draft ' } )
2008-08-24 14:45:43 +00:00
def button_draft ( self , cr , uid , ids , context = { } ) :
2010-05-17 13:31:14 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' draft ' } )
2008-10-07 09:26:12 +00:00
2008-08-24 14:45:43 +00:00
def button_cancel ( self , cr , uid , ids , context = { } ) :
2010-05-17 13:31:14 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' cancel ' } )
2008-10-07 09:26:12 +00:00
2008-08-24 14:45:43 +00:00
def button_done ( self , cr , uid , ids , context = { } ) :
2010-05-17 13:31:14 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' done ' } )
2008-10-07 09:26:12 +00:00
2008-08-24 14:45:43 +00:00
def button_confirm ( self , cr , uid , ids , context = { } ) :
2010-06-07 06:43:12 +00:00
2008-10-07 09:26:12 +00:00
for eve in self . browse ( cr , uid , ids ) :
if eve . mail_auto_confirm :
#send reminder that will confirm the event for all the people that were already confirmed
2010-06-07 06:43:12 +00:00
reg_ids = self . pool . get ( ' event.registration ' ) . search ( cr , uid ,
[ ( ' event_id ' , ' = ' , eve . id ) ,
( ' state ' , ' not in ' , [ ' draft ' , ' cancel ' ] ) ] )
2008-10-07 09:26:12 +00:00
if reg_ids :
self . pool . get ( ' event.registration ' ) . mail_user_confirm ( cr , uid , reg_ids )
2010-06-07 06:43:12 +00:00
2010-05-17 13:31:14 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' confirm ' } )
2008-08-24 14:45:43 +00:00
def _get_register ( self , cr , uid , ids , name , args , context = None ) :
2010-06-07 06:43:12 +00:00
"""
Get Confirm or uncofirm register value .
@param self : The object pointer
@param cr : the current row , from the database cursor ,
@param uid : the current user ’ s ID for security checks ,
@param ids : List of Event registration type ' s id
@param name : List of function fields ( register_current and register_prospect ) .
@param context : A standard dictionary for contextual values
@return : Dictionary of function fields value .
"""
res = { }
2008-08-24 14:45:43 +00:00
for event in self . browse ( cr , uid , ids , context ) :
2010-05-17 13:31:14 +00:00
res [ event . id ] = { }
state = ' draft '
if name [ 0 ] == ' register_current ' :
state = ' open '
query = """ SELECT sum(r.nb_register)
from event_registration r
where state = % s and event_id = % s """
2010-06-07 06:43:12 +00:00
cr . execute ( query , ( state , event . id , ) )
2008-08-24 14:45:43 +00:00
res2 = cr . fetchone ( )
2010-06-07 06:43:12 +00:00
2008-08-24 14:45:43 +00:00
if res2 and res2 [ 0 ] :
2010-05-17 13:31:14 +00:00
res [ event . id ] [ name [ 0 ] ] = res2 [ 0 ]
2008-08-24 14:45:43 +00:00
else :
2010-05-17 13:31:14 +00:00
res [ event . id ] [ name [ 0 ] ] = 0
2010-06-07 06:43:12 +00:00
2008-08-24 14:45:43 +00:00
return res
2010-05-17 13:31:14 +00:00
def write ( self , cr , uid , ids , vals , * args , * * kwargs ) :
2010-06-07 06:43:12 +00:00
"""
Writes values in one or several fields .
@param cr : the current row , from the database cursor ,
@param uid : the current user ’ s ID for security checks ,
@param ids : List of Event registration type ' s IDs
@param vals : dictionary with values to update .
@return : True
"""
2010-05-17 13:31:14 +00:00
res = super ( event , self ) . write ( cr , uid , ids , vals , * args , * * kwargs )
2008-08-24 14:45:43 +00:00
if ' date_begin ' in vals and vals [ ' date_begin ' ] :
2008-10-07 09:26:12 +00:00
for eve in self . browse ( cr , uid , ids ) :
#change the deadlines of the registration linked to this event
2010-06-07 06:43:12 +00:00
reg_ids = self . pool . get ( ' event.registration ' ) . search ( cr , uid ,
[ ( ' event_id ' , ' = ' , eve . id ) ] )
2008-10-07 09:26:12 +00:00
if reg_ids :
2010-06-07 06:43:12 +00:00
self . pool . get ( ' event.registration ' ) . write ( cr , uid , reg_ids ,
{ ' date_deadline ' : vals [ ' date_begin ' ] } )
2008-10-07 09:26:12 +00:00
#change the description of the registration linked to this event
if ' mail_auto_confirm ' in vals :
if vals [ ' mail_auto_confirm ' ] :
2008-10-08 05:29:16 +00:00
if ' mail_confirm ' not in vals :
2008-10-07 09:26:12 +00:00
for eve in self . browse ( cr , uid , ids ) :
vals [ ' mail_confirm ' ] = eve . mail_confirm
else :
2010-06-07 06:43:12 +00:00
vals [ ' mail_confirm ' ] = False
2008-10-07 09:26:12 +00:00
if ' mail_confirm ' in vals :
for eve in self . browse ( cr , uid , ids ) :
2010-06-07 06:43:12 +00:00
reg_ids = self . pool . get ( ' event.registration ' ) . search ( cr , uid ,
[ ( ' event_id ' , ' = ' , eve . id ) ] )
2008-10-07 09:26:12 +00:00
if reg_ids :
2010-06-07 06:43:12 +00:00
self . pool . get ( ' event.registration ' ) . write ( cr , uid , reg_ids ,
{ ' description ' : vals [ ' mail_confirm ' ] } )
2008-08-24 14:45:43 +00:00
return res
_columns = {
2010-05-17 13:31:14 +00:00
' type ' : fields . many2one ( ' event.type ' , ' Type ' ) ,
' register_max ' : fields . integer ( ' Maximum Registrations ' ) ,
' register_min ' : fields . integer ( ' Minimum Registrations ' ) ,
' register_current ' : fields . function ( _get_register , method = True , string = ' Confirmed Registrations ' , multi = ' register_current ' ) ,
' register_prospect ' : fields . function ( _get_register , method = True , string = ' Unconfirmed Registrations ' , multi = ' register_prospect ' ) ,
' date_begin ' : fields . datetime ( ' Beginning date ' , required = True ) ,
' date_end ' : fields . datetime ( ' Ending date ' , required = True ) ,
' state ' : fields . selection ( [ ( ' draft ' , ' Draft ' ) , ( ' confirm ' , ' Confirmed ' ) , ( ' done ' , ' Done ' ) , ( ' cancel ' , ' Cancelled ' ) ] , ' State ' , readonly = True , required = True ,
2009-11-25 10:03:47 +00:00
help = ' If event is created, the state is \' Draft \' . \n If event is confirmed for the particular dates the state is set to \' Confirmed \' . \
2010-05-17 13:31:14 +00:00
\nIf the event is over , the state is set to \' Done \' . \n If event is cancelled the state is set to \' Cancelled \' . ' ) ,
' mail_auto_registr ' : fields . boolean ( ' Mail Auto Register ' , help = ' Check this box if you want to use the automatic mailing for new registration ' ) ,
' mail_auto_confirm ' : fields . boolean ( ' Mail Auto Confirm ' , help = ' Check this box if you want ot use the automatic confirmation emailing or the reminder ' ) ,
' mail_registr ' : fields . text ( ' Registration Email ' , help = ' This email will be sent when someone subscribes to the event. ' ) ,
' mail_confirm ' : fields . text ( ' Confirmation Email ' , 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 ) ,
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-05-17 13:31:14 +00:00
' state ' : lambda * args : ' draft ' ,
' code ' : lambda obj , cr , uid , context : obj . pool . get ( ' ir.sequence ' ) . get ( cr , uid , ' event.event ' ) ,
' user_id ' : lambda self , cr , uid , ctx : uid ,
2008-08-24 14:45:43 +00:00
}
2010-05-17 13:31:14 +00:00
2008-08-24 14:45:43 +00:00
event ( )
class event_registration ( osv . osv ) :
2010-06-07 06:43:12 +00:00
""" Event Registration """
2008-08-24 14:45:43 +00:00
2010-03-30 12:17:54 +00:00
def check_confirm ( self , cr , uid , ids , context ) :
2010-06-07 06:43:12 +00:00
"""
Check confirm event register on given id .
@param cr : the current row , from the database cursor ,
@param uid : the current user ’ s ID for security checks ,
@param ids : List of Event registration ' s IDs
@param context : A standard dictionary for contextual values
@return : Dictionary value which open Confirm registration form .
"""
2010-03-30 12:17:54 +00:00
mod_obj = self . pool . get ( ' ir.model.data ' )
current_registration = self . browse ( cr , uid , [ ids [ 0 ] ] ) [ 0 ]
total_confirmed = current_registration . event_id . register_current + current_registration . nb_register
if total_confirmed < = current_registration . event_id . register_max or current_registration . event_id . register_max == 0 :
2010-05-17 13:31:14 +00:00
self . write ( cr , uid , [ ids [ 0 ] ] , { ' state ' : ' open ' } , context = context )
2010-03-30 12:17:54 +00:00
self . _history ( cr , uid , [ ids [ 0 ] ] , ' Open ' , history = True )
self . mail_user ( cr , uid , [ ids [ 0 ] ] )
return True
else :
2010-05-17 13:31:14 +00:00
model_data_ids = mod_obj . search ( cr , uid , [ ( ' model ' , ' = ' , ' ir.ui.view ' ) , ( ' name ' , ' = ' , ' view_event_confirm_registration ' ) ] , context = context )
2010-03-30 12:17:54 +00:00
resource_id = mod_obj . read ( cr , uid , model_data_ids , fields = [ ' res_id ' ] , context = context ) [ 0 ] [ ' res_id ' ]
context . update ( { ' reg_id ' : ids [ 0 ] } )
return {
2010-05-17 13:31:14 +00:00
' name ' : _ ( ' Confirm Registration ' ) ,
' context ' : context ,
' view_type ' : ' form ' ,
' view_mode ' : ' tree,form ' ,
' res_model ' : ' event.confirm.registration ' ,
' views ' : [ ( resource_id , ' form ' ) ] ,
' type ' : ' ir.actions.act_window ' ,
' target ' : ' new ' ,
2010-03-30 12:17:54 +00:00
' nodestroy ' : True
}
2010-05-17 13:31:14 +00:00
def _history ( self , cr , uid , ids , keyword , history = False , email = False , context = { } ) :
2010-06-07 06:43:12 +00:00
"""
Create value in mailgateway . message model .
@param cr : the current row , from the database cursor ,
@param uid : the current user ’ s ID for security checks ,
@param ids : List of Event registration ' s IDs
@param context : A standard dictionary for contextual values
@return : True
"""
2008-10-28 16:29:45 +00:00
for case in self . browse ( cr , uid , ids ) :
2008-08-24 14:45:43 +00:00
data = {
2010-05-17 13:31:14 +00:00
' name ' : keyword ,
' som ' : case . som . id ,
' canal_id ' : case . canal_id . id ,
' user_id ' : uid ,
2008-08-24 14:45:43 +00:00
}
2010-05-17 13:31:14 +00:00
obj = self . pool . get ( ' mailgate.message ' )
obj . create ( cr , uid , data , context = context )
2008-08-24 14:45:43 +00:00
return True
def button_reg_close ( self , cr , uid , ids , * args ) :
2010-05-17 13:31:14 +00:00
self . write ( cr , uid , ids , { ' state ' : ' done ' , } )
2008-10-28 16:29:45 +00:00
self . _history ( cr , uid , ids , ' Done ' , history = True )
2008-08-24 14:45:43 +00:00
return True
def button_reg_cancel ( self , cr , uid , ids , * args ) :
2010-05-17 13:31:14 +00:00
self . write ( cr , uid , ids , { ' state ' : ' cancel ' , } )
2008-10-28 16:29:45 +00:00
self . _history ( cr , uid , ids , ' Cancel ' , history = True )
2008-08-24 14:45:43 +00:00
return True
def create ( self , cr , uid , * args , * * argv ) :
2010-06-07 06:43:12 +00:00
""" Overrides orm create method.
@param self : The object pointer
@param cr : the current row , from the database cursor ,
@param uid : the current user ’ s ID for security checks ,
@param * args : Fields value
@return : New created record Id .
"""
2008-10-07 12:51:22 +00:00
event = self . pool . get ( ' event.event ' ) . browse ( cr , uid , args [ 0 ] [ ' event_id ' ] , None )
2010-06-07 06:43:12 +00:00
2008-10-07 12:51:22 +00:00
args [ 0 ] [ ' date_deadline ' ] = event . date_begin
args [ 0 ] [ ' description ' ] = event . mail_confirm
2008-08-24 14:45:43 +00:00
res = super ( event_registration , self ) . create ( cr , uid , * args , * * argv )
2010-06-07 06:43:12 +00:00
2010-05-17 13:31:14 +00:00
self . _history ( cr , uid , [ res ] , ' Created ' , history = True )
2010-06-07 06:43:12 +00:00
2008-08-24 14:45:43 +00:00
return res
def write ( self , cr , uid , * args , * * argv ) :
2010-06-07 06:43:12 +00:00
2008-08-24 14:45:43 +00:00
if ' event_id ' in args [ 1 ] :
2008-10-07 12:51:22 +00:00
event = self . pool . get ( ' event.event ' ) . browse ( cr , uid , args [ 1 ] [ ' event_id ' ] , None )
2010-06-07 06:43:12 +00:00
2008-10-07 12:51:22 +00:00
args [ 1 ] [ ' date_deadline ' ] = event . date_begin
args [ 1 ] [ ' description ' ] = event . mail_confirm
2008-08-24 14:45:43 +00:00
return super ( event_registration , self ) . write ( cr , uid , * args , * * argv )
2010-05-18 14:55:40 +00:00
def mail_user_confirm ( self , cr , uid , ids ) :
2010-06-07 06:43:12 +00:00
"""
@param self : The object pointer
@param cr : the current row , from the database cursor ,
@param uid : the current user ’ s ID for security checks ,
@param ids : List of Event Registration ' s Id.
@return : False
"""
reg_ids = self . browse ( cr , uid , ids )
2008-10-07 09:26:12 +00:00
for reg_id in reg_ids :
src = reg_id . event_id . reply_to or False
2010-05-18 14:55:40 +00:00
dest = [ ]
if reg_id . email_from :
dest + = [ reg_id . email_from ]
2008-10-07 09:26:12 +00:00
if reg_id . email_cc :
dest + = [ reg_id . email_cc ]
if dest and src :
2010-05-17 13:31:14 +00:00
tools . email_send ( src , dest , ' Auto Confirmation: ' + ' [ ' + str ( reg_id . id ) + ' ] ' + ' ' + reg_id . name , reg_id . event_id . mail_confirm , openobject_id = str ( reg_id . id ) )
2008-10-07 09:26:12 +00:00
if not src :
raise osv . except_osv ( _ ( ' Error! ' ) , _ ( ' You must define a reply-to address in order to mail the participant. You can do this in the Mailing tab of your event. Note that this is also the place where you can configure your event to not send emails automaticly while registering ' ) )
return False
2010-05-18 14:55:40 +00:00
def mail_user ( self , cr , uid , ids ) :
2010-06-07 06:43:12 +00:00
"""
@param self : The object pointer
@param cr : the current row , from the database cursor ,
@param uid : the current user ’ s ID for security checks ,
@param ids : List of Event Registration ' s Id.
@return : False
"""
2010-05-18 14:55:40 +00:00
reg_ids = self . browse ( cr , uid , ids )
2010-06-07 06:43:12 +00:00
2008-08-24 14:45:43 +00:00
for reg_id in reg_ids :
2008-10-07 09:26:12 +00:00
src = reg_id . event_id . reply_to or False
2010-05-18 14:55:40 +00:00
dest = [ ]
if reg_id . email_from :
dest + = [ reg_id . email_from ]
2008-10-07 09:26:12 +00:00
if reg_id . email_cc :
dest + = [ reg_id . email_cc ]
if reg_id . event_id . mail_auto_confirm or reg_id . event_id . mail_auto_registr :
if dest and src :
2010-05-17 13:31:14 +00:00
if reg_id . event_id . state in [ ' draft ' , ' fixed ' , ' open ' , ' confirm ' , ' running ' ] and reg_id . event_id . mail_auto_registr :
tools . email_send ( src , dest , ' Auto Registration: ' + ' [ ' + str ( reg_id . id ) + ' ] ' + ' ' + reg_id . name , reg_id . event_id . mail_registr , openobject_id = str ( reg_id . id ) )
if ( reg_id . event_id . state in [ ' confirm ' , ' running ' ] ) and reg_id . event_id . mail_auto_confirm :
tools . email_send ( src , dest , ' Auto Confirmation: ' + ' [ ' + str ( reg_id . id ) + ' ] ' + ' ' + reg_id . name , reg_id . event_id . mail_confirm , openobject_id = str ( reg_id . id ) )
2008-10-07 09:26:12 +00:00
if not src :
raise osv . except_osv ( _ ( ' Error! ' ) , _ ( ' You must define a reply-to address in order to mail the participant. You can do this in the Mailing tab of your event. Note that this is also the place where you can configure your event to not send emails automaticly while registering ' ) )
2008-08-24 14:45:43 +00:00
return False
2008-11-28 13:09:47 +00:00
def _create_invoice_lines ( self , cr , uid , ids , vals ) :
2010-06-07 06:43:12 +00:00
""" Create account Invoice line for Registration Id.
@param self : The object pointer
@param cr : the current row , from the database cursor ,
@param uid : the current user ’ s ID for security checks ,
@param Ids : List of event registration ' s Id
@param vals : Create fields value
@return : New created record Id .
"""
2010-05-17 13:31:14 +00:00
return self . pool . get ( ' account.invoice.line ' ) . create ( cr , uid , vals )
2008-11-28 13:09:47 +00:00
2008-08-24 14:45:43 +00:00
_name = ' event.registration '
2010-06-07 06:43:12 +00:00
_description = __doc__
2010-05-17 13:31:14 +00:00
_inherit = ' crm.meeting '
2008-08-24 14:45:43 +00:00
_columns = {
2010-05-17 13:31:14 +00:00
' email_cc ' : fields . text ( ' Watchers Emails ' , size = 252 , help = " These \
people will receive a copy of the future communication between partner \
2010-06-07 06:43:12 +00:00
and users by email " ),
2010-05-17 13:31:14 +00:00
' nb_register ' : fields . integer ( ' Number of Registration ' , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
' event_id ' : fields . many2one ( ' event.event ' , ' Event Related ' , required = True ) ,
" partner_invoice_id " : fields . many2one ( ' res.partner ' , ' Partner Invoiced ' ) ,
" contact_id " : fields . many2one ( ' res.partner.contact ' , ' Partner Contact ' ) , #TODO: filter only the contacts that have a function into the selected partner_id
" unit_price " : fields . float ( ' Unit Price ' ) ,
" badge_title " : fields . char ( ' Badge Title ' , size = 128 ) ,
" badge_name " : fields . char ( ' Badge Name ' , size = 128 ) ,
" badge_partner " : fields . char ( ' Badge Partner ' , size = 128 ) ,
" invoice_label " : fields . char ( " Label Invoice " , size = 128 , required = True ) ,
" tobe_invoiced " : fields . boolean ( " To be Invoiced " ) ,
" invoice_id " : fields . many2one ( " account.invoice " , " Invoice " ) ,
' 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 ) ,
' canal_id ' : fields . many2one ( ' res.partner.canal ' , ' Channel ' , help = " The channels represent the different communication modes available with the customer. " \
" With each commercial opportunity, you can indicate the canall which is this opportunity source. " ) ,
2010-01-19 05:47:36 +00:00
' som ' : fields . many2one ( ' res.partner.som ' , ' State of Mind ' , help = " The minds states allow to define a value scale which represents " \
" the partner mentality in relation to our services.The scale has " \
2010-05-17 13:31:14 +00:00
" to be created with a factor for each level from 0 (Very dissatisfied) to 10 (Extremely satisfied). " ) ,
2008-08-24 14:45:43 +00:00
}
2010-05-17 13:31:14 +00:00
2008-08-24 14:45:43 +00:00
_defaults = {
2010-05-17 13:31:14 +00:00
' nb_register ' : lambda * a : 1 ,
' tobe_invoiced ' : lambda * a : True ,
' name ' : lambda * a : ' Registration ' ,
2008-08-24 14:45:43 +00:00
}
def onchange_badge_name ( self , cr , uid , ids , badge_name ) :
2010-06-07 06:43:12 +00:00
2008-08-24 14:45:43 +00:00
data = { }
if not badge_name :
return data
data [ ' name ' ] = ' Registration: ' + badge_name
2010-05-17 13:31:14 +00:00
return { ' value ' : data }
2008-08-24 14:45:43 +00:00
2008-10-07 09:26:12 +00:00
def onchange_contact_id ( self , cr , uid , ids , contact , partner ) :
2010-06-07 06:43:12 +00:00
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-06-07 06:43:12 +00:00
2008-10-07 09:26:12 +00:00
contact_id = self . pool . get ( ' res.partner.contact ' ) . browse ( cr , uid , contact )
data [ ' badge_name ' ] = contact_id . name
data [ ' badge_title ' ] = contact_id . title
if partner :
2010-05-17 13:31:14 +00:00
partner_addresses = self . pool . get ( ' res.partner.address ' ) . search ( cr , uid , [ ( ' partner_id ' , ' = ' , partner ) ] )
job_ids = self . pool . get ( ' res.partner.job ' ) . search ( cr , uid , [ ( ' contact_id ' , ' = ' , contact ) , ( ' address_id ' , ' in ' , partner_addresses ) ] )
2008-10-08 05:29:16 +00:00
if job_ids :
data [ ' email_from ' ] = self . pool . get ( ' res.partner.job ' ) . browse ( cr , uid , job_ids [ 0 ] ) . email
2010-05-17 13:31:14 +00:00
d = self . onchange_badge_name ( cr , uid , ids , data [ ' badge_name ' ] )
2008-10-07 09:26:12 +00:00
data . update ( d [ ' value ' ] )
2008-08-24 14:45:43 +00:00
2010-05-17 13:31:14 +00:00
return { ' value ' : data }
2008-08-24 14:45:43 +00:00
def onchange_event ( self , cr , uid , ids , event_id , partner_invoice_id ) :
context = { }
if not event_id :
2010-06-07 06:43:12 +00:00
return { ' value ' : { ' unit_price ' : False , ' invoice_label ' : False } }
2010-05-17 13:31:14 +00:00
data_event = self . pool . get ( ' event.event ' ) . browse ( cr , uid , event_id )
2010-06-07 06:43:12 +00:00
2008-08-24 14:45:43 +00:00
if data_event . product_id :
if not partner_invoice_id :
2010-05-17 13:31:14 +00:00
unit_price = self . pool . get ( ' product.product ' ) . price_get ( cr , uid , [ data_event . product_id . id ] , context = context ) [ data_event . product_id . id ]
2010-06-07 06:43:12 +00:00
return { ' value ' : { ' unit_price ' : unit_price , ' invoice_label ' : data_event . product_id . name } }
2010-05-17 13:31:14 +00:00
data_partner = self . pool . get ( ' res.partner ' ) . browse ( cr , uid , partner_invoice_id )
context . update ( { ' partner_id ' : data_partner } )
unit_price = self . pool . get ( ' product.product ' ) . _product_price ( cr , uid , [ data_event . product_id . id ] , False , False , { ' pricelist ' : data_partner . property_product_pricelist . id } ) [ data_event . product_id . id ]
2010-06-07 06:43:12 +00:00
return { ' value ' : { ' unit_price ' : unit_price , ' invoice_label ' : data_event . product_id . name } }
2010-05-17 13:31:14 +00:00
return { ' value ' : { ' unit_price ' : False , ' invoice_label ' : False } }
2008-08-24 14:45:43 +00:00
2008-10-07 12:51:22 +00:00
def onchange_partner_id ( self , cr , uid , ids , part , event_id , email = False ) :
2010-06-07 06:43:12 +00:00
2008-08-24 14:45:43 +00:00
data = { }
2008-10-07 09:26:12 +00:00
data [ ' badge_partner ' ] = data [ ' contact_id ' ] = data [ ' partner_invoice_id ' ] = data [ ' email_from ' ] = data [ ' badge_title ' ] = data [ ' badge_name ' ] = False
2008-08-24 14:45:43 +00:00
if not part :
2010-05-17 13:31:14 +00:00
return { ' value ' : data }
2008-08-24 14:45:43 +00:00
data [ ' partner_invoice_id ' ] = part
# this calls onchange_partner_invoice_id
2010-05-17 13:31:14 +00:00
d = self . onchange_partner_invoice_id ( cr , uid , ids , event_id , part )
2008-08-24 14:45:43 +00:00
# this updates the dictionary
data . update ( d [ ' value ' ] )
2008-10-07 09:26:12 +00:00
addr = self . pool . get ( ' res.partner ' ) . address_get ( cr , uid , [ part ] )
if addr :
if addr . has_key ( ' default ' ) :
2010-05-17 13:31:14 +00:00
job_ids = self . pool . get ( ' res.partner.job ' ) . search ( cr , uid , [ ( ' address_id ' , ' = ' , addr [ ' default ' ] ) ] )
2008-10-07 09:26:12 +00:00
if job_ids :
data [ ' contact_id ' ] = self . pool . get ( ' res.partner.job ' ) . browse ( cr , uid , job_ids [ 0 ] ) . contact_id . id
2010-05-17 13:31:14 +00:00
d = self . onchange_contact_id ( cr , uid , ids , data [ ' contact_id ' ] , part )
2008-10-07 09:26:12 +00:00
data . update ( d [ ' value ' ] )
partner_data = self . pool . get ( ' res.partner ' ) . browse ( cr , uid , part )
data [ ' badge_partner ' ] = partner_data . name
2010-05-17 13:31:14 +00:00
return { ' value ' : data }
2008-08-24 14:45:43 +00:00
def onchange_partner_invoice_id ( self , cr , uid , ids , event_id , partner_invoice_id ) :
2010-06-07 06:43:12 +00:00
2008-08-24 14:45:43 +00:00
data = { }
context = { }
data [ ' unit_price ' ] = False
if not event_id :
2010-05-17 13:31:14 +00:00
return { ' value ' : data }
data_event = self . pool . get ( ' event.event ' ) . browse ( cr , uid , event_id )
2008-08-24 14:45:43 +00:00
if data_event . product_id :
if not partner_invoice_id :
2010-05-17 13:31:14 +00:00
data [ ' unit_price ' ] = self . pool . get ( ' product.product ' ) . price_get ( cr , uid , [ data_event . product_id . id ] , context = context ) [ data_event . product_id . id ]
return { ' value ' : data }
data_partner = self . pool . get ( ' res.partner ' ) . browse ( cr , uid , partner_invoice_id )
context . update ( { ' partner_id ' : data_partner } )
data [ ' unit_price ' ] = self . pool . get ( ' product.product ' ) . _product_price ( cr , uid , [ data_event . product_id . id ] , False , False , { ' pricelist ' : data_partner . property_product_pricelist . id } ) [ data_event . product_id . id ]
return { ' value ' : data }
return { ' value ' : data }
2008-08-24 14:45:43 +00:00
event_registration ( )
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: