From db2cdc75ab7664f84a2a455b68449d53c1d8889f Mon Sep 17 00:00:00 2001 From: MVA Date: Tue, 7 Feb 2012 10:41:25 +0100 Subject: [PATCH] [MERGE] merge with event module bzr revid: mva@openerp.com-20120207094125-t3ze0w9pxh2af7a7 --- addons/event/__openerp__.py | 1 - addons/event/event.py | 311 +++--------------- addons/event/event_view.xml | 233 ++++++------- addons/event/wizard/event_make_invoice.py | 38 --- .../event/wizard/event_make_invoice_view.xml | 37 --- 5 files changed, 141 insertions(+), 479 deletions(-) delete mode 100644 addons/event/wizard/event_make_invoice.py delete mode 100644 addons/event/wizard/event_make_invoice_view.xml diff --git a/addons/event/__openerp__.py b/addons/event/__openerp__.py index b55e7439bd0..aaf50779c0c 100644 --- a/addons/event/__openerp__.py +++ b/addons/event/__openerp__.py @@ -56,7 +56,6 @@ Note that: 'test': [], 'installable': True, 'active': False, - 'certificate': '0083059161581', 'images': ['images/1_event_type_list.jpeg','images/2_events.jpeg','images/3_registrations.jpeg'], } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/event/event.py b/addons/event/event.py index 66fee6c7f7b..04da0d6e463 100644 --- a/addons/event/event.py +++ b/addons/event/event.py @@ -45,12 +45,9 @@ class event_event(osv.osv): _name = 'event.event' _description = __doc__ _order = 'date_begin' - def copy(self, cr, uid, id, default=None, context=None): - """ Copy record of Given id - @param id: Id of Event record. - @param context: A standard dictionary for contextual values + """ Reset the state and the registrations while copying an event """ if not default: default = {} @@ -60,20 +57,6 @@ class event_event(osv.osv): }) return super(event_event, self).copy(cr, uid, id, default=default, context=context) - def onchange_product(self, cr, uid, ids, product_id=False): - """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 - """ - 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}} - def button_draft(self, cr, uid, ids, context=None): return self.write(cr, uid, ids, {'state': 'draft'}, context=context) @@ -81,61 +64,27 @@ class event_event(osv.osv): return self.write(cr, uid, ids, {'state': 'cancel'}, context=context) def button_done(self, cr, uid, ids, context=None): - if type(ids) in (int, long,): - ids = [ids] return self.write(cr, uid, ids, {'state': 'done'}, context=context) - def do_confirm(self, cr, uid, ids, context=None): + def button_confirm(self, cr, uid, ids, context=None): """ Confirm Event and send confirmation email to all register peoples """ + if isinstance(ids, (int, long)): + ids = [ids] + #renforcing method : create a list of ids register_pool = self.pool.get('event.registration') for event in self.browse(cr, uid, ids, context=context): - # if event.mail_auto_confirm: + total_confirmed = event.register_current + if total_confirmed < event.register_min or total_confirmed > event.register_max: + raise osv.except_osv(_('Error!'),_("The total of confirmed registration for the event '%s' does not meet the expected minimum/maximum. You should maybe reconsider those limits before going further") % (even.name)) + if event.email_confirmation_id: #send reminder that will confirm the event for all the people that were already confirmed reg_ids = register_pool.search(cr, uid, [ ('event_id', '=', event.id), ('state', 'not in', ['draft', 'cancel'])], context=context) register_pool.mail_user_confirm(cr, uid, reg_ids) - return self.write(cr, uid, ids, {'state': 'confirm'}, context=context) - 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 - """ - if context is None: - context = {} - res = False - if type(ids) in (int, long,): - ids = [ids] - 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: - res = self.do_confirm(cr, uid, [event.id], context=context) - else: - unconfirmed_ids.append(event.id) - if unconfirmed_ids: - view_id = data_pool.get_object_reference(cr, uid, 'event', 'view_event_confirm') - view_id = view_id and view_id[1] or False - context['event_ids'] = unconfirmed_ids - return { - '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', - 'context': context, - 'nodestroy': True - } - return res - 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 @@ -170,38 +119,10 @@ class event_event(osv.osv): res[event.id]['register_prospect'] = number and number[0] or 0.0 return res - def write(self, cr, uid, ids, vals, context=None): - """ - 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 - """ - register_pool = self.pool.get('event.registration') - res = super(event_event, self).write(cr, uid, ids, vals, context=context) - if vals.get('date_begin', False) or vals.get('mail_confirm', False): - for event in self.browse(cr, uid, ids, context=context): - #change the deadlines of the registration linked to this event - 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 - - if 'mail_confirm' in vals: - register_values['description'] = vals['mail_confirm'] - - if register_values: - reg_ids = register_pool.search(cr, uid, [('event_id', '=', event.id)], context=context) - register_pool.write(cr, uid, reg_ids, register_values, context=context) - return res - _columns = { 'name': fields.char('Name', size=64, required=True, translate=True, readonly=False, states={'done': [('readonly', True)]}), '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)]}), 'type': fields.many2one('event.type', 'Type', help="Type of Event like Seminar, Exhibition, Conference, Training.", readonly=False, states={'done': [('readonly', True)]}), '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)]}), @@ -219,23 +140,18 @@ class event_event(osv.osv): ('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\'.'), - 'email_registration_id' : fields.many2one('email.template','Email registration'), 'email_confirmation_id' : fields.many2one('email.template','Email confirmation'), 'reply_to': fields.char('Reply-To', size=64, readonly=False, states={'done': [('readonly', True)]}, help="The email address put in the 'Reply-To' of all emails sent by OpenERP"), - - '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."), - '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."), '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', 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)]}), - 'language': fields.char('Language',size=64, 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 = { @@ -244,9 +160,6 @@ class event_event(osv.osv): 'user_id': lambda obj, cr, uid, context: uid, } - def _check_recursion(self, cr, uid, ids, context=None): - return super(event_event, self)._check_recursion(cr, uid, ids, context=context) - def _check_closing_date(self, cr, uid, ids, context=None): for event in self.browse(cr, uid, ids, context=context): if event.date_end < event.date_begin: @@ -254,10 +167,9 @@ class event_event(osv.osv): return True _constraints = [ - (_check_recursion, 'Error ! You cannot create recursive event.', ['parent_id']), (_check_closing_date, 'Error ! Closing Date cannot be set before Beginning Date.', ['date_end']), ] - + #TODO: display sale_team in event form view and use this onchange def do_team_change(self, cr, uid, ids, team_id, context=None): """ On Change Callback: when team change, this is call. @@ -280,48 +192,24 @@ class event_registration(osv.osv): _description = __doc__ _inherit = ['mail.thread','res.partner.address'] - - 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 - _columns = { 'id': fields.integer('ID'), 'origin': fields.char('Origin', size=124, readonly=True, states={'draft': [('readonly', False)]}), - '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"), 'nb_register': fields.integer('Quantity', required=True, readonly=True, states={'draft': [('readonly', False)]}, help="Number of Registrations or Tickets"), '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)]}), - "partner_invoice_id": fields.many2one('res.partner', 'Partner Invoiced', readonly=True, states={'draft': [('readonly', False)]}), "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 - "unit_price": fields.float('Unit Price', required=True, digits_compute=dp.get_precision('Sale Price'), readonly=True, states={'draft': [('readonly', False)]}), - 'price_subtotal': fields.function(_amount_line, string='Subtotal', digits_compute=dp.get_precision('Sale Price'), store=True), - "event_product": fields.char("Invoice Name", size=128, 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), - 'ref2': fields.reference('Reference 2', selection=crm._links_get, size=128), - 'email_from': fields.char('Email', size=128, states={'done': [('readonly', True)]}, help="These people will receive email."), - 'create_date': fields.datetime('Creation Date', readonly=True), - 'write_date': fields.datetime('Write Date', readonly=True), - 'description': fields.text('Description', states={'done': [('readonly', True)]}), - 'message_ids': fields.one2many('mail.message', 'res_id', 'Messages', domain=[('model','=',_name)]), + 'date_closed': fields.datetime('Closure Date', readonly=True), + 'email_from': 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="End Date", readonly=True), - 'date': fields.related('event_id', 'date_begin', type='datetime', string="Start Date", readonly=True), + '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), '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), '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([('open', 'Confirmed'), - ('draft', 'Unconfirmed'), + 'state': fields.selection([('draft', 'Unconfirmed'), + ('open', 'Confirmed'), ('cancel', 'Cancelled'), ('done', 'Done')], 'State', \ size=16, readonly=True) @@ -329,25 +217,8 @@ class event_registration(osv.osv): _defaults = { 'nb_register': 1, 'state': 'draft', - 'active': 1, 'user_id': lambda self, cr, uid, ctx: uid, } - - - - 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) - - def do_open(self, cr, uid, ids, context=None): """ Open Registration @@ -362,78 +233,40 @@ class event_registration(osv.osv): """ if context is None: 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: - values['invoice_id'] = invoice_id res = self.write(cr, uid, ids, values) self.message_append(cr, uid, ids, msg) return res - + # 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) - return self.write(cr, uid, ids, {'state': 'done'}) + #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 """ 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 - - def check_confirm(self, cr, uid, ids, context=None): - """This Function Open Event Registration and send email to user. - @param ids: List of Event registration's IDs - @param context: A standard dictionary for contextual values - @return: True - """ - if type(ids) in (int, long,): - ids = [ids] - data_pool = self.pool.get('ir.model.data') - unconfirmed_ids = [] - if context is None: - context = {} - 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: - self.do_open(cr, uid, [registration.id], context=context) - else: - unconfirmed_ids.append(registration.id) - if unconfirmed_ids: - view_id = data_pool.get_object_reference(cr, uid, 'event', 'view_event_confirm_registration') - view_id = view_id and view_id[1] or False - context['registration_ids'] = unconfirmed_ids - return { - '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', - 'context': context, - 'nodestroy': True - } - return True - def button_reg_close(self, cr, uid, ids, context=None): - """This Function Close Event Registration. - """ - return self.case_close(cr, uid, ids) + #def button_reg_close(self, cr, uid, ids, context=None): + # """This Function Close Event Registration. + # """ + # return self.case_close(cr, uid, ids) def button_reg_cancel(self, cr, uid, ids, context=None, *args): return self.case_cancel(cr, uid, ids) @@ -441,7 +274,7 @@ class event_registration(osv.osv): def mail_user(self, cr, uid, ids, confirm=False, context=None): """ Send email to user with email_template when registration is done -""" + """ for registration in self.browse(cr, uid, ids, context=context): template_id = registration.event_id.email_registration_id.id if template_id: @@ -458,94 +291,42 @@ class event_registration(osv.osv): mail_message = self.pool.get('email.template').send_mail(cr,uid,template_id,registration.id) return True - - def onchange_contact_id(self, cr, uid, ids, contact, partner): - - """This function returns value of Badge Name, Badge Title based on Partner contact. - @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 - @param partner: Partner IDS - """ + def onchange_contact_id(self, cr, uid, ids, contact, partner, context=None): data ={} if not contact: return data addr_obj = self.pool.get('res.partner.address') - data['email_from'] = addr_obj.browse(cr, uid, contact).email + data['email_from'] = addr_obj.browse(cr, uid, contact, context).email return {'value': data} - def onchange_event(self, cr, uid, ids, event_id): + def onchange_event(self, cr, uid, ids, event_id, context=None): """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 - @param partner_invoice_id: Partner Invoice ID """ - partner_invoice_id=""; - context = {} + if context is None: + context = {} if not event_id: - return {'value': {'unit_price': False, 'event_product': False}} - + return {} event_obj = self.pool.get('event.event') - prod_obj = self.pool.get('product.product') - res_obj = self.pool.get('res.partner') + data_event = event_obj.browse(cr, uid, event_id, context=context) + return {'value': + {'date': data_event.date_begin, + 'date_deadline': data_event.date_end, + 'section_id': data_event.section_id and data_event.section_id.id or False, + 'company_id': data_event.company_id and data_event.company_id.id or False, + } + } - data_event = event_obj.browse(cr, uid, event_id) - 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, - }} - if data_event.user_id.id: - res['value'].update({'user_id': data_event.user_id.id}) - if data_event.product_id: - 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] - if not unit_price: - unit_price = data_event.unit_price - res['value'].update({'unit_price': unit_price, 'event_product': data_event.product_id.name}) - return res - - def onchange_partner_id(self, cr, uid, ids, part, event_id, email=False): - """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 - """ + def onchange_partner_id(self, cr, uid, ids, part, context=None): res_obj = self.pool.get('res.partner') data = {} - data['contact_id'], data['partner_invoice_id'], data['email_from'] = (False, False, False) if not part: return {'value': data} - data['partner_invoice_id'] = part - # this calls onchange_partner_invoice_id - d = self.onchange_partner_invoice_id(cr, uid, ids, event_id, part) - # this updates the dictionary - data.update(d['value']) addr = res_obj.address_get(cr, uid, [part]).get('default', False) if addr: - d = self.onchange_contact_id(cr, uid, ids, addr, part) + d = self.onchange_contact_id(cr, uid, ids, addr, part, context) data.update(d['value']) return {'value': data} - - event_registration() - - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/event/event_view.xml b/addons/event/event_view.xml index eb12e42ceee..f28081a5730 100644 --- a/addons/event/event_view.xml +++ b/addons/event/event_view.xml @@ -5,7 +5,6 @@ - @@ -39,11 +38,11 @@ event.type form - - + + - - + + @@ -53,8 +52,6 @@ form
- - @@ -65,55 +62,46 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - -