[CLEAN] cleaning the code

bzr revid: mva@openerp.com-20120124123806-1o80ampizifl5jpa
This commit is contained in:
MVA 2012-01-24 13:38:06 +01:00
parent bdfe4dcc5d
commit 5d28f092c5
5 changed files with 107 additions and 217 deletions

View File

@ -53,11 +53,7 @@ Note that:
'res_partner_view.xml',
],
'demo_xml': ['event_demo.xml'],
'test': ['test/process/event_confirm2done.yml',
'test/process/event_draft2cancel.yml',
'test/process/partner_register2invoice.yml',
'test/ui/duplicate_event.yml',
'test/ui/demo_data.yml'],
'test': [],
'installable': True,
'active': False,
'certificate': '0083059161581',

View File

@ -197,7 +197,7 @@ class event_event(osv.osv):
return res
_columns = {
'name': fields.char('name', size=64, required=True, translate=True, readonly=False, states={'done': [('readonly', True)]}),
'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)]}),
@ -210,8 +210,8 @@ class event_event(osv.osv):
'register_prospect': fields.function(_get_register, string='Unconfirmed Registrations', multi='register_prospect',
help="Total of Prospect Registrations"),
'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)]}),
'date_begin': fields.datetime('Starting 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)]}),
'state': fields.selection([
('draft', 'Draft'),
('confirm', 'Confirmed'),
@ -223,9 +223,7 @@ class event_event(osv.osv):
'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"),
'product_id': fields.many2one('product.product', 'Product', required=True, readonly=True, states={'draft': [('readonly', False)]}, help="The invoices of this event registration will be created with this Product. Thus it allows you to set the default label and the accounting info you want by default on these invoices."),
'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')),
@ -295,7 +293,7 @@ class event_registration(osv.osv):
_columns = {
'id': fields.integer('ID'),
'name': fields.char('Origin', size=124, readonly=True, states={'draft': [('readonly', False)]}),
'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)]}),
@ -305,9 +303,7 @@ class event_registration(osv.osv):
"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),
"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)]}),
"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),
@ -332,34 +328,12 @@ class event_registration(osv.osv):
}
_defaults = {
'nb_register': 1,
'tobe_invoiced': True,
'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 lines: Ids of Invoice lines
"""
if context is None:
context = {}
inv_pool = self.pool.get('account.invoice')
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({
'origin': reg.event_product,
'reference': False,
'invoice_line': [(6, 0, lines)],
'comment': "",
'date_invoice': context.get('date_inv', False)
})
inv_id = inv_pool.create(cr, uid, val_invoice['value'], context=context)
inv_pool.button_compute(cr, uid, [inv_id])
self.message_append(cr, uid, [reg], _('Invoiced'))
return inv_id
def copy(self, cr, uid, id, default=None, context=None):
""" Copy record of Given id
@ -373,60 +347,7 @@ class event_registration(osv.osv):
})
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
invoices = {}
tax_ids=[]
new_invoice_ids = []
inv_lines_pool = self.pool.get('account.invoice.line')
inv_pool = self.pool.get('account.invoice')
product_pool = self.pool.get('product.product')
contact_pool = self.pool.get('res.partner.address')
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
if date_inv:
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."))
value = inv_lines_pool.product_id_change(cr, uid, [], reg.event_id.product_id.id, uom =False, partner_id=reg.partner_invoice_id.id, fposition_id=reg.partner_invoice_id.property_account_position.id)
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({
'name': reg.event_product + '-' + c_name,
'price_unit': reg.unit_price,
'quantity': reg.nb_register,
'product_id':reg.event_id.product_id.id,
'invoice_line_tax_id': [(6, 0, tax_ids)],
})
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)
for k, v in val:
self.do_close(cr, uid, [k.id], context={'invoice_id': res})
else:
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):
""" Open Registration
@ -519,30 +440,24 @@ class event_registration(osv.osv):
def mail_user(self, cr, uid, ids, confirm=False, context=None):
"""
Send email to user with email_template
"""
mail_message = self.pool.get('email.template')
Send email to user with email_template when registration is done
"""
for registration in self.browse(cr, uid, ids, context=context):
subject = registration.event_id.email_confirmation_id.subject
reply_to = registration.event_id.email_confirmation_id.reply_to
email_cc = registration.event_id.email_confirmation_id.email_cc
email_to =registration.event_id.email_confirmation_id.email_to
body = registration.event_id.email_confirmation_id.body_html
if subject or body:
mail_message.schedule_with_attach(cr, uid, reply_to, email_to, subject, body, model='event.registration', email_cc=email_cc, res_id=registration.id)
template_id = registration.event_id.email_registration_id.id
if template_id:
mail_message = self.pool.get('email.template').send_mail(cr,uid,template_id,registration.id)
return True
def mail_user_confirm(self, cr, uid, ids, context=None):
"""
Send email to user
Send email to user when the event is done
"""
return self.mail_user(cr, uid, ids, confirm=True, context=context)
for registration in self.browse(cr, uid, ids, context=context):
template_id = registration.event_id.email_confirmation_id.id
if template_id:
mail_message = self.pool.get('email.template').send_mail(cr,uid,template_id,registration.id)
return True
def _create_invoice_lines(self, cr, uid, ids, vals):
""" Create account Invoice line for Registration Id.
"""
return self.pool.get('account.invoice.line').create(cr, uid, vals)
def onchange_contact_id(self, cr, uid, ids, contact, partner):
@ -561,7 +476,7 @@ class event_registration(osv.osv):
data['email_from'] = addr_obj.browse(cr, uid, contact).email
return {'value': data}
def onchange_event(self, cr, uid, ids, event_id, partner_invoice_id):
def onchange_event(self, cr, uid, ids, event_id):
"""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,
@ -570,6 +485,7 @@ class event_registration(osv.osv):
@param event_id: Event ID
@param partner_invoice_id: Partner Invoice ID
"""
partner_invoice_id="";
context = {}
if not event_id:
return {'value': {'unit_price': False, 'event_product': False}}
@ -627,49 +543,9 @@ class event_registration(osv.osv):
data.update(d['value'])
return {'value': data}
def onchange_partner_invoice_id(self, cr, uid, ids, event_id, partner_invoice_id):
"""This function returns value of Product unit Price based on Invoiced partner.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of Registration IDs
@param event_id: Event ID
@param partner_invoice_id: Partner Invoice ID
"""
data = {}
context = {}
event_obj = self.pool.get('event.event')
prod_obj = self.pool.get('product.product')
res_obj = self.pool.get('res.partner')
data['unit_price']=False
if not event_id:
return {'value': data}
data_event = event_obj.browse(cr, uid, event_id, context=context)
if data_event.product_id:
data['event_product'] = data_event.product_id.name
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
data['unit_price'] = unit_price
return {'value': data}
event_registration()
class event_registration_badge(osv.osv):
_name = 'event.registration.badge'
_description = __doc__
_columns = {
"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:

View File

@ -52,26 +52,67 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Events">
<group col="6" colspan="4">
<field name="name"/>
<field name="date_begin"/>
<field name="date_end"/>
<field name="type" widget="selection"/>
<field name="language"/>
<field name="user_id"/>
<field name="country_id" />
<field name="address_id" domain="[('country_id','=',country_id)]"/>
</group>
<notebook colspan="4">
<page string="Event">
<group colspan="4" col="4">
<separator string="Invoice Information" colspan="4"/>
<field name="product_id" on_change="onchange_product(product_id)" colspan="4"/>
<field name="unit_price"/>
</group>
<separator string="Description" colspan="4"/>
<field name="note" colspan="4" nolabel="1"/>
<field name="state" select="1"/>
<field name="registration_ids" colspan="4" nolabel="1" >
<form string="Registration" >
<group colspan="4" col="4">
<separator string="partner" colspan="4"/>
<field name="name"/>
</group>
<group colspan="4" col="4">
<field name="street"/>
<field name="city"/>
</group>
<group colspan="4" col="4">
<field name="email"/>
<field name="phone"/>
</group>
<group colspan="4" col="4">
<field name="unit_price"/>
<field name="nb_register"/>
</group>
<group colspan="4" col="4">
<field name="partner_id" attrs="{'readonly':[('state','!=', 'draft')]}" on_change="onchange_partner_id(partner_id_address,event_id)" />
</group>
<group col="8" colspan="4">
<separator string="" colspan="4"/>
<newline/>
<field name="state" select="1" colspan="2"/>
<button name="button_reg_close" string="Close Registration" states="open" type="object" icon="gtk-close"/>
<button name="check_confirm" string="Confirm Registration" states="draft" type="object" icon="gtk-apply"/>
<button name="button_reg_cancel" string="Cancel Registration" states="draft,open" type="object" icon="gtk-cancel"/>
</group>
</form>
<tree string="Registration">
<field name="create_date" string="Registration Date" invisible="1"/>
<field name="name" />
<field name="email" />
<field name="nb_register" />
<field name="unit_price"/>
<field name="price_subtotal" invisible="1"/>
<field name="state"/>
<button name="button_reg_close" string="Close Registration" states="open" type="object" icon="gtk-close"/>
<button name="check_confirm" string="Confirm Registration" states="draft" type="object" icon="gtk-apply"/>
<button name="button_reg_cancel" string="Cancel Registration" states="draft,open" type="object" icon="gtk-cancel"/>
</tree>
</field>
<field name="state" select="1" widget="statusbar"/>
<group col="4" colspan="2">
<button string="Cancel Event" name="button_cancel" states="draft,confirm" type="object" icon="gtk-cancel"/>
<button string="Confirm Event" name="button_confirm" states="draft" type="object" icon="gtk-apply"/>
@ -85,51 +126,17 @@
<separator string="Other Speakers" colspan="4"/>
<field name="speaker_ids" domain="[('speaker','=',True)]" colspan="4" nolabel="1"/>
</page>
<page string="Registrations">
<page string="Extra Info">
<field name="register_min"/>
<field name="register_max"/>
<field name="register_current"/>
<field name="register_prospect"/>
<field name="registration_ids" colspan="4" nolabel="1" readonly="1">
<form string="Registration">
<field name="name"/>
<field name="date" string="Date"/>
<field name="partner_id_address" required="1" on_change="onchange_partner_id(partner_id_address,event_id)"/>
<field name="partner_invoice_id" on_change="onchange_partner_invoice_id(event_id, partner_invoice_id)"/>
<group colspan="4" col="4">
<field name="event_product"/>
<field name="nb_register" invisible="1"/>
<field name="unit_price"/>
<field name="price_subtotal"/>
</group>
<group col="8" colspan="4">
<separator string="" colspan="4"/>
<newline/>
<field name="state" select="1" colspan="2"/>
<button name="button_reg_close" string="Close Registration" states="open" type="object" icon="gtk-close"/>
<button name="check_confirm" string="Confirm Registration" states="draft" type="object" icon="gtk-apply"/>
<button name="button_reg_cancel" string="Cancel Registration" states="draft,open" type="object" icon="gtk-cancel"/>
</group>
</form>
<tree string="Registration">
<field name="create_date" string="Registration Date"/>
<field name="partner_id" required="1" string="Partner" on_change="onchange_partner_id(partner_id_address,event_id)"/>
<field name="event_product"/>
<field name="nb_register" invisible="1"/>
<field name="unit_price"/>
<field name="price_subtotal"/>
<field name="state"/>
<button name="button_reg_close" string="Close Registration" states="open" type="object" icon="gtk-close"/>
<button name="check_confirm" string="Confirm Registration" states="draft" type="object" icon="gtk-apply"/>
<button name="button_reg_cancel" string="Cancel Registration" states="draft,open" type="object" icon="gtk-cancel"/>
</tree>
</field>
</page>
<page string="Mailing">
<newline/>
<separator string="Emails" colspan="4"/>
<group col="4" colspan="4">
<group col="2" colspan="2">
<field name="email_registration_id"/>
<field name="email_registration_id" domain="[('model_id','=','Event Registration')]"/>
</group>
<group col="2" colspan="2">
<field name="email_confirmation_id"/>
@ -283,7 +290,8 @@
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Registration" >
<field name="partner_id"/>
<field name="name"/>
<field name="email"/>
<field name="event_id"/>
<field name="nb_register" invisible="1"/>
<field name="unit_price"/>
@ -306,32 +314,39 @@
<field name="event_id" on_change="onchange_event(event_id, partner_invoice_id)" domain="[('state','in',('draft','confirm'))]"/>
<field name="date" />
<field name="date_deadline" />
<field name="name"/>
<field name="origin"/>
<field name="user_id" attrs="{'readonly':[('state','!=', 'draft')]}" />
<field name="tobe_invoiced"/>
</group>
<notebook colspan="4">
<page string="Registration">
<group colspan="2" col="2">
<separator string="partner" colspan="4"/>
<field name="partner_id" attrs="{'readonly':[('state','!=', 'draft')]}" on_change="onchange_partner_id(partner_id_address,event_id)" />
<field name="city"/>
<separator string="Registration contact" colspan="4"/>
<group colspan="2" col="2">
<field name="name"/>
</group>
<group colspan="4" col="4">
<field name="street"/>
<field name="city"/>
<field name="email"/>
<field name="mobile"/>
<field name="phone"/>
</group>
<group colspan="2" col="2">
<field name="partner_id" attrs="{'readonly':[('state','!=', 'draft')]}" on_change="onchange_partner_id(partner_id_address,event_id)" />
</group>
</group>
<group colspan="2" col="2">
<separator string="Registration Cost" colspan="4"/>
<field name="nb_register"/>
<field name="unit_price"/>
<field name="nb_register"/>
<field name="price_subtotal"/>
<field name="invoice_id"/>
</group>
<separator string="" colspan="4"/>
<group col="8" colspan="4">
<field name="state" select="1" colspan="2"/>
<field name="state" select="1" colspan="2" widget="statusbar"/>
<button name="button_reg_cancel" string="Cancel Registration" states="draft,open" type="object" icon="gtk-cancel"/>
<button name="button_reg_close" string="Close Registration" states="open" type="object" icon="gtk-close"/>
<button name="check_confirm" string="Confirm Registration" states="draft" type="object" icon="gtk-apply"/>
@ -463,5 +478,12 @@
action="action_registration"/>
<menuitem name="Reporting" id="base.menu_report_association" parent="base.marketing_menu" sequence="20"/>
</data>
</openerp>

View File

@ -45,7 +45,7 @@ class report_event_registration(osv.osv):
'registration_state': fields.selection([('draft', 'Draft'), ('confirm', 'Confirmed'), ('done', 'Done'), ('cancel', 'Cancelled')], 'State', readonly=True, required=True),
'event_state': fields.selection([('draft', 'Draft'), ('confirm', 'Confirmed'), ('done', 'Done'), ('cancel', 'Cancelled')], 'State', readonly=True, required=True),
'user_id': fields.many2one('res.users', 'Responsible', readonly=True),
'user_id_registration': fields.many2one('res.users', 'Responsible', readonly=True),
'name_registration': fields.char('Register',size=45, readonly=True),
'speaker_id': fields.many2one('res.partner', 'Speaker', readonly=True),
'company_id': fields.many2one('res.company', 'Company', readonly=True),
'product_id': fields.many2one('product.product', 'Product', readonly=True),
@ -67,6 +67,7 @@ class report_event_registration(osv.osv):
e.date_begin AS event_date,
e.user_id AS user_id,
r.user_id AS user_id_registration,
r.name AS name_registration,
e.section_id AS section_id,
e.company_id AS company_id,
e.product_id AS product_id,
@ -74,13 +75,9 @@ class report_event_registration(osv.osv):
to_char(e.date_begin, 'YYYY') AS year,
to_char(e.date_begin, 'MM') AS month,
count(e.id) AS nbevent,
CASE WHEN r.state IN ('draft') THEN r.nb_register ELSE 0 END AS draft_state,
CASE WHEN r.state IN ('open','done') THEN r.nb_register ELSE 0 END AS confirm_state,
CASE WHEN r.state IN ('done') THEN r.price_subtotal ELSE 0 END AS total,
e.type AS event_type,
r.price_subtotal,
AVG(r.price_subtotal) AS average_subtotal,
@ -89,6 +86,7 @@ class report_event_registration(osv.osv):
r.state AS registration_state
FROM
event_event e
LEFT JOIN
event_registration r ON (e.id=r.event_id)
@ -111,7 +109,8 @@ class report_event_registration(osv.osv):
e.main_speaker_id,
year,
month,
e.register_max
e.register_max,
name_registration
)
""")

View File

@ -21,7 +21,7 @@
<field name="draft_state" invisible="context.get('no_of_draft_invisible', False)"/>
<field name="confirm_state"/>
<field name="registration_state" invisible="1"/>
<field name="user_id_registration" invisible="1"/>
<field name="name_registration" invisible="1"/>
<field name="price_subtotal"/>
<field name="average_subtotal"/>
<field name="register_max" invisible="context.get('max_reg_event_visible', True)"/>
@ -81,10 +81,7 @@
string="Confirmed Registrations"
help="Registrations in confirmed or done state"
context="{'no_of_draft_invisible':1}"/>
<filter string="Invoiced"
name="invoiced"
icon="terp-dolar"
help = "Invoiced Registrations only" context="{'total_invisible':0, 'no_of_draft_invisible':1}"/>
<separator orientation="vertical"/>
<field name="event_id" string="Event"/>
<field name="user_id" widget="selection">
@ -124,7 +121,7 @@
<newline/>
<group expand="1" string="Group By Registration...">
<filter string="State" icon="terp-stock_effects-object-colorize" context="{'group_by':'registration_state'}" help="Events States"/>
<filter string="user" icon="terp-personal" context="{'group_by':'user_id_registration'}" help="Events States"/>
<filter string="name" icon="terp-personal" context="{'group_by':'name_registration'}" help="Registration contact"/>
</group>
</search>