[REF] refactoring the code

bzr revid: mva@openerp.com-20120223101810-dyc7towtmvqemxol
This commit is contained in:
MVA 2012-02-23 11:18:10 +01:00
parent c33c228b68
commit b48f23b6cd
15 changed files with 42 additions and 400 deletions

View File

@ -39,21 +39,19 @@ Note that:
Association / Configuration / Types of Events
""",
'author': 'OpenERP SA',
'depends': ['crm', 'account', 'marketing', 'email_template'],
'depends': ['crm', 'account', 'marketing', 'mail'],
'init_xml': [],
'update_xml': [
'security/ir.model.access.csv',
'wizard/event_confirm_registration_view.xml',
'wizard/event_confirm_view.xml',
'event_view.xml',
'report/report_event_registration_view.xml',
'wizard/partner_event_registration_view.xml',
'board_association_view.xml',
'res_partner_view.xml',
'email_template.xml',
],
'demo_xml': ['event_demo.xml'],
'test': [],
'test': ['test/process/event_draft2done.yml'],
'installable': True,
'active': False,
'auto_install': False,

View File

@ -45,9 +45,6 @@
<action string="Next Events"
name="%(act_event_view)d"
domain="[('state','not in',('cancel','done'))]"/>
<!--<action string="Unconfirmed Registrations"
name="%(event.act_event_list_register_event)d"
domain="[('state','=','draft')]"/>-->
</column>
<column>
<action string="Events Filling Status"

View File

@ -10,7 +10,7 @@
<field name="body_text">
hello ${object.contact_id.name},
The event ${object.event_id.name} that you register is confirmed
The event ${object.event_id.name} that you registered from is confirmed and will be held from ${object.event_id.date_begin} to ${object.event_id.date_end}. For any further information please contact our event department.
we thank you for your participation
@ -29,7 +29,8 @@
<field name="subject">Ticket for ${object.event_id.name}</field>
<field name="body_text">
hello ${object.contact_id.name},
You have just been registered for the event ${object.event_id.name} to be held from ${object.event_id.date_begin} to ${object.event_id.date_end}
We confirm your registration to the event ${object.event_id.name} to be held from ${object.event_id.date_begin} to ${object.event_id.date_end}
we thank you for your participation

View File

@ -27,7 +27,7 @@ from tools.translate import _
import decimal_precision as dp
from crm import wizard
import time
from datetime import datetime
wizard.mail_compose_message.SUPPORTED_MODELS.append('event.registration')
@ -39,12 +39,12 @@ class event_type(osv.osv):
'name': fields.char('Event type', size=64, required=True),
'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." ),
'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"),
'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"),
'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"),
}
_defaults = {
'default_registration_min' : 0,
'default_registration_min': 0,
'default_registration_max':0,
}
@ -59,11 +59,10 @@ class event_event(osv.osv):
def name_get(self, cr, uid, ids, context=None):
if not ids:
return []
reads = self.browse(cr, uid, ids, context=context)
res = []
for record in reads:
date= time.strptime(record.date_begin,'%Y-%m-%d %H:%M:%S')
date =time.strftime('%d/%m/%Y',date)
for record in self.browse(cr, uid, ids, context=context):
date = record.date_begin.split(" ")
date = date[0]
registers=''
if record.register_max !=0:
register_max = str(record.register_max)
@ -71,7 +70,6 @@ class event_event(osv.osv):
register_tot = str(register_tot)
registers = register_tot+'/'+register_max
name = record.name+' ('+date+') '+registers
#TODO create a best method to give the name
res.append((record['id'], name))
return res
@ -79,7 +77,6 @@ class event_event(osv.osv):
res = self.name_get(cr, uid, ids, context=context)
return dict(res)
def copy(self, cr, uid, id, default=None, context=None):
""" Reset the state and the registrations while copying an event
"""
@ -118,7 +115,7 @@ class event_event(osv.osv):
('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)
def _get_register(self, cr, uid, ids, fields, args, context=None):
"""Get Confirm or uncofirm register value.
@param ids: List of Event registration type's id
@ -138,13 +135,12 @@ class event_event(osv.osv):
state += ['open']
if 'register_prospect' in fields:
state.append('draft')
#TODO refactor this part of code to have only one search
reg_ids = register_pool.search(cr, uid, [('event_id', '=', event.id),('state', '=', 'open')], context=context)
reg_ids1= register_pool.search(cr, uid, [('event_id', '=', event.id),('state', '=', 'done')], context=context)
reg_ids2= register_pool.search(cr, uid, [('event_id', '=', event.id),('state', '=', 'draft')], context=context)
res[event.id]['register_current'] = len(reg_ids)
res[event.id]['register_prospect'] = len(reg_ids2)
res[event.id]['register_participated'] = len(reg_ids1)
reg_open_ids = register_pool.search(cr, uid, [('event_id', '=', event.id),('state', '=', 'open')], context=context)
reg_done_ids= register_pool.search(cr, uid, [('event_id', '=', event.id),('state', '=', 'done')], context=context)
reg_draft_ids= register_pool.search(cr, uid, [('event_id', '=', event.id),('state', '=', 'draft')], context=context)
res[event.id]['register_current'] = len(reg_open_ids)
res[event.id]['register_prospect'] = len(reg_done_ids)
res[event.id]['register_attended'] = len(reg_draft_ids)
return res
@ -157,7 +153,7 @@ class event_event(osv.osv):
'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)]}),
'register_current': fields.function(_get_register, string='Confirmed Registrations', multi='register_current'),
'register_prospect': fields.function(_get_register, string='Unconfirmed Registrations', multi='register_prospect'),
'register_participated': fields.function(_get_register, string='Participated Registrations', multi='register_prospect'),
'register_attended': fields.function(_get_register, string='Attended Registrations', multi='register_prospect'),
'registration_ids': fields.one2many('event.registration', 'event_id', 'Registrations', readonly=False, states={'done': [('readonly', True)]}),
'date_begin': fields.datetime('Starting Date', required=True, readonly=True, states={'draft': [('readonly', False)]}),
'date_end': fields.datetime('Closing Date', required=True, readonly=True, states={'draft': [('readonly', False)]}),
@ -171,16 +167,15 @@ class event_event(osv.osv):
'email_registration_id' : fields.many2one('email.template','Registration Confirmation Email'),
'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."),
'full_name' : fields.function(_name_get_fnc, type="char", string='Name'),
'reply_to': fields.char('Reply-To Email', size=64, readonly=False, states={'done': [('readonly', True)]}, 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."),
'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."),
'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."),
'speaker_ids': fields.many2many('res.partner', 'event_speaker_rel', 'speaker_id', 'partner_id', 'Other Speakers', readonly=False, states={'done': [('readonly', True)]}),
'address_id': fields.many2one('res.partner.address','Location Address', readonly=False, states={'done': [('readonly', True)]}),
'speaker_confirmed': fields.boolean('Speaker Confirmed',help='You can choose this checkbox for your information', readonly=False, states={'done': [('readonly', True)]}),
'speaker_confirmed': fields.boolean('Speaker Confirmed',help='You can choose this checkbox for your information => ca veut rien dire ca', readonly=False, states={'done': [('readonly', True)]}),
'country_id': fields.related('address_id', 'country_id',
type='many2one', relation='res.country', string='Country', readonly=False, states={'done': [('readonly', True)]}),
'note': fields.text('Description', readonly=False, states={'done': [('readonly', True)]}),
'company_id': fields.many2one('res.company', 'Company', required=False, change_default=True, readonly=False, states={'done': [('readonly', True)]}),
'product_id': fields.many2one('product.product', 'Product', readonly=True, states={'draft': [('readonly', False)]}, help="The product is optional and only serves informative purposes. It will be used for analysis mainly."),
}
_defaults = {
@ -224,21 +219,21 @@ class event_registration(osv.osv):
'nb_register': fields.integer('Number of Participants', required=True, readonly=True, states={'draft': [('readonly', False)]}),
'event_id': fields.many2one('event.event', 'Event', required=True, readonly=True, states={'draft': [('readonly', False)]}),
'partner_id': fields.many2one('res.partner', 'Partner', states={'done': [('readonly', True)]}),
'partner_id_address': 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)]}), #TODO: filter only the contacts that have a function into the selected partner_id
'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)]}),
'create_date': fields.datetime('Creation Date' , readonly=True),
'date_closed': fields.datetime('Participated Date', readonly=True),
'date_closed': fields.datetime('Attended Date', readonly=True),
'date_open': fields.datetime('Registration Date', readonly=True),
'email_from': fields.related('event_id','reply_to',string='Reply-to Email', type='char', size=128, readonly=True,),
'reply_to': fields.related('event_id','reply_to',string='Reply-to Email', type='char', size=128, readonly=True,),
'log_ids': fields.one2many('mail.message', 'res_id', 'Logs', domain=[('email_from', '=', False),('model','=',_name)]),
'date_deadline': fields.related('event_id','date_end', type='datetime', string="Event End Date", readonly=True),
'date': fields.related('event_id', 'date_begin', type='datetime', string="Event Start Date", readonly=True),
'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),
'user_id': fields.many2one('res.users', 'Responsible', states={'done': [('readonly', True)]}),
'company_id': fields.related('event_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True, states={'draft':[('readonly',False)]}),
'state': fields.selection([('draft', 'Unconfirmed'),
('open', 'Confirmed'),
('cancel', 'Cancelled'),
('done', 'Participated')], 'State', \
('done', 'Attended')], 'State',
size=16, readonly=True)
}
@ -252,6 +247,7 @@ class event_registration(osv.osv):
def do_draft(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'state': 'draft'}, context=context)
def registration_open(self, cr, uid, ids, context=None):
""" Open Registration
"""
@ -275,11 +271,6 @@ class event_registration(osv.osv):
def case_open(self, cr, uid, ids, context):
return self.registration_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)
# return self.write(cr, uid, ids, {'state': 'done'})
# event uses add_note wizard from crm, which expects case_* methods
def case_cancel(self, cr, uid, ids, context=None):
""" Cancel Registration
@ -328,7 +319,7 @@ class event_registration(osv.osv):
if not contact:
return data
addr_obj = self.pool.get('res.partner.address')
contact_id = addr_obj.browse(cr, uid, contact, context)
contact_id = addr_obj.browse(cr, uid, contact, context=context)
data = {
'email':contact_id.email,
'contact_id':contact_id.id,
@ -347,8 +338,8 @@ class event_registration(osv.osv):
event_obj = self.pool.get('event.event')
data_event = event_obj.browse(cr, uid, event_id, context=context)
return {'value':
{'date': data_event.date_begin,
'date_deadline': data_event.date_end,
{'event_begin_date': data_event.date_begin,
'event_end_date': data_event.date_end,
'company_id': data_event.company_id and data_event.company_id.id or False,
}
}

View File

@ -122,7 +122,7 @@
<field name="register_min"/>
<field name="register_max"/>
<field name="register_current"/>
<field name="register_participated"/>
<field name="register_attended"/>
<field name="register_prospect"/>
</group>
<group col="2" colspan="2">
@ -279,7 +279,7 @@
<field name="state"/>
<button name="button_reg_cancel" string="Cancel Registration" states="draft,open" type="object" icon="gtk-cancel"/>
<button name="case_open" string="Confirm Registration" states="draft" type="object" icon="gtk-apply"/>
<button name="case_close" string="participated" states="open" type="object" icon="gtk-apply"/>
<button name="case_close" string="Attended" states="open" type="object" icon="gtk-apply"/>
<button string="Set To Unconfirmed" name="do_draft" states="cancel,done" type="object" icon="gtk-convert"/>
</tree>
</field>
@ -311,15 +311,15 @@
<separator string="Dates" colspan="2"/>
<field name="create_date"/>
<field name="date_closed"/>
<field name="date" />
<field name="date_deadline" />
<field name="event_begin_date" />
<field name="event_end_date" />
</group>
<separator string="" colspan="4"/>
<group col="8" colspan="4">
<field name="state" select="1" colspan="2" widget="statusbar" statusbar_visible="draft,open,done"/>
<button name="button_reg_cancel" string="Cancel Registration" states="draft,open" type="object" icon="gtk-cancel"/>
<button name="button_reg_close" string="participated" states="open" type="object" icon="gtk-apply"/>
<button name="button_reg_close" string="Attended" states="open" type="object" icon="gtk-apply"/>
<button name="case_open" string="Confirm Registration" states="draft" type="object" icon="gtk-apply"/>
<button string="Set To Unconfirmed" name="do_draft" states="cancel,done" type="object" icon="gtk-convert"/>
</group>
@ -328,9 +328,9 @@
<field name="message_ids" colspan="4" nolabel="1" mode="tree">
<tree string="History">
<field name="display_text" string="History Information"/>
<field name="email_from" invisible="1"/>
<field name="reply_to" invisible="1"/>
<button
string="Reply" attrs="{'invisible': [('email_from', '=', False)]}"
string="Reply" attrs="{'invisible': [('reply_to', '=', False)]}"
name="%(mail.action_email_compose_message_wizard)d"
context="{'mail.compose.message.mode':'reply', 'message_id':active_id}"
icon="terp-mail-replied" type="action" />

View File

@ -29,9 +29,6 @@ class res_partner(osv.osv):
'event_ids': fields.one2many('event.event','main_speaker_id', readonly=True),
'event_registration_ids': fields.one2many('event.registration','partner_id', readonly=True),
}
_defaults = {
'speaker':True
}
res_partner()

View File

@ -30,7 +30,7 @@
</field>
<field name="event_registration_ids" colspan="4" nolabel="1">
<tree string="Events Registration">
<field name="date" string="Date"/>
<field name="event_begin_date" string="Date"/>
<field name="event_id" />
<field name="nb_register"/>
<field name="state"/>

View File

@ -1,22 +0,0 @@
-
I want to organize one conference event on "OpenERP Business", Customer subscribe/join
into "Conference on OpenERP Business" with 6 tickets, first I confim this event.
-
!python {model: event.event}: |
self.button_confirm(cr, uid, [ref("event_0")])
-
I Check that Event is "confirmed", and Its automatically sending mail to registered
partner which joined to this event.
-
!assert {model: event.event, id: event_0}:
- state == 'confirm', "Event should be confirmed."
-
After completed event, I close this event.
-
!python {model: event.event}: |
self.button_done(cr, uid, [ref("event_0")])
-
Check that conference is in "close" state.
-
!assert {model: event.event, id: event_0}:
- state == 'done', "Event should be Closed."

View File

@ -1,22 +0,0 @@
-
I want to organize event and its need Minimum 50 Registrations to confirm/start
this Event, but Only 10 registration confirm for this event, I confirm this event.
-
!python {model: event.event}: |
self.button_confirm(cr, uid, [ref("event_1")])
-
Now I cheked for event and It should not be confirm because registrations for
this event is below limit.
-
!assert {model: event.event, id: event_1}:
- state == 'confirm', "Event should be confirm."
-
So I cancel this Event
-
!python {model: event.event}: |
self.button_cancel(cr, uid, [ref("event_1")])
-
I check event should be cancel.
-
!assert {model: event.event, id: event_1}:
- state == 'cancel', "Event should be cancel"

View File

@ -1,32 +0,0 @@
-
I want to organize one conference event, First I registered partner for event
with 5 tickets.
-
!python {model: partner.event.registration}: |
context.update({'active_model': 'res.partner', 'active_ids': [ref("base.res_partner_ericdubois0")], 'active_id': ref("base.res_partner_ericdubois0")})
register = self.create(cr, uid, {'event_id': ref('event_1'),'nb_register': 5}, context=context)
self.open_registration(cr, uid, [register], context=context)
-
Now I check for registration created base on partner.
-
!python {model: event.registration}: |
ids = self.search(cr, uid, [('partner_id','=',ref("base.res_partner_ericdubois0")), ('event_id', '=', ref('event_1'))])
assert ids, "Registration should be create here."
-
I confirm registration process.
-
!python {model: event.registration}: |
self.check_confirm(cr, uid, [ref("reg_1_1")])
-
I Check that Registration is confirm.
-
!assert {model: event.registration, id: reg_1_1}:
- state == 'open', "Registration should be open here."
-
I Check that Registration is close.
-
!assert {model: event.registration, id: reg_1_1}:
- state == 'done', "Registration should be done here."

View File

@ -20,7 +20,5 @@
##############################################################################
import event_confirm_registration
import event_confirm
import partner_event_registration
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,46 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# 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.
#
# 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
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import fields, osv
from tools.translate import _
class event_confirm_registration(osv.osv_memory):
"""
Confirm Event Registration
"""
_name = "event.confirm.registration"
_description = "Confirmation for Event Registration"
_columns = {
'msg': fields.text('Message', readonly=True),
}
_defaults = {
'msg': 'The event limit is reached. What do you want to do?'
}
def confirm(self, cr, uid, ids, context=None):
return {'type': 'ir.actions.act_window_close'}
event_confirm_registration()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,32 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_event_confirm_registration" model="ir.ui.view">
<field name="name">Registration Confirmation</field>
<field name="model">event.confirm.registration</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Registration Confirmation">
<field name="msg" nolabel="1" colspan="4"/>
<separator string="" colspan="4"/>
<group colspan="4" col="6">
<button icon="gtk-close" special="cancel" string="Close"/>
<button icon="gtk-ok" name="confirm" string="Confirm Anyway" type="object"/>
</group>
</form>
</field>
</record>
<record id="action_event_confirm_registration" model="ir.actions.act_window">
<field name="name">Registrations</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">event.confirm.registration</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_event_confirm_registration"/>
<field name="target">new</field>
</record>
</data>
</openerp>

View File

@ -1,140 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# 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.
#
# 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
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import fields, osv
from tools.translate import _
from decimal_precision import decimal_precision as dp
class partner_event_registration(osv.osv_memory):
""" event Registration """
_name = "partner.event.registration"
_description = __doc__
_order = 'event_id'
_columns = {
'event_id': fields.many2one('event.event', 'Event'),
'event_type': fields.many2one('event.type', 'Type', readonly=True),
'unit_price': fields.float('Registration Cost', digits_compute=dp.get_precision('Sale Price')),
'start_date': fields.datetime('Start date', help="Beginning Date of Event", readonly=True),
'end_date': fields.datetime('Closing date', help="Closing Date of Event", readonly=True),
'nb_register': fields.integer('Number of Registration'),
}
_defaults = {
'nb_register': 1,
}
def open_registration(self, cr, uid, ids, context=None):
"""This Function Open Registration For Given Event id and Partner.
"""
value = {}
res_obj = self.pool.get('res.partner')
addr_obj = self.pool.get('res.partner.address')
reg_obj = self.pool.get('event.registration')
mod_obj = self.pool.get('ir.model.data')
record_ids = context and context.get('active_ids', []) or []
addr = res_obj.address_get(cr, uid, record_ids)
email = False
contact_id = addr.get('default', False)
if contact_id:
email = addr_obj.browse(cr, uid, contact_id, context=context).email
result = mod_obj.get_object_reference(cr, uid, 'event', 'view_registration_search')
res = result and result[1] or False
# Select the view
id2 = mod_obj.get_object_reference(cr, uid, 'event', 'view_event_registration_form')
id2 = id2 and id2[1] or False
id3 = mod_obj.get_object_reference(cr, uid, 'event', 'view_event_registration_tree')
id3 = id3 and id3[1] or False
for current in self.browse(cr, uid, ids, context=context):
for partner in res_obj.browse(cr, uid, record_ids, context=context):
new_case = reg_obj.create(cr, uid, {
'name': 'Registration',
'event_id': current.event_id and current.event_id.id or False,
'unit_price': current.unit_price,
'partner_id': partner.id,
'event_product': current.event_id.product_id.name,
'contact_id': contact_id,
'email_from': email,
'nb_register': current.nb_register,
}, context=context)
value = {
'name': _('Event Registration'),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'event.registration',
'res_id': new_case,
'views': [(id2, 'form'), (id3, 'tree'), (False, 'calendar'), (False, 'graph')],
'type': 'ir.actions.act_window',
'search_view_id': res
}
return value
def name_get(self, cr, uid, ids, context=None):
"""Overrides orm name_get method
@param ids: List of partner_event_register ids
"""
res = []
if not ids:
return res
reads = self.read(cr, uid, ids, ['event_type', 'event_id'], context=context)
for record in reads:
event_id = record['event_id'][1]
if record['event_type']:
event_id = record['event_type'][1] + ' on ' + event_id
res.append((record['id'], event_id))
return res
def onchange_event_id(self, cr, uid, ids, event_id, context=None):
res = {}
event_obj = self.pool.get('event.event')
product_obj = self.pool.get('product.product')
partner_obj = self.pool.get('res.partner')
if context is None:
context = {}
partner_id = context.get('active_id', False)
if event_id:
event = event_obj.browse(cr, uid, event_id, context=context)
pricelist_id = event.pricelist_id and event.pricelist_id.id or False
if partner_id:
partner = partner_obj.browse(cr, uid, partner_id, context=context)
pricelist_id = pricelist_id or partner.property_product_pricelist.id
unit_price = product_obj._product_price(cr, uid, [event.product_id.id], False, False, {'pricelist': pricelist_id})[event.product_id.id]
res['value'] = {
'event_type': event.type and event.type.id or False,
'start_date': event.date_begin,
'end_date': event.date_end,
'unit_price': unit_price,
}
return res
partner_event_registration()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,46 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Partner event registration -->
<record id="view_partner_event_registration" model="ir.ui.view">
<field name="name">Partner event registration</field>
<field name="model">partner.event.registration</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Event Registration">
<separator string="Event For Registration" colspan="4"/>
<group colspan="4" col="4">
<field name="event_id" on_change="onchange_event_id(event_id, context)"/>
<field name="nb_register"/>
</group>
<separator string="Event Details" colspan="4"/>
<group colspan="4" col="4">
<field name="start_date"/>
<field name="end_date"/>
<field name="event_type"/>
<field name="unit_price"/>
</group>
<separator string="" colspan="4" />
<group colspan="4" col="6">
<label string="" colspan="2"/>
<button special="cancel" string="_Close" icon="gtk-close"/>
<button name="open_registration" string="_Subcribe" type="object" icon="gtk-go-back"/>
</group>
</form>
</field>
</record>
<act_window name="Event Registration"
res_model="partner.event.registration"
src_model="res.partner"
view_mode="form"
target="new"
key2="client_action_multi"
id="action_partner_event_registration"
/>
</data>
</openerp>