1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
24 from osv import fields, osv
25 from tools.translate import _
26 from decimal_precision import decimal_precision as dp
29 class partner_event_registration(osv.osv_memory):
30 """ event Registration """
32 _name = "partner.event.registration"
33 _description = __doc__
37 'event_id': fields.many2one('event.event', 'Event'),
38 'event_type': fields.many2one('event.type', 'Type', readonly=True),
39 'unit_price': fields.float('Registration Cost', digits_compute=dp.get_precision('Sale Price')),
40 'start_date': fields.datetime('Start date', required=True, help="Beginning Date of Event", readonly=True),
41 'end_date': fields.datetime('Closing date', required=True, help="Closing Date of Event", readonly=True),
42 'nb_register': fields.integer('Number of Registration'),
48 def open_registration(self, cr, uid, ids, context=None):
49 """This Function Open Registration For Given Event id and Partner.
53 res_obj = self.pool.get('res.partner')
54 job_obj = self.pool.get('res.partner.job')
55 reg_obj = self.pool.get('event.registration')
56 mod_obj = self.pool.get('ir.model.data')
58 record_ids = context and context.get('active_ids', []) or []
59 addr = res_obj.address_get(cr, uid, record_ids)
62 if addr.has_key('default'):
63 job_ids = job_obj.search(cr, uid, [('address_id', '=', addr['default'])], context=context)
65 contact = job_obj.browse(cr, uid, job_ids[0], context=context)
67 contact_id = contact.contact_id.id
70 result = mod_obj._get_id(cr, uid, 'event', 'view_registration_search')
71 res = mod_obj.read(cr, uid, result, ['res_id'])
74 id2 = mod_obj._get_id(cr, uid, 'event', 'view_event_registration_form')
75 id3 = mod_obj._get_id(cr, uid, 'event', 'view_event_registration_tree')
77 id2 = mod_obj.browse(cr, uid, id2, context=context).res_id
79 id3 = mod_obj.browse(cr, uid, id3, context=context).res_id
81 for current in self.browse(cr, uid, ids, context=context):
82 for partner in res_obj.browse(cr, uid, record_ids, context=context):
83 new_case = reg_obj.create(cr, uid, {
84 'name' : 'Registration',
85 'event_id' : current.event_id and current.event_id.id or False,
86 'unit_price' : current.unit_price,
87 'partner_id' : partner.id,
88 'partner_invoice_id' : partner.id,
89 'event_product': current.event_id.product_id.name,
90 'contact_id': contact_id,
92 'nb_register': current.nb_register,
97 'name': _('Event Registration'),
99 'view_mode': 'tree,form',
100 'res_model': 'event.registration',
102 'views': [(id2, 'form'), (id3, 'tree'), (False, 'calendar'), (False, 'graph')],
103 'type': 'ir.actions.act_window',
104 'search_view_id': res['res_id']
108 def name_get(self, cr, uid, ids, context=None):
109 """Overrides orm name_get method
110 @param ids: List of partner_event_register ids
118 reads = self.read(cr, uid, ids, ['event_type', 'event_id'], context=context)
120 event_id = record['event_id'][1]
121 if record['event_type']:
122 event_id = record['event_type'][1] + ' on ' + event_id
123 res.append((record['id'], event_id))
126 def onchange_event_id(self, cr, uid, ids, event_id, context=None):
128 event_obj = self.pool.get('event.event')
129 product_obj = self.pool.get('product.product')
130 partner_obj = self.pool.get('res.partner')
133 partner_id = context.get('active_id', False)
135 event = event_obj.browse(cr, uid, event_id, context=context)
136 pricelist_id = event.pricelist_id and event.pricelist_id.id or False
138 partner = partner_obj.browse(cr, uid, partner_id, context=context)
139 pricelist_id = pricelist_id or partner.property_product_pricelist.id
140 unit_price = product_obj._product_price(cr, uid, [event.product_id.id], False, False, {'pricelist': pricelist_id})[event.product_id.id]
143 'event_type': event.type and event.type.id or False,
144 'start_date': event.date_begin,
145 'end_date': event.date_end,
146 'unit_price': unit_price,
150 partner_event_registration()
152 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: