From ab3047a80a3490917c94efe67c5fc59ee74a3844 Mon Sep 17 00:00:00 2001 From: "atp (Open ERP)" Date: Wed, 30 Jun 2010 19:51:59 +0530 Subject: [PATCH] [IMP]: event: Add currency field.Improve registration view. bzr revid: atp@tinyerp.co.in-20100630142159-7vxbjdhqa5doya13 --- addons/event/__openerp__.py | 1 + addons/event/event.py | 49 ++++++-- addons/event/event_view.xml | 207 ++++++++++++++++++++----------- addons/event/test/test_event.yml | 13 +- addons/event/wizard/__init__.py | 1 + 5 files changed, 174 insertions(+), 97 deletions(-) diff --git a/addons/event/__openerp__.py b/addons/event/__openerp__.py index c1f61bcff8f..7cd7d4ae2c6 100644 --- a/addons/event/__openerp__.py +++ b/addons/event/__openerp__.py @@ -51,6 +51,7 @@ 'security/event_security.xml', 'security/ir.model.access.csv', 'wizard/event_make_invoice_view.xml', + 'wizard/partner_event_registration_view.xml', 'board_association_view.xml', ], 'demo_xml': ['event_demo.xml', 'board_association_demo.xml'], diff --git a/addons/event/event.py b/addons/event/event.py index 6a02e44fa89..b6af6d4f6ed 100644 --- a/addons/event/event.py +++ b/addons/event/event.py @@ -35,7 +35,6 @@ class event_type(osv.osv): _columns = { 'name': fields.char('Event type', size=64, required=True), } - event_type() class event_event(osv.osv): @@ -44,7 +43,14 @@ class event_event(osv.osv): _description = __doc__ _inherit = 'crm.case.section' _order = 'date_begin' - + + def _get_currency(self, cr, uid, context): + user = self.pool.get('res.users').browse(cr, uid, [uid])[0] + if user.company_id: + return user.company_id.currency_id.id + else: + return self.pool.get('res.currency').search(cr, uid, [('rate','=',1.0)])[0] + def copy(self, cr, uid, id, default=None, context=None): """ Copy record of Given id @param id: Id of Event Registration type record. @@ -57,6 +63,14 @@ class event_event(osv.osv): 'state': 'draft' }) return super(event_event, self).copy(cr, uid, id, default=default, context=context) + + def onchange_product(self, cr, uid, ids, product_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) @@ -88,6 +102,7 @@ class event_event(osv.osv): @param context: A standard dictionary for contextual values @return: Dictionary of function fields value. """ + register_pool = self.pool.get('event.registration') res = {} for event in self.browse(cr, uid, ids, context): @@ -103,11 +118,11 @@ class event_event(osv.osv): reg_ids = register_pool.search(cr, uid, [ ('event_id', '=', event.id), ('state', 'in', state)]) + if 'register_current' in fields: res[event.id]['register_current'] = len(reg_ids) if 'register_prospect' in fields: res[event.id]['register_prospect'] = len(reg_ids) - return res @@ -142,6 +157,7 @@ class event_event(osv.osv): register_pool.write(cr, uid, reg_ids, register_values) return res + _columns = { 'type': fields.many2one('event.type', 'Type', help="Type of Event like Seminar, Exhibition, Conference, Training."), 'register_max': fields.integer('Maximum Registrations', help="Provide Maximun Number of Registrations"), @@ -157,15 +173,20 @@ class event_event(osv.osv): 'mail_registr': fields.text('Registration Email', help='This email will be sent when someone subscribes to the event.'), 'mail_confirm': fields.text('Confirmation Email', help="This email will be sent when the event gets confimed or when someone subscribes to a confirmed event. This is also the email sent to remind someone about the event."), 'product_id': fields.many2one('product.product', 'Product', required=True, help="Product which is provided cost of event. Invoice of event will be created with this Product."), - 'note': fields.text('Notes', help="Description or Summary of Event") + 'note': fields.text('Notes', help="Description or Summary of Event"), + 'currency_id': fields.many2one('res.currency', 'Currency', required=True, readonly=True, states={'draft':[('readonly',False)]}), + "unit_price": fields.float('Cost'), + } _defaults = { 'state': 'draft', - 'code': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'event.event'), + # 'code': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'event.event'), 'user_id': lambda obj, cr, uid, context: uid, + 'currency_id': _get_currency, } + event_event() class event_registration(osv.osv): @@ -192,13 +213,16 @@ and users by email"), "invoice_id": fields.many2one("account.invoice", "Invoice"), 'date_closed': fields.datetime('Closed', readonly=True), 'ref': fields.reference('Reference', selection=crm._links_get, size=128), - 'ref2': fields.reference('Reference 2', selection=crm._links_get, size=128), + 'ref2': fields.reference('Reference 2', selection=crm._links_get, size=128), + 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('history', '=', True),('model','=',_name)]), + 'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False),('model','=',_name)]), + 'currency_id': fields.many2one('res.currency', 'Currency', readonly=True), } - _defaults = { 'nb_register': 1, 'tobe_invoiced': True, 'name': 'Registration', + # 'currency_id': _get_currency, } def _make_invoice(self, cr, uid, reg, lines, context=None): @@ -302,7 +326,7 @@ and users by email"), if total_confirmed <= registration.event_id.register_max or registration.event_id.register_max == 0: self.write(cr, uid, [registration.id], {'state': 'open'}, context=context) self.mail_user(cr, uid, [registration.id]) - self._history(cr, uid, [registration.id], _('Open')) + self._history(cr, uid, [registration], _('Open')) else: unconfirmed_ids.append(registration.id) if unconfirmed_ids: @@ -343,6 +367,7 @@ and users by email"), values['date_deadline']= event.date_begin values['description']= event.mail_confirm + values['currency_id'] = event.currency_id.id res = super(event_registration, self).create(cr, uid, values, context=context) registrations = self.browse(cr, uid, [res], context=context) self._history(cr, uid, registrations, _('Created')) @@ -354,7 +379,6 @@ and users by email"), values['date_deadline']= event.date_begin values['description']= event.mail_confirm return super(event_registration, self).write(cr, uid, ids, values, context=context) - def mail_user(self, cr, uid, ids, confirm=False, context=None): """ @@ -434,14 +458,16 @@ and users by email"), return {'value': {'unit_price': False, 'event_product': False}} data_event = self.pool.get('event.event').browse(cr, uid, event_id) + context['currency_id'] = data_event.currency_id.id + if data_event.product_id: if not partner_invoice_id: unit_price=self.pool.get('product.product').price_get(cr, uid, [data_event.product_id.id], context=context)[data_event.product_id.id] - return {'value': {'unit_price': unit_price, 'event_product': data_event.product_id.name}} + return {'value': {'unit_price': unit_price, 'event_product': data_event.product_id.name, 'currency_id': data_event.currency_id.id}} data_partner = self.pool.get('res.partner').browse(cr, uid, partner_invoice_id) context.update({'partner_id': data_partner}) unit_price = self.pool.get('product.product')._product_price(cr, uid, [data_event.product_id.id], False, False, {'pricelist': data_partner.property_product_pricelist.id})[data_event.product_id.id] - return {'value': {'unit_price': unit_price, 'event_product': data_event.product_id.name}} + return {'value': {'unit_price': unit_price, 'event_product': data_event.product_id.name, 'currency_id': data_event.currency_id.id}} return {'value': {'unit_price': False, 'event_product': False}} @@ -489,6 +515,5 @@ and users by email"), 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 41c0fef5cfb..3bcc98b18ce 100644 --- a/addons/event/event_view.xml +++ b/addons/event/event_view.xml @@ -51,10 +51,12 @@ - + + + @@ -118,6 +120,33 @@ + + + event.event.calendar + event.event + calendar + + + + + + + + + + + + Event Graph + event.event + graph + + + + + + + + Events @@ -160,7 +189,7 @@ ir.actions.act_window event.event form - tree,form + tree,form,calendar,graph {"search_default_draft": "1"} @@ -170,9 +199,18 @@ name="Registration" res_model="event.registration" src_model="event.event" - view_mode="tree,form" + view_mode="tree,form,calendar,graph" domain="[('event_id', '=', active_id)]" view_type="form"/> + + @@ -203,29 +241,32 @@
+ - - - -