#
##############################################################################
+import time
+
from crm import crm
from osv import fields, osv
from tools.translate import _
-import time
import tools
import decimal_precision as dp
-
class event_type(osv.osv):
""" Event Type """
_name = 'event.type'
_columns = {
'name': fields.char('Event type', size=64, required=True),
}
+
event_type()
class event_event(osv.osv):
'registration_ids': False,
})
return super(event_event, self).copy(cr, uid, id, default=default, context=context)
- def onchange_product(self, cr, uid, ids, product_id):
+
+ 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 context: A standard dictionary for contextual values
@return: True
"""
- if not context:
- context = {}
res = False
if type(ids) in (int, long,):
ids = [ids]
+ if context is None:
+ context = {}
data_pool = self.pool.get('ir.model.data')
unconfirmed_ids = []
for event in self.browse(cr, uid, ids, context=context):
else:
unconfirmed_ids.append(event.id)
if unconfirmed_ids:
- view_id = data_pool._get_id(cr, uid, 'event', 'view_event_confirm')
- view_data = data_pool.browse(cr, uid, view_id, context=context)
- view_id = view_data.res_id
+ 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'),
}
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
if reg_ids:
cr.execute('SELECT SUM(nb_register) FROM event_registration WHERE id IN %s', (tuple(reg_ids),))
number = cr.fetchone()
+
if 'register_current' in fields:
- res[event.id]['register_current'] = len(reg_ids)
+ res[event.id]['register_current'] = number and number[0] or 0.0
if 'register_prospect' in fields:
- res[event.id]['register_prospect'] = len(reg_ids)
-
+ res[event.id]['register_prospect'] = number and number[0] or 0.0
return res
def write(self, cr, uid, ids, vals, context=None):
'register_current': fields.function(_get_register, method=True, string='Confirmed Registrations', multi='register_current',
help="Total of Open and Done Registrations"),
'register_prospect': fields.function(_get_register, method=True, string='Unconfirmed Registrations', multi='register_prospect',
- help="Total of Prospect Registrations"),
+ help="Total of Prospect Registrati./event/event.py:41:ons"),
'registration_ids': fields.one2many('event.registration', 'event_id', 'Registrations', readonly=False, states={'done': [('readonly', True)]}),
'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)]}),
'user_id': lambda obj, cr, uid, context: uid,
}
- def _check_recursion(self, cr, uid, ids):
+ def _check_recursion(self, cr, uid, ids, context=None):
"""
Checks for recursion level for event
"""
level = 100
-
while len(ids):
cr.execute('SELECT DISTINCT parent_id FROM event_event WHERE id IN %s', (tuple(ids),))
ids = filter(None, map(lambda x: x[0], cr.fetchall()))
if not level:
return False
level -= 1
+ return True
+ 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:
+ return False
return True
_constraints = [
- (_check_recursion, 'Error ! You cannot create recursive event.', ['parent_id'])
+ (_check_recursion, 'Error ! You cannot create recursive event.', ['parent_id']),
+ (_check_closing_date, 'Error ! Closing Date cannot be set before Beginning Date.', ['date_end']),
]
def do_team_change(self, cr, uid, ids, team_id, context=None):
if context is None:
context = {}
team_pool = self.pool.get('crm.case.section')
- team = team_pool.browse(cr, uid, team_id, context=context)
res = {}
+ team = team_pool.browse(cr, uid, team_id, context=context)
if team.reply_to:
res = {'value': {'reply_to': team.reply_to}}
return res
_columns = {
'name': fields.char('Summary', 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"),
+ '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_invoice_id": fields.many2one('res.partner', 'Partner Invoiced', readonly=True, states={'draft': [('readonly', False)]}),
"contact_id": fields.many2one('res.partner.contact', '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, method=True, string='Subtotal', digits_compute=dp.get_precision('Sale Price')),
+ 'price_subtotal': fields.function(_amount_line, method=True, string='Subtotal', digits_compute=dp.get_precision('Sale Price'), store=True),
"badge_ids": fields.one2many('event.registration.badge', 'registration_id', 'Badges', readonly=False, states={'done': [('readonly', True)]}),
"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)]}),
'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),
+ '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('mailgate.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False),('model','=',_name)]),
_defaults = {
'nb_register': 1,
'tobe_invoiced': True,
- 'state': lambda *a: 'draft',
- 'active': lambda *a: 1,
+ 'state': 'draft',
+ 'active': 1,
'user_id': lambda self, cr, uid, ctx: uid,
}
def _make_invoice(self, cr, uid, reg, lines, context=None):
""" Create Invoice from Invoice lines
- @param reg : Model of Event Registration
+ @param reg: Model of Event Registration
@param lines: Ids of Invoice lines
"""
if context is None:
context = {}
inv_pool = self.pool.get('account.invoice')
- inv_lines_pool = self.pool.get('account.invoice.line')
-
val_invoice = inv_pool.onchange_partner_id(cr, uid, [], 'out_invoice', reg.partner_invoice_id.id, False, False)
val_invoice['value'].update({'partner_id': reg.partner_invoice_id.id})
val_invoice['value'].update({
self.history(cr, uid, [reg], _('Invoiced'))
return inv_id
+ 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 action_invoice_create(self, cr, uid, ids, grouped=False, date_inv = False, context=None):
""" Action of Create Invoice """
res = False
inv_pool = self.pool.get('account.invoice')
product_pool = self.pool.get('product.product')
contact_pool = self.pool.get('res.partner.contact')
- if not context:
+ if context is None:
context = {}
# 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
context['date_inv'] = date_inv
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)
-
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."))
product = product_pool.browse(cr, uid, reg.event_id.product_id.id, context=context)
for tax in product.taxes_id:
tax_ids.append(tax.id)
-
vals = value['value']
c_name = reg.contact_id and ('-' + contact_pool.name_get(cr, uid, [reg.contact_id.id])[0][1]) or ''
vals.update({
})
inv_line_ids = self._create_invoice_lines(cr, uid, [reg.id], vals)
invoices.setdefault(reg.partner_id.id, []).append((reg, inv_line_ids))
-
for val in invoices.values():
res = False
if grouped:
- res = self._make_invoice(cr, uid, val[0][0], [v for k , v in val], context=context)
+ res = self._make_invoice(cr, uid, val[0][0], [v for k, v in val], context=context)
- for k , v in val:
+ for k, v in val:
self.do_close(cr, uid, [k.id], context={'invoice_id': res})
else:
- for k , v in val:
+ for k, v in val:
res = self._make_invoice(cr, uid, k, [v], context=context)
self.do_close(cr, uid, [k.id], context={'invoice_id': res})
if res: new_invoice_ids.append(res)
-
return new_invoice_ids
def do_open(self, cr, uid, ids, context=None):
def do_close(self, cr, uid, ids, context=None):
""" Close Registration
"""
- if not context:
+ 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')}
@param context: A standard dictionary for contextual values
@return: True
"""
- if not context:
- context = {}
+ 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:
else:
unconfirmed_ids.append(registration.id)
if unconfirmed_ids:
- view_id = data_pool._get_id(cr, uid, 'event', 'view_event_confirm_registration')
- view_data = data_pool.browse(cr, uid, view_id, context=context)
- view_id = view_data.res_id
+ 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'),
def button_reg_close(self, cr, uid, ids, context=None):
"""This Function Close Event Registration.
"""
- if not context:
- context = {}
data_pool = self.pool.get('ir.model.data')
unclosed_ids = []
+ if context is None:
+ context = {}
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:
self.do_close(cr, uid, [registration.id], context=context)
if unclosed_ids:
- view_id = data_pool._get_id(cr, uid, 'event', 'view_event_make_invoice')
- view_data = data_pool.browse(cr, uid, view_id, context=context)
- view_id = view_data.res_id
+ view_id = data_pool.get_object_reference(cr, uid, 'event', 'view_event_make_invoice')
+ view_id = view_id and view_id[1] or False
context['active_ids'] = unclosed_ids
return {
'name': _('Close Registration'),
"""
registrations = self.browse(cr, uid, ids)
self.history(cr, uid, registrations, _('Cancel'))
- self.write(cr, uid, ids, {'state': 'cancel'})
- return True
+ return self.write(cr, uid, ids, {'state': 'cancel'})
def mail_user(self, cr, uid, ids, confirm=False, context=None):
"""
Send email to user
"""
- if not context:
- context = {}
for regestration in self.browse(cr, uid, ids, context=context):
src = regestration.event_id.reply_to or False
subject = _('Auto Confirmation: [%s] %s') %(regestration.id, regestration.name)
body = regestration.event_id.mail_confirm
if subject or body:
- tools.email_send(src, email_to, subject, body, email_cc = email_cc, openobject_id = regestration.id)
+ tools.email_send(src, email_to, subject, body, email_cc=email_cc, openobject_id=regestration.id)
self.history(cr, uid, [regestration], subject, history = True, \
- email = email_to, details = body, \
- subject = subject, email_from = src, \
- email_cc = ', '.join(email_cc))
+ email=email_to, details=body, \
+ subjec=subject, email_from=src, \
+ email_cc=', '.join(email_cc))
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.
+ """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,
data ={}
if not contact:
return data
- contact_obj = self.pool.get('res.partner.contact')
addr_obj = self.pool.get('res.partner.address')
job_obj = self.pool.get('res.partner.job')
@param event_id: Event ID
@param partner_invoice_id: Partner Invoice ID
"""
- context={}
+ context = {}
if not event_id:
return {'value': {'unit_price': False, 'event_product': False}}
data['contact_id'] = job_obj.browse(cr, uid, job_ids[0]).contact_id.id
d = self.onchange_contact_id(cr, uid, ids, data['contact_id'], part)
data.update(d['value'])
- partner_data = res_obj.browse(cr, uid, part)
return {'value': data}
def onchange_partner_invoice_id(self, cr, uid, ids, event_id, partner_invoice_id):
_name = 'event.registration.badge'
_description = __doc__
_columns = {
- 'registration_id': fields.many2one('event.registration', 'Registration', required=True),
+ "registration_id": fields.many2one('event.registration', 'Registration', required=True),
"title": fields.char('Title', size=128),
"name": fields.char('Name', size=128, required=True),
"address_id": fields.many2one('res.partner.address', 'Address'),
}
-event_registration_badge()
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+event_registration_badge()
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file