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
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 _
2010-07-15 13:41:44 +00:00
import decimal_precision as dp
2011-02-24 10:13:05 +00:00
from crm import wizard
2008-08-24 14:45:43 +00:00
2011-09-07 17:25:00 +00:00
wizard . mail_compose_message . SUPPORTED_MODELS . append ( ' event.registration ' )
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 ) ,
2008-08-24 14:45:43 +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
def copy ( self , cr , uid , id , default = None , context = None ) :
""" Copy record of Given id
2010-07-12 13:30:56 +00:00
@param id : Id of Event record .
2010-06-07 06:43:12 +00:00
@param context : A standard dictionary for contextual values
"""
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
def onchange_product ( self , cr , uid , ids , product_id = False ) :
2010-07-12 13:30:56 +00:00
""" This function returns value of product ' s unit price based on product 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 IDs
@param product_id : Product ' s id
"""
2010-06-30 14:21:59 +00:00
if not product_id :
return { ' value ' : { ' unit_price ' : False } }
else :
unit_price = self . pool . get ( ' product.product ' ) . price_get ( cr , uid , [ product_id ] ) [ product_id ]
return { ' value ' : { ' unit_price ' : unit_price } }
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 ) :
return self . write ( cr , uid , ids , { ' state ' : ' cancel ' } , context = context )
def button_done ( self , cr , uid , ids , context = None ) :
2010-07-16 08:19:57 +00:00
if type ( ids ) in ( int , long , ) :
ids = [ ids ]
2010-06-26 10:13:40 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' done ' } , context = context )
2010-07-15 13:41:44 +00:00
def do_confirm ( self , cr , uid , ids , context = None ) :
""" Confirm Event and send confirmation email to all register peoples
2010-07-16 06:47:14 +00:00
"""
2010-06-26 10:13:40 +00:00
register_pool = self . pool . get ( ' event.registration ' )
for event in self . browse ( cr , uid , ids , context = context ) :
2012-01-06 13:59:55 +00:00
# if event.mail_auto_confirm:
2008-10-07 09:26:12 +00:00
#send reminder that will confirm the event for all the people that were already confirmed
2010-06-26 10:13:40 +00:00
reg_ids = register_pool . search ( cr , uid , [
2010-07-16 06:47:14 +00:00
( ' event_id ' , ' = ' , event . id ) ,
2010-10-11 06:07:52 +00:00
( ' state ' , ' not in ' , [ ' draft ' , ' cancel ' ] ) ] , context = context )
2010-06-26 10:13:40 +00:00
register_pool . mail_user_confirm ( cr , uid , reg_ids )
2010-07-16 06:47:14 +00:00
2010-10-11 06:07:52 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' confirm ' } , context = context )
2008-08-24 14:45:43 +00:00
2010-07-15 13:41:44 +00:00
def button_confirm ( self , cr , uid , ids , context = None ) :
""" This Function Confirm Event.
@param ids : List of Event IDs
@param context : A standard dictionary for contextual values
@return : True
"""
2010-12-13 07:40:49 +00:00
if context is None :
context = { }
2010-07-16 13:14:31 +00:00
res = False
2010-07-16 08:19:57 +00:00
if type ( ids ) in ( int , long , ) :
ids = [ ids ]
2010-07-15 13:41:44 +00:00
data_pool = self . pool . get ( ' ir.model.data ' )
unconfirmed_ids = [ ]
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 :
2010-07-16 13:14:31 +00:00
res = self . do_confirm ( cr , uid , [ event . id ] , context = context )
2010-07-15 13:41:44 +00:00
else :
unconfirmed_ids . append ( event . id )
if unconfirmed_ids :
2010-10-28 11:44:48 +00:00
view_id = data_pool . get_object_reference ( cr , uid , ' event ' , ' view_event_confirm ' )
2010-10-28 11:25:36 +00:00
view_id = view_id and view_id [ 1 ] or False
2010-07-15 13:41:44 +00:00
context [ ' event_ids ' ] = unconfirmed_ids
return {
2010-07-16 06:47:14 +00:00
' name ' : _ ( ' Confirm Event ' ) ,
' context ' : context ,
' view_type ' : ' form ' ,
' view_mode ' : ' tree,form ' ,
' res_model ' : ' event.confirm ' ,
' views ' : [ ( view_id , ' form ' ) ] ,
' type ' : ' ir.actions.act_window ' ,
' target ' : ' new ' ,
2010-07-15 13:41:44 +00:00
' context ' : context ,
' nodestroy ' : True
2010-08-17 07:04:50 +00:00
}
2010-07-16 13:14:31 +00:00
return res
2010-07-15 13:41:44 +00:00
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 ] = { }
2010-06-26 10:13:40 +00:00
for field in fields :
res [ event . id ] [ field ] = False
state = [ ]
if ' register_current ' in fields :
2010-07-15 13:41:44 +00:00
state + = [ ' open ' , ' done ' ]
2010-07-16 06:47:14 +00:00
if ' register_prospect ' in fields :
2010-06-26 10:13:40 +00:00
state . append ( ' draft ' )
2010-07-16 06:47:14 +00:00
2010-06-26 10:13:40 +00:00
reg_ids = register_pool . search ( cr , uid , [
2010-07-16 06:47:14 +00:00
( ' event_id ' , ' = ' , event . id ) ,
2010-10-11 06:07:52 +00:00
( ' state ' , ' in ' , state ) ] , context = context )
2010-07-16 06:47:14 +00:00
2010-10-07 12:28:54 +00:00
number = 0.0
if reg_ids :
2010-10-11 06:07:52 +00:00
cr . execute ( ' SELECT SUM(nb_register) FROM event_registration WHERE id IN %s ' , ( tuple ( reg_ids ) , ) )
2010-10-07 12:28:54 +00:00
number = cr . fetchone ( )
2010-10-12 05:33:20 +00:00
2010-06-26 10:13:40 +00:00
if ' register_current ' in fields :
2010-10-12 05:33:20 +00:00
res [ event . id ] [ ' register_current ' ] = number and number [ 0 ] or 0.0
2010-07-16 06:47:14 +00:00
if ' register_prospect ' in fields :
2010-10-12 05:33:20 +00:00
res [ event . id ] [ ' register_prospect ' ] = number and number [ 0 ] or 0.0
2008-08-24 14:45:43 +00:00
return res
2010-06-26 10:13:40 +00:00
def write ( self , cr , uid , ids , vals , context = None ) :
2010-06-07 06:43:12 +00:00
"""
Writes values in one or several fields .
@param ids : List of Event registration type ' s IDs
@param vals : dictionary with values to update .
@return : True
"""
2010-06-26 10:13:40 +00:00
register_pool = self . pool . get ( ' event.registration ' )
res = super ( event_event , self ) . write ( cr , uid , ids , vals , context = context )
2012-01-09 15:53:47 +00:00
if vals . get ( ' date_begin ' , False ) or vals . get ( ' mail_confirm ' , False ) :
2010-06-26 10:13:40 +00:00
for event in self . browse ( cr , uid , ids , context = context ) :
2008-10-07 09:26:12 +00:00
#change the deadlines of the registration linked to this event
2010-06-26 10:13:40 +00:00
register_values = { }
if vals . get ( ' date_begin ' , False ) :
register_values [ ' date_deadline ' ] = vals [ ' date_begin ' ]
#change the description of the registration linked to this event
2012-01-09 15:53:47 +00:00
"""
2010-06-26 10:13:40 +00:00
if vals . get ( ' mail_auto_confirm ' , False ) :
if vals [ ' mail_auto_confirm ' ] :
if ' mail_confirm ' not in vals :
vals [ ' mail_confirm ' ] = event . mail_confirm
else :
vals [ ' mail_confirm ' ] = False
if ' mail_confirm ' in vals :
register_values [ ' description ' ] = vals [ ' mail_confirm ' ]
2012-01-09 15:53:47 +00:00
"""
2010-06-26 10:13:40 +00:00
if register_values :
2010-10-11 06:07:52 +00:00
reg_ids = register_pool . search ( cr , uid , [ ( ' event_id ' , ' = ' , event . id ) ] , context = context )
register_pool . write ( cr , uid , reg_ids , register_values , context = context )
2008-08-24 14:45:43 +00:00
return res
_columns = {
2010-07-16 10:16:51 +00:00
' name ' : fields . char ( ' Summary ' , 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 ) ] } ) ,
' 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 ) ] } ) ,
' child_ids ' : fields . one2many ( ' event.event ' , ' parent_id ' , ' Child Events ' , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
2010-07-16 06:47:14 +00:00
' type ' : fields . many2one ( ' event.type ' , ' Type ' , help = " Type of Event like Seminar, Exhibition, Conference, Training. " , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
2011-04-15 06:29:18 +00:00
' register_max ' : fields . integer ( ' Maximum Registrations ' , help = " Provide Maximum Number of Registrations " , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
' register_min ' : fields . integer ( ' Minimum Registrations ' , help = " Provide Minimum Number of Registrations " , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
2011-07-01 23:41:24 +00:00
' register_current ' : fields . function ( _get_register , string = ' Confirmed Registrations ' , multi = ' register_current ' ,
2010-07-16 06:47:14 +00:00
help = " Total of Open and Done Registrations " ) ,
2011-07-01 23:41:24 +00:00
' register_prospect ' : fields . function ( _get_register , string = ' Unconfirmed Registrations ' , multi = ' register_prospect ' ,
2011-04-15 06:29:18 +00:00
help = " Total of Prospect Registrations " ) ,
2010-07-15 13:41:44 +00:00
' registration_ids ' : fields . one2many ( ' event.registration ' , ' event_id ' , ' Registrations ' , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
2010-07-16 06:47:14 +00:00
' date_begin ' : fields . datetime ( ' Beginning date ' , required = True , help = " Beginning Date of Event " , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
' date_end ' : fields . datetime ( ' Closing date ' , required = True , help = " Closing Date of Event " , 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-01-06 08:13:22 +00:00
' email_registration_id ' : fields . many2one ( ' email.template ' , ' Email registration ' ) ,
' email_confirmation_id ' : fields . many2one ( ' email.template ' , ' Email registration ' ) ,
2010-07-18 21:51:49 +00:00
' 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. " ) ,
2010-07-15 13:41:44 +00:00
' 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. " ) ,
2011-04-15 06:29:18 +00:00
' 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 a specific amount for each registration. " , digits_compute = dp . get_precision ( ' Sale Price ' ) ) ,
' 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 ) ] } ) ,
' 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 ) ] } ) ,
' language ' : fields . char ( ' Language ' , size = 64 , 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 ) ] } ) ,
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 ' ,
2010-07-15 13:41:44 +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
}
2010-05-17 13:31:14 +00:00
2010-11-19 13:48:01 +00:00
def _check_recursion ( self , cr , uid , ids , context = None ) :
2010-12-06 13:11:02 +00:00
return super ( event_event , self ) . _check_recursion ( cr , uid , ids , context = context )
2010-07-15 13:41:44 +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_recursion , ' Error ! You cannot create recursive event. ' , [ ' parent_id ' ] ) ,
( _check_closing_date , ' Error ! Closing Date cannot be set before Beginning Date. ' , [ ' date_end ' ] ) ,
2010-07-15 13:41:44 +00:00
]
def do_team_change ( self , cr , uid , ids , team_id , context = None ) :
"""
On Change Callback : when team change , this is call .
2010-07-16 06:47:14 +00:00
on this function , take value of reply_to from selected team .
2010-07-15 13:41:44 +00:00
"""
if not team_id :
return { }
team_pool = self . pool . get ( ' crm.case.section ' )
res = { }
2010-10-27 13:05:24 +00:00
team = team_pool . browse ( cr , uid , team_id , context = context )
2010-07-15 13:41:44 +00:00
if team . reply_to :
res = { ' value ' : { ' reply_to ' : team . reply_to } }
return res
2010-06-30 14:21:59 +00:00
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__
2011-08-22 17:16:59 +00:00
_inherit = ' mail.thread '
2008-08-24 14:45:43 +00:00
2010-07-15 13:41:44 +00:00
def _amount_line ( self , cr , uid , ids , field_name , arg , context = None ) :
cur_obj = self . pool . get ( ' res.currency ' )
res = { }
for line in self . browse ( cr , uid , ids , context = context ) :
price = line . unit_price * line . nb_register
pricelist = line . event_id . pricelist_id or line . partner_invoice_id . property_product_pricelist
cur = pricelist and pricelist . currency_id or False
res [ line . id ] = cur and cur_obj . round ( cr , uid , cur , price ) or price
return res
2010-06-26 10:13:40 +00:00
_columns = {
2011-11-14 22:08:36 +00:00
' id ' : fields . integer ( ' ID ' ) ,
2010-07-16 06:47:14 +00:00
' name ' : fields . char ( ' Summary ' , size = 124 , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
2010-10-13 13:46:45 +00:00
' email_cc ' : fields . text ( ' CC ' , size = 252 , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } , help = " These email addresses will be added to the CC field of all inbound and outbound emails for this record before being sent. Separate multiple email addresses with a comma " ) ,
2010-07-16 06:47:14 +00:00
' nb_register ' : fields . integer ( ' Quantity ' , required = True , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } , help = " Number of Registrations or Tickets " ) ,
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 ) ] } ) ,
2010-07-16 06:47:14 +00:00
" partner_invoice_id " : fields . many2one ( ' res.partner ' , ' Partner Invoiced ' , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
2011-11-25 10:33:20 +00:00
" contact_id " : fields . many2one ( ' res.partner.address ' , ' Partner Contact ' , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) , #TODO: filter only the contacts that have a function into the selected partner_id
2010-10-04 12:18:31 +00:00
" unit_price " : fields . float ( ' Unit Price ' , required = True , digits_compute = dp . get_precision ( ' Sale Price ' ) , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
2011-07-01 23:41:24 +00:00
' price_subtotal ' : fields . function ( _amount_line , string = ' Subtotal ' , digits_compute = dp . get_precision ( ' Sale Price ' ) , store = True ) ,
2010-07-15 13:41:44 +00:00
" badge_ids " : fields . one2many ( ' event.registration.badge ' , ' registration_id ' , ' Badges ' , readonly = False , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
2010-07-16 06:47:14 +00:00
" event_product " : fields . char ( " Invoice Name " , size = 128 , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
" tobe_invoiced " : fields . boolean ( " To be Invoiced " , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
" invoice_id " : fields . many2one ( " account.invoice " , " Invoice " , readonly = True ) ,
' date_closed ' : fields . datetime ( ' Closed ' , readonly = True ) ,
' ref ' : fields . reference ( ' Reference ' , selection = crm . _links_get , size = 128 ) ,
2010-06-30 14:21:59 +00:00
' ref2 ' : fields . reference ( ' Reference 2 ' , selection = crm . _links_get , size = 128 ) ,
2010-07-20 06:22:14 +00:00
' email_from ' : fields . char ( ' Email ' , size = 128 , states = { ' done ' : [ ( ' readonly ' , True ) ] } , help = " These people will receive email. " ) ,
2010-10-13 13:46:45 +00:00
' create_date ' : fields . datetime ( ' Creation Date ' , readonly = True ) ,
' write_date ' : fields . datetime ( ' Write Date ' , readonly = True ) ,
2010-07-20 06:22:14 +00:00
' description ' : fields . text ( ' Description ' , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
2011-08-22 17:16:59 +00:00
' message_ids ' : fields . one2many ( ' mail.message ' , ' res_id ' , ' Messages ' , domain = [ ( ' model ' , ' = ' , _name ) ] ) ,
' log_ids ' : fields . one2many ( ' mail.message ' , ' res_id ' , ' Logs ' , domain = [ ( ' email_from ' , ' = ' , False ) , ( ' model ' , ' = ' , _name ) ] ) ,
2010-07-20 06:22:14 +00:00
' date_deadline ' : fields . related ( ' event_id ' , ' date_end ' , type = ' datetime ' , string = " End Date " , readonly = True ) ,
' date ' : fields . related ( ' event_id ' , ' date_begin ' , type = ' datetime ' , string = " Start Date " , readonly = True ) ,
' user_id ' : fields . many2one ( ' res.users ' , ' Responsible ' , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
' active ' : fields . boolean ( ' Active ' ) ,
' section_id ' : fields . related ( ' event_id ' , ' section_id ' , type = ' many2one ' , relation = ' crm.case.section ' , string = ' Sale Team ' , store = True , 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 ) ] } ) ,
2010-07-20 06:22:14 +00:00
' state ' : fields . selection ( [ ( ' open ' , ' Confirmed ' ) ,
( ' draft ' , ' Unconfirmed ' ) ,
( ' cancel ' , ' Cancelled ' ) ,
( ' done ' , ' Done ' ) ] , ' State ' , \
size = 16 , readonly = True )
2010-06-26 10:13:40 +00:00
}
_defaults = {
2010-07-16 06:47:14 +00:00
' nb_register ' : 1 ,
' tobe_invoiced ' : True ,
2010-10-13 10:50:12 +00:00
' state ' : ' draft ' ,
' active ' : 1 ,
2010-07-20 06:22:14 +00:00
' user_id ' : lambda self , cr , uid , ctx : uid ,
2010-06-26 10:13:40 +00:00
}
2008-08-24 14:45:43 +00:00
2010-06-21 06:02:20 +00:00
def _make_invoice ( self , cr , uid , reg , lines , context = None ) :
2010-06-26 10:13:40 +00:00
""" Create Invoice from Invoice lines
2010-10-13 13:46:45 +00:00
@param reg : Model of Event Registration
2010-07-16 06:47:14 +00:00
@param lines : Ids of Invoice lines
2010-06-26 10:13:40 +00:00
"""
2010-06-21 06:02:20 +00:00
if context is None :
context = { }
2010-06-26 10:13:40 +00:00
inv_pool = self . pool . get ( ' account.invoice ' )
2010-07-16 06:47:14 +00:00
val_invoice = inv_pool . onchange_partner_id ( cr , uid , [ ] , ' out_invoice ' , reg . partner_invoice_id . id , False , False )
2010-06-21 06:02:20 +00:00
val_invoice [ ' value ' ] . update ( { ' partner_id ' : reg . partner_invoice_id . id } )
val_invoice [ ' value ' ] . update ( {
2010-07-16 06:47:14 +00:00
' origin ' : reg . event_product ,
' reference ' : False ,
' invoice_line ' : [ ( 6 , 0 , lines ) ] ,
' comment ' : " " ,
2010-07-05 14:28:43 +00:00
' date_invoice ' : context . get ( ' date_inv ' , False )
2010-06-21 06:02:20 +00:00
} )
2010-10-11 06:07:52 +00:00
inv_id = inv_pool . create ( cr , uid , val_invoice [ ' value ' ] , context = context )
2010-06-26 10:13:40 +00:00
inv_pool . button_compute ( cr , uid , [ inv_id ] )
2011-08-25 12:27:57 +00:00
self . message_append ( cr , uid , [ reg ] , _ ( ' Invoiced ' ) )
2010-06-21 06:02:20 +00:00
return inv_id
2010-11-10 12:49:30 +00:00
def copy ( self , cr , uid , id , default = None , context = None ) :
""" Copy record of Given id
@param id : Id of Registration record .
@param context : A standard dictionary for contextual values
"""
if not default :
default = { }
default . update ( {
' invoice_id ' : False ,
} )
return super ( event_registration , self ) . copy ( cr , uid , id , default = default , context = context )
2010-06-26 10:13:40 +00:00
def action_invoice_create ( self , cr , uid , ids , grouped = False , date_inv = False , context = None ) :
""" Action of Create Invoice """
2010-06-21 06:02:20 +00:00
res = False
invoices = { }
tax_ids = [ ]
2010-07-01 15:29:07 +00:00
new_invoice_ids = [ ]
2010-06-26 10:13:40 +00:00
inv_lines_pool = self . pool . get ( ' account.invoice.line ' )
inv_pool = self . pool . get ( ' account.invoice ' )
product_pool = self . pool . get ( ' product.product ' )
2011-11-25 10:33:20 +00:00
contact_pool = self . pool . get ( ' res.partner.address ' )
2010-11-23 07:05:05 +00:00
if context is None :
2010-06-26 10:13:40 +00:00
context = { }
2010-06-21 06:02:20 +00:00
# If date was specified, use it as date invoiced, usefull when invoices are generated this month and put the
# last day of the last month as invoice date
if date_inv :
context [ ' date_inv ' ] = date_inv
2010-06-26 10:13:40 +00:00
for reg in self . browse ( cr , uid , ids , context = context ) :
val_invoice = inv_pool . onchange_partner_id ( cr , uid , [ ] , ' out_invoice ' , reg . partner_invoice_id . id , False , False )
2010-06-21 06:02:20 +00:00
val_invoice [ ' value ' ] . update ( { ' partner_id ' : reg . partner_invoice_id . id } )
partner_address_id = val_invoice [ ' value ' ] [ ' address_invoice_id ' ]
if not partner_address_id :
raise osv . except_osv ( _ ( ' Error ! ' ) ,
_ ( " Registered partner doesn ' t have an address to make the invoice. " ) )
2010-07-16 06:47:14 +00:00
2010-06-26 10:13:40 +00:00
value = inv_lines_pool . product_id_change ( cr , uid , [ ] , reg . event_id . product_id . id , uom = False , partner_id = reg . partner_invoice_id . id , fposition_id = reg . partner_invoice_id . property_account_position . id )
product = product_pool . browse ( cr , uid , reg . event_id . product_id . id , context = context )
for tax in product . taxes_id :
2010-06-21 06:02:20 +00:00
tax_ids . append ( tax . id )
vals = value [ ' value ' ]
2010-06-26 10:13:40 +00:00
c_name = reg . contact_id and ( ' - ' + contact_pool . name_get ( cr , uid , [ reg . contact_id . id ] ) [ 0 ] [ 1 ] ) or ' '
2010-06-21 06:02:20 +00:00
vals . update ( {
2010-07-16 06:47:14 +00:00
' name ' : reg . event_product + ' - ' + c_name ,
' price_unit ' : reg . unit_price ,
' quantity ' : reg . nb_register ,
' product_id ' : reg . event_id . product_id . id ,
' invoice_line_tax_id ' : [ ( 6 , 0 , tax_ids ) ] ,
2010-06-21 06:02:20 +00:00
} )
2010-06-26 10:13:40 +00:00
inv_line_ids = self . _create_invoice_lines ( cr , uid , [ reg . id ] , vals )
2010-06-21 06:02:20 +00:00
invoices . setdefault ( reg . partner_id . id , [ ] ) . append ( ( reg , inv_line_ids ) )
for val in invoices . values ( ) :
2010-07-01 15:29:07 +00:00
res = False
2010-06-21 06:02:20 +00:00
if grouped :
2010-10-13 13:46:45 +00:00
res = self . _make_invoice ( cr , uid , val [ 0 ] [ 0 ] , [ v for k , v in val ] , context = context )
2010-07-16 06:47:14 +00:00
2010-10-13 13:46:45 +00:00
for k , v in val :
2010-07-15 13:41:44 +00:00
self . do_close ( cr , uid , [ k . id ] , context = { ' invoice_id ' : res } )
2010-07-16 06:47:14 +00:00
2010-06-21 06:02:20 +00:00
else :
2010-10-13 13:46:45 +00:00
for k , v in val :
2010-06-21 06:02:20 +00:00
res = self . _make_invoice ( cr , uid , k , [ v ] , context = context )
2010-07-15 13:41:44 +00:00
self . do_close ( cr , uid , [ k . id ] , context = { ' invoice_id ' : res } )
2010-07-01 15:29:07 +00:00
if res : new_invoice_ids . append ( res )
return new_invoice_ids
2010-06-21 06:02:20 +00:00
2010-07-15 13:41:44 +00:00
def do_open ( self , cr , uid , ids , context = None ) :
""" Open Registration
"""
res = self . write ( cr , uid , ids , { ' state ' : ' open ' } , context = context )
2010-07-16 06:47:14 +00:00
self . mail_user ( cr , uid , ids )
2011-08-25 12:27:57 +00:00
self . message_append ( cr , uid , ids , _ ( ' Open ' ) )
2010-07-16 06:47:14 +00:00
return res
2010-07-15 13:41:44 +00:00
def do_close ( self , cr , uid , ids , context = None ) :
""" Close Registration
"""
2010-11-23 07:05:05 +00:00
if context is None :
2010-07-15 13:41:44 +00:00
context = { }
invoice_id = context . get ( ' invoice_id ' , False )
values = { ' state ' : ' done ' , ' date_closed ' : time . strftime ( ' % Y- % m- %d % H: % M: % S ' ) }
msg = _ ( ' Done ' )
if invoice_id :
2010-07-16 06:47:14 +00:00
values [ ' invoice_id ' ] = invoice_id
2010-07-15 13:41:44 +00:00
res = self . write ( cr , uid , ids , values )
2011-08-25 12:27:57 +00:00
self . message_append ( cr , uid , ids , msg )
2010-07-15 13:41:44 +00:00
return res
2011-12-22 17:02:05 +00:00
# event uses add_note wizard from crm, which expects case_* methods
def case_open ( self , cr , uid , ids , context = None ) :
self . do_open ( cr , uid , ids , context )
# event uses add_note wizard from crm, which expects case_* methods
def case_close ( self , cr , uid , ids , context = None ) :
self . do_close ( cr , uid , ids , context )
# event uses add_note wizard from crm, which expects case_* methods
def case_cancel ( self , cr , uid , ids , context = None ) :
""" Cancel Registration
"""
self . message_append ( cr , uid , ids , _ ( ' Cancel ' ) )
return self . write ( cr , uid , ids , { ' state ' : ' cancel ' } )
# event uses add_note wizard from crm, which expects case_* methods
def case_reset ( self , cr , uid , ids , context = None ) :
pass
# event uses add_note wizard from crm, which expects case_* methods
def case_pending ( self , cr , uid , ids , context = None ) :
pass
2010-06-26 10:13:40 +00:00
def check_confirm ( self , cr , uid , ids , context = None ) :
2010-07-12 13:30:56 +00:00
""" This Function Open Event Registration and send email to user.
2010-06-07 06:43:12 +00:00
@param ids : List of Event registration ' s IDs
@param context : A standard dictionary for contextual values
2010-07-12 13:30:56 +00:00
@return : True
2010-06-07 06:43:12 +00:00
"""
2010-10-12 12:54:35 +00:00
if type ( ids ) in ( int , long , ) :
ids = [ ids ]
2010-06-26 10:13:40 +00:00
data_pool = self . pool . get ( ' ir.model.data ' )
unconfirmed_ids = [ ]
2010-11-23 07:05:05 +00:00
if context is None :
context = { }
2010-06-26 10:13:40 +00:00
for registration in self . browse ( cr , uid , ids , context = context ) :
total_confirmed = registration . event_id . register_current + registration . nb_register
if total_confirmed < = registration . event_id . register_max or registration . event_id . register_max == 0 :
2010-10-11 06:07:52 +00:00
self . do_open ( cr , uid , [ registration . id ] , context = context )
2010-06-21 06:02:20 +00:00
else :
2010-06-26 10:13:40 +00:00
unconfirmed_ids . append ( registration . id )
if unconfirmed_ids :
2010-10-28 11:44:48 +00:00
view_id = data_pool . get_object_reference ( cr , uid , ' event ' , ' view_event_confirm_registration ' )
2010-10-28 11:25:36 +00:00
view_id = view_id and view_id [ 1 ] or False
2010-06-26 10:13:40 +00:00
context [ ' registration_ids ' ] = unconfirmed_ids
2010-03-30 12:17:54 +00:00
return {
2010-07-16 06:47:14 +00:00
' name ' : _ ( ' Confirm Registration ' ) ,
' context ' : context ,
' view_type ' : ' form ' ,
' view_mode ' : ' tree,form ' ,
' res_model ' : ' event.confirm.registration ' ,
' views ' : [ ( view_id , ' form ' ) ] ,
' type ' : ' ir.actions.act_window ' ,
' target ' : ' new ' ,
2010-06-26 10:13:40 +00:00
' context ' : context ,
2010-03-30 12:17:54 +00:00
' nodestroy ' : True
}
2010-07-16 06:47:14 +00:00
return True
2010-03-30 12:17:54 +00:00
2010-07-15 13:41:44 +00:00
def button_reg_close ( self , cr , uid , ids , context = None ) :
2010-07-16 06:47:14 +00:00
""" This Function Close Event Registration.
"""
2010-07-15 13:41:44 +00:00
data_pool = self . pool . get ( ' ir.model.data ' )
unclosed_ids = [ ]
for registration in self . browse ( cr , uid , ids , context = context ) :
if registration . tobe_invoiced and not registration . invoice_id :
unclosed_ids . append ( registration . id )
else :
2010-10-11 06:07:52 +00:00
self . do_close ( cr , uid , [ registration . id ] , context = context )
2010-07-15 13:41:44 +00:00
if unclosed_ids :
2010-10-28 11:44:48 +00:00
view_id = data_pool . get_object_reference ( cr , uid , ' event ' , ' view_event_make_invoice ' )
2010-10-28 11:25:36 +00:00
view_id = view_id and view_id [ 1 ] or False
2010-07-15 13:41:44 +00:00
context [ ' active_ids ' ] = unclosed_ids
return {
2010-07-16 06:47:14 +00:00
' name ' : _ ( ' Close Registration ' ) ,
' context ' : context ,
' view_type ' : ' form ' ,
' view_mode ' : ' tree,form ' ,
' res_model ' : ' event.make.invoice ' ,
' views ' : [ ( view_id , ' form ' ) ] ,
' type ' : ' ir.actions.act_window ' ,
' target ' : ' new ' ,
2010-07-15 13:41:44 +00:00
' context ' : context ,
' nodestroy ' : True
}
2008-08-24 14:45:43 +00:00
return True
2010-07-16 06:47:14 +00:00
2011-12-22 17:02:05 +00:00
def button_reg_cancel ( self , cr , uid , ids , context = None , * args ) :
return self . case_cancel ( cr , uid , ids )
2010-06-21 06:02:20 +00:00
2010-06-26 10:13:40 +00:00
def mail_user ( self , cr , uid , ids , confirm = False , context = None ) :
2010-06-21 06:02:20 +00:00
"""
2010-07-16 06:47:14 +00:00
Send email to user
2012-01-06 13:59:55 +00:00
"""
mail_message = self . pool . get ( ' email.template ' )
2011-09-07 17:25:00 +00:00
for registration in self . browse ( cr , uid , ids , context = context ) :
2012-01-06 13:59:55 +00:00
# src = registration.reply_to or False
2010-07-15 13:41:44 +00:00
email_to = [ ]
email_cc = [ ]
2011-09-07 17:25:00 +00:00
if registration . email_from :
2011-09-07 20:27:02 +00:00
email_to = [ registration . email_from ]
2011-09-07 17:25:00 +00:00
if registration . email_cc :
email_cc + = [ registration . email_cc ]
2010-08-17 07:04:50 +00:00
if not ( email_to or email_cc ) :
2010-07-15 13:41:44 +00:00
continue
subject = " "
body = " "
if confirm :
2011-09-07 17:25:00 +00:00
subject = _ ( ' Auto Confirmation: [ %s ] %s ' ) % ( registration . id , registration . name )
body = registration . event_id . mail_confirm
elif registration . event_id . mail_auto_confirm or registration . event_id . mail_auto_registr :
if registration . event_id . state in [ ' draft ' , ' fixed ' , ' open ' , ' confirm ' , ' running ' ] and registration . event_id . mail_auto_registr :
subject = _ ( ' Auto Registration: [ %s ] %s ' ) % ( registration . id , registration . name )
body = registration . event_id . mail_registr
if ( registration . event_id . state in [ ' confirm ' , ' running ' ] ) and registration . event_id . mail_auto_confirm :
subject = _ ( ' Auto Confirmation: [ %s ] %s ' ) % ( registration . id , registration . name )
body = registration . event_id . mail_confirm
2010-07-15 13:41:44 +00:00
if subject or body :
2011-09-07 17:25:00 +00:00
mail_message . schedule_with_attach ( cr , uid , src , email_to , subject , body , model = ' event.registration ' , email_cc = email_cc , res_id = registration . id )
2012-01-06 13:59:55 +00:00
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
"""
2010-07-16 06:47:14 +00:00
Send email to user
2010-06-07 06:43:12 +00:00
"""
2010-06-26 10:13:40 +00:00
return self . mail_user ( cr , uid , ids , confirm = True , context = context )
2008-08-24 14:45:43 +00:00
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.
"""
2010-07-16 06:47:14 +00:00
return self . pool . get ( ' account.invoice.line ' ) . create ( cr , uid , vals )
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-07-16 06:47:14 +00:00
2010-10-13 13:46:45 +00:00
""" This function returns value of Badge Name, Badge Title based on Partner contact.
2010-07-12 13:30:56 +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 Registration IDs
@param contact : Patner Contact IDS
2010-07-16 06:47:14 +00:00
@param partner : Partner IDS
2010-07-12 13:30:56 +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-07-12 13:30:56 +00:00
addr_obj = self . pool . get ( ' res.partner.address ' )
2011-12-18 21:14:59 +00:00
data [ ' email_from ' ] = addr_obj . browse ( cr , uid , contact ) . email
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 ) :
2010-07-12 13:30:56 +00:00
""" This function returns value of Product Name, Unit Price based on Event.
@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 Registration IDs
@param event_id : Event ID
2010-07-16 06:47:14 +00:00
@param partner_invoice_id : Partner Invoice ID
2010-07-12 13:30:56 +00:00
"""
2010-10-27 13:10:19 +00:00
context = { }
2008-08-24 14:45:43 +00:00
if not event_id :
2010-06-21 06:02:20 +00:00
return { ' value ' : { ' unit_price ' : False , ' event_product ' : False } }
2010-07-16 06:47:14 +00:00
2010-07-12 13:30:56 +00:00
event_obj = self . pool . get ( ' event.event ' )
prod_obj = self . pool . get ( ' product.product ' )
2010-08-17 07:04:50 +00:00
res_obj = self . pool . get ( ' res.partner ' )
2010-07-16 06:47:14 +00:00
2010-07-12 13:30:56 +00:00
data_event = event_obj . browse ( cr , uid , event_id )
2010-10-11 06:07:52 +00:00
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 ,
' section_id ' : data_event . section_id and data_event . section_id . id or False ,
2010-07-20 06:22:14 +00:00
} }
2010-07-10 09:16:49 +00:00
if data_event . user_id . id :
2010-10-11 06:07:52 +00:00
res [ ' value ' ] . update ( { ' user_id ' : data_event . user_id . id } )
2008-08-24 14:45:43 +00:00
if data_event . product_id :
2010-07-15 13:41:44 +00:00
pricelist_id = data_event . pricelist_id and data_event . pricelist_id . id or False
if partner_invoice_id :
partner = res_obj . browse ( cr , uid , partner_invoice_id , context = context )
pricelist_id = pricelist_id or partner . property_product_pricelist . id
unit_price = prod_obj . _product_price ( cr , uid , [ data_event . product_id . id ] , False , False , { ' pricelist ' : pricelist_id } ) [ data_event . product_id . id ]
2010-07-20 06:40:23 +00:00
if not unit_price :
unit_price = data_event . unit_price
2010-07-16 06:47:14 +00:00
res [ ' value ' ] . update ( { ' unit_price ' : unit_price , ' event_product ' : data_event . product_id . name } )
2010-07-15 13:41:44 +00:00
return res
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-07-12 13:30:56 +00:00
""" This function returns value of Patner Invoice id, Unit Price, badget title based on partner and Event.
@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 Registration IDs
@param event_id : Event ID
@param partner_invoice_id : Partner Invoice ID
"""
res_obj = self . pool . get ( ' res.partner ' )
2010-07-16 06:47:14 +00:00
2010-07-15 13:41:44 +00:00
data = { }
data [ ' contact_id ' ] , data [ ' partner_invoice_id ' ] , data [ ' email_from ' ] = ( False , False , False )
2008-08-24 14:45:43 +00:00
if not part :
2010-05-17 13:31:14 +00:00
return { ' value ' : data }
2010-10-11 06:07:52 +00:00
data [ ' partner_invoice_id ' ] = part
2008-08-24 14:45:43 +00:00
# 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 ' ] )
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 :
2011-12-18 21:14:59 +00:00
d = self . onchange_contact_id ( cr , uid , ids , addr , part )
data . update ( d [ ' value ' ] )
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-07-12 13:30:56 +00:00
""" This function returns value of Product unit Price based on Invoiced partner.
@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 Registration IDs
@param event_id : Event ID
@param partner_invoice_id : Partner Invoice ID
"""
2010-10-11 06:07:52 +00:00
data = { }
context = { }
2010-07-12 13:30:56 +00:00
event_obj = self . pool . get ( ' event.event ' )
prod_obj = self . pool . get ( ' product.product ' )
res_obj = self . pool . get ( ' res.partner ' )
2010-07-16 06:47:14 +00:00
2008-08-24 14:45:43 +00:00
data [ ' unit_price ' ] = False
if not event_id :
2010-05-17 13:31:14 +00:00
return { ' value ' : data }
2010-10-11 06:07:52 +00:00
data_event = event_obj . browse ( cr , uid , event_id , context = context )
2008-08-24 14:45:43 +00:00
if data_event . product_id :
2010-07-15 13:41:44 +00:00
data [ ' event_product ' ] = data_event . product_id . name
pricelist_id = data_event . pricelist_id and data_event . pricelist_id . id or False
if partner_invoice_id :
partner = res_obj . browse ( cr , uid , partner_invoice_id , context = context )
pricelist_id = pricelist_id or partner . property_product_pricelist . id
2010-07-20 06:40:23 +00:00
unit_price = prod_obj . _product_price ( cr , uid , [ data_event . product_id . id ] , False , False , { ' pricelist ' : pricelist_id } ) [ data_event . product_id . id ]
if not unit_price :
unit_price = data_event . unit_price
data [ ' unit_price ' ] = unit_price
2010-05-17 13:31:14 +00:00
return { ' value ' : data }
2008-08-24 14:45:43 +00:00
event_registration ( )
2010-07-15 13:41:44 +00:00
class event_registration_badge ( osv . osv ) :
_name = ' event.registration.badge '
_description = __doc__
_columns = {
2010-10-26 12:40:14 +00:00
" registration_id " : fields . many2one ( ' event.registration ' , ' Registration ' , required = True ) ,
2010-07-16 06:47:14 +00:00
" title " : fields . char ( ' Title ' , size = 128 ) ,
" name " : fields . char ( ' Name ' , size = 128 , required = True ) ,
" address_id " : fields . many2one ( ' res.partner.address ' , ' Address ' ) ,
2010-07-15 13:41:44 +00:00
}
2010-10-13 10:50:12 +00:00
2010-07-15 13:41:44 +00:00
event_registration_badge ( )
2011-03-02 17:49:20 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: