[FIX] base_contact: Review the algo
bzr revid: stw@openerp.com-20111208184328-7wl5oo1exom3w38j
This commit is contained in:
parent
1183a6c3c5
commit
a4ac411066
|
@ -49,7 +49,7 @@ Pay attention that this module converts the existing addresses into "addresses +
|
|||
'security/ir.model.access.csv',
|
||||
'base_contact_view.xml',
|
||||
'base_contact_installer_view.xml',
|
||||
'process/base_contact_process.xml'
|
||||
#'process/base_contact_process.xml'
|
||||
],
|
||||
'demo_xml': ['base_contact_demo.xml'],
|
||||
'test': [
|
||||
|
|
|
@ -28,27 +28,6 @@ class res_partner_contact(osv.osv):
|
|||
_name = "res.partner.contact"
|
||||
_description = "Contact"
|
||||
|
||||
def _main_job(self, cr, uid, ids, fields, arg, context=None):
|
||||
"""
|
||||
@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 partner contact’s IDs
|
||||
@fields: Get Fields
|
||||
@param context: A standard dictionary for contextual values
|
||||
@param arg: list of tuples of form [(‘name_of_the_field’, ‘operator’, value), ...]. """
|
||||
res = dict.fromkeys(ids, False)
|
||||
|
||||
res_partner_job_obj = self.pool.get('res.partner.job')
|
||||
all_job_ids = res_partner_job_obj.search(cr, uid, [])
|
||||
all_job_names = dict(zip(all_job_ids, res_partner_job_obj.name_get(cr, uid, all_job_ids, context=context)))
|
||||
|
||||
for contact in self.browse(cr, uid, ids, context=context):
|
||||
if contact.job_ids:
|
||||
res[contact.id] = all_job_names.get(contact.job_ids[0].id, False)
|
||||
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Last Name', size=64, required=True),
|
||||
'first_name': fields.char('First Name', size=64),
|
||||
|
@ -56,17 +35,15 @@ class res_partner_contact(osv.osv):
|
|||
'title': fields.many2one('res.partner.title','Title'),
|
||||
'website': fields.char('Website', size=120),
|
||||
'lang_id': fields.many2one('res.lang', 'Language'),
|
||||
'job_ids': fields.one2many('res.partner.job', 'contact_id', 'Functions and Addresses'),
|
||||
'job_ids': fields.one2many('res.partner.address', 'contact_id', 'Functions and Addresses'),
|
||||
'country_id': fields.many2one('res.country','Nationality'),
|
||||
'birthdate': fields.date('Birth Date'),
|
||||
'active': fields.boolean('Active', help="If the active field is set to False,\
|
||||
it will allow you to hide the partner contact without removing it."),
|
||||
'partner_id': fields.related('job_ids', 'address_id', 'partner_id', type='many2one',\
|
||||
'partner_id': fields.related('job_ids', 'location_id', 'partner_id', type='many2one',\
|
||||
relation='res.partner', string='Main Employer'),
|
||||
'function': fields.related('job_ids', 'function', type='char', \
|
||||
string='Main Function'),
|
||||
'job_id': fields.function(_main_job, type='many2one',\
|
||||
relation='res.partner.job', string='Main Job'),
|
||||
'email': fields.char('E-Mail', size=240),
|
||||
'comment': fields.text('Notes', translate=True),
|
||||
'photo': fields.binary('Photo'),
|
||||
|
@ -84,7 +61,7 @@ class res_partner_contact(osv.osv):
|
|||
|
||||
_order = "name,first_name"
|
||||
|
||||
def name_get(self, cr, user, ids, context=None):
|
||||
def name_get2(self, cr, user, ids, context=None):
|
||||
|
||||
""" will return name and first_name.......
|
||||
@param self: The object pointer
|
||||
|
@ -122,73 +99,35 @@ class res_partner_contact(osv.osv):
|
|||
|
||||
res_partner_contact()
|
||||
|
||||
|
||||
class res_partner_address(osv.osv):
|
||||
|
||||
#overriding of the name_get defined in base in order to remove the old contact name
|
||||
def name_get(self, cr, user, ids, context=None):
|
||||
"""
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param user: the current user,
|
||||
@param ids: List of partner address’s IDs
|
||||
@param context: A standard dictionary for contextual values
|
||||
"""
|
||||
|
||||
if not len(ids):
|
||||
return []
|
||||
res = []
|
||||
if context is None:
|
||||
context = {}
|
||||
for r in self.read(cr, user, ids, ['zip', 'city', 'partner_id', 'street']):
|
||||
if context.get('contact_display', 'contact')=='partner' and r['partner_id']:
|
||||
res.append((r['id'], r['partner_id'][1]))
|
||||
else:
|
||||
addr = str('')
|
||||
addr += "%s %s %s" % (r.get('street', '') or '', r.get('zip', '') \
|
||||
or '', r.get('city', '') or '')
|
||||
res.append((r['id'], addr.strip() or '/'))
|
||||
return res
|
||||
|
||||
def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=100):
|
||||
if not args:
|
||||
args=[]
|
||||
ids = self.search(cr, user, [('name',operator,name)] + args, limit=limit, context=context)
|
||||
jobs = self.pool.get('res.partner.job')
|
||||
if name:
|
||||
job_ids = jobs.search(cr, user, [('contact_id', operator, name)] + args, limit=limit, context=context)
|
||||
for job in jobs.browse(cr, user, job_ids):
|
||||
ids += [job.address_id.id]
|
||||
return self.name_get(cr, user, ids, context)
|
||||
|
||||
_name = 'res.partner.address'
|
||||
_inherit = 'res.partner.address'
|
||||
_description ='Partner Address'
|
||||
class res_partner(osv.osv):
|
||||
_inherit = 'res.partner'
|
||||
|
||||
_columns = {
|
||||
'job_id': fields.related('job_ids','contact_id','job_id',type='many2one',\
|
||||
relation='res.partner.job', string='Main Job'),
|
||||
'job_ids': fields.one2many('res.partner.job', 'address_id', 'Contacts'),
|
||||
'address': fields.one2many('res.partner.location', 'partner_id', 'Address')
|
||||
}
|
||||
res_partner_address()
|
||||
|
||||
res_partner()
|
||||
|
||||
class res_partner_location(osv.osv):
|
||||
_name = 'res.partner.location'
|
||||
_inherit = 'res.partner.address'
|
||||
_table = 'res_partner_address'
|
||||
|
||||
#_table = 'res_partner_address'
|
||||
_columns = {
|
||||
'job_ids': fields.one2many('res.partner.address', 'location_id', 'Contacts'),
|
||||
}
|
||||
res_partner_location()
|
||||
|
||||
class res_partner_address(osv.osv):
|
||||
_name = 'res.partner.address'
|
||||
_inherits = { 'res.partner.location' : 'address_id' }
|
||||
_inherits = { 'res.partner.location' : 'location_id' }
|
||||
_table = 'res_partner_job'
|
||||
|
||||
_columns = {
|
||||
'address_id' : fields.many2one('res.partner.location', 'Location'),
|
||||
'location_id' : fields.many2one('res.partner.location', 'Location'),
|
||||
'contact_id' : fields.many2one('res.partner.contact', 'Contact'),
|
||||
|
||||
'contact_firstname' : fields.related('contact_id', 'first_name', type='char', size=64, string='FirstName'),
|
||||
'contact_name' : fields.related('contact_id', 'name', type='char', size='64', string="LastName"),
|
||||
'name' : fields.related('contact_id', 'name', type='char', size='64', string="LastName"),
|
||||
'function': fields.char('Partner Function', size=64, help="Function of this contact with this partner"),
|
||||
'date_start': fields.date('Date Start',help="Start date of job(Joining Date)"),
|
||||
'date_stop': fields.date('Date Stop', help="Last date of job"),
|
||||
|
@ -202,68 +141,7 @@ class res_partner_address(osv.osv):
|
|||
'state': 'current',
|
||||
}
|
||||
|
||||
def name_get(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param user: the current user,
|
||||
@param ids: List of partner address’s IDs
|
||||
@param context: A standard dictionary for contextual values
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
if not ids:
|
||||
return []
|
||||
res = []
|
||||
|
||||
jobs = self.browse(cr, uid, ids, context=context)
|
||||
|
||||
contact_ids = [rec.contact_id.id for rec in jobs if rec.contact_id]
|
||||
contact_names = dict(self.pool.get('res.partner.contact').name_get(cr, uid, contact_ids, context=context))
|
||||
|
||||
for r in jobs:
|
||||
function_name = r.function
|
||||
funct = function_name and (", " + function_name) or ""
|
||||
res.append((r.id, contact_names.get(r.contact_id.id, '') + funct))
|
||||
|
||||
return res
|
||||
|
||||
def onchange_name(self, cr, uid, ids, address_id='', name='', context=None):
|
||||
return {'value': {'address_id': address_id}, 'domain':{'partner_id':'name'}}
|
||||
|
||||
def onchange_partner(self, cr, uid, _, partner_id, context=None):
|
||||
"""
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user,
|
||||
@param _: List of IDs,
|
||||
@partner_id : ID of the Partner selected,
|
||||
@param context: A standard dictionary for contextual values
|
||||
"""
|
||||
return {'value': {'address_id': False}}
|
||||
|
||||
def onchange_address(self, cr, uid, _, address_id, context=None):
|
||||
"""
|
||||
@@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user,
|
||||
@param _: List of IDs,
|
||||
@address_id : ID of the Address selected,
|
||||
@param context: A standard dictionary for contextual values
|
||||
"""
|
||||
partner_id = False
|
||||
if address_id:
|
||||
address = self.pool.get('res.partner.address')\
|
||||
.browse(cr, uid, address_id, context=context)
|
||||
partner_id = address.partner_id.id
|
||||
return {'value': {'name': partner_id}}
|
||||
res_partner_address()
|
||||
|
||||
class res_partner_job(osv.osv):
|
||||
_name = 'res.partner.job'
|
||||
_inherit = 'res.partner.address'
|
||||
|
||||
res_partner_job()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -168,6 +168,7 @@
|
|||
</record>
|
||||
|
||||
<!-- Create the jobs -->
|
||||
<!--
|
||||
<record id="res_partner_job_0" model="res.partner.job">
|
||||
<field name="address_id" ref="base.res_partner_address_1"/>
|
||||
<field name="function">Salesman</field>
|
||||
|
@ -322,5 +323,6 @@
|
|||
<field name="function">CEO</field>
|
||||
<field name="sequence_contact">1</field>
|
||||
</record>
|
||||
-->
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -165,7 +165,7 @@
|
|||
<field name="fax"/>
|
||||
<field name="email" widget="email"/>
|
||||
</group>
|
||||
<field name="job_ids" mode="tree,form" nolabel="1" colspan="4">
|
||||
<field name="job_ids" mode="tree,form" nolabel="1" colspan="4" context="{'default_is_job' : True}" default_get="{'is_job' : True}">
|
||||
<tree string="Contacts" editable="top">
|
||||
<field name="contact_id"/>
|
||||
<field name="function"/>
|
||||
|
@ -174,16 +174,16 @@
|
|||
<field name="email"/>
|
||||
</tree>
|
||||
<form string="Contacts">
|
||||
<group colspan="4" col="4">
|
||||
<field name="contact_id"/>
|
||||
<field name="function"/>
|
||||
</group>
|
||||
<separator string="Communication" colspan="4"/>
|
||||
<group colspan="4" col="4">
|
||||
<field name="phone"/>
|
||||
<field name="fax"/>
|
||||
<field name="email" widget="email"/>
|
||||
</group>
|
||||
<group colspan="4" col="4">
|
||||
<field name="contact_id"/>
|
||||
<field name="function"/>
|
||||
</group>
|
||||
<separator string="Communication" colspan="4"/>
|
||||
<group colspan="4" col="4">
|
||||
<field name="phone"/>
|
||||
<field name="fax"/>
|
||||
<field name="email" widget="email"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</form>
|
||||
|
@ -298,6 +298,7 @@
|
|||
|
||||
<!-- Views for partner job Tree view -->
|
||||
|
||||
<!--
|
||||
<record model="ir.ui.view" id="view_partner_job_tree">
|
||||
<field name="name">res.partner.job.tree</field>
|
||||
<field name="model">res.partner.job</field>
|
||||
|
@ -315,9 +316,11 @@
|
|||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
-->
|
||||
|
||||
<!-- Views for partner job Form view -->
|
||||
|
||||
<!--
|
||||
<record model="ir.ui.view" id="view_partner_job_form">
|
||||
<field name="name">res.partner.job.form</field>
|
||||
<field name="model">res.partner.job</field>
|
||||
|
@ -337,9 +340,11 @@
|
|||
</form>
|
||||
</field>
|
||||
</record>
|
||||
-->
|
||||
|
||||
<!-- Menuitem for res.partner.job -->
|
||||
|
||||
<!--
|
||||
<record model="ir.actions.act_window" id="action_res_partner_job">
|
||||
<field name="name">Contact's Jobs</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
|
@ -352,9 +357,11 @@
|
|||
res_model="res.partner.job"
|
||||
src_model="res.partner"
|
||||
/>
|
||||
-->
|
||||
|
||||
<!-- Act window defining a shorcut on partner address to open all his jobs -->
|
||||
|
||||
<!--
|
||||
<act_window
|
||||
id="act_res_partner_jobs"
|
||||
name="Open Jobs"
|
||||
|
@ -362,6 +369,7 @@
|
|||
res_model="res.partner.job"
|
||||
src_model="res.partner.address"
|
||||
/>
|
||||
-->
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -36,15 +36,6 @@
|
|||
<field eval="1" name="flow_start"/>
|
||||
</record>
|
||||
|
||||
<record id="process_node_function0" model="process.node">
|
||||
<field name="model_id" ref="base_contact.model_res_partner_job"/>
|
||||
<field eval=""""state"""" name="kind"/>
|
||||
<field eval=""""Jobs at a same partner address."""" name="note"/>
|
||||
<field eval=""""Function"""" name="name"/>
|
||||
<field name="process_id" ref="process_process_basecontactprocess0"/>
|
||||
<field eval="0" name="flow_start"/>
|
||||
</record>
|
||||
|
||||
<record id="process_node_addresses0" model="process.node">
|
||||
<field name="menu_id" ref="base.menu_partner_address_form"/>
|
||||
<field name="model_id" ref="base.model_res_partner_address"/>
|
||||
|
@ -59,22 +50,6 @@
|
|||
Process Transition
|
||||
-->
|
||||
|
||||
<record id="process_transition_contacttofunction0" model="process.transition">
|
||||
<field eval="[(6,0,[])]" name="transition_ids"/>
|
||||
<field eval=""""Contact to function"""" name="name"/>
|
||||
<field eval=""""Defines contacts and functions."""" name="note"/>
|
||||
<field model="process.node" name="target_node_id" ref="process_node_function0"/>
|
||||
<field model="process.node" name="source_node_id" ref="process_node_contacts0"/>
|
||||
</record>
|
||||
|
||||
<record id="process_transition_functiontoaddress0" model="process.transition">
|
||||
<field eval="[(6,0,[])]" name="transition_ids"/>
|
||||
<field eval=""""Function to address"""" name="name"/>
|
||||
<field eval=""""Define functions and address."""" name="note"/>
|
||||
<field model="process.node" name="target_node_id" ref="process_node_addresses0"/>
|
||||
<field model="process.node" name="source_node_id" ref="process_node_function0"/>
|
||||
</record>
|
||||
|
||||
<record id="process_transition_partnertoaddress0" model="process.transition">
|
||||
<field eval="[(6,0,[])]" name="transition_ids"/>
|
||||
<field eval=""""Partner to address"""" name="name"/>
|
||||
|
@ -84,4 +59,4 @@
|
|||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</openerp>
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
|
||||
"access_res_partner_contact","res.partner.contact","model_res_partner_contact","base.group_partner_manager",1,1,1,1
|
||||
"access_res_partner_job","res.partner.job","model_res_partner_job","base.group_partner_manager",1,1,1,1
|
||||
"access_res_partner_contact_all","res.partner.contact all","model_res_partner_contact","base.group_user",1,0,0,0
|
||||
"access_res_partner_job_all","res.partner.job all","model_res_partner_job","base.group_user",1,0,0,0
|
||||
"access_group_sale_salesman","res.partner.contact.sale.salesman","model_res_partner_contact","base.group_sale_salesman",1,1,1,0
|
||||
"access_res_partner_job_salesman","res.partner.job.salesman","model_res_partner_job","base.group_sale_salesman",1,1,1,0
|
||||
|
|
|
|
@ -108,46 +108,46 @@ class crm_lead_report(osv.osv):
|
|||
@param cr: the current row, from the database cursor
|
||||
"""
|
||||
tools.drop_view_if_exists(cr, 'crm_lead_report')
|
||||
cr.execute("""
|
||||
CREATE OR REPLACE VIEW crm_lead_report AS (
|
||||
SELECT
|
||||
id,
|
||||
#cr.execute("""
|
||||
# CREATE OR REPLACE VIEW crm_lead_report AS (
|
||||
# SELECT
|
||||
# id,
|
||||
|
||||
to_char(c.date_deadline, 'YYYY') as deadline_year,
|
||||
to_char(c.date_deadline, 'MM') as deadline_month,
|
||||
to_char(c.date_deadline, 'YYYY-MM-DD') as deadline_day,
|
||||
# to_char(c.date_deadline, 'YYYY') as deadline_year,
|
||||
# to_char(c.date_deadline, 'MM') as deadline_month,
|
||||
# to_char(c.date_deadline, 'YYYY-MM-DD') as deadline_day,
|
||||
|
||||
to_char(c.create_date, 'YYYY') as creation_year,
|
||||
to_char(c.create_date, 'MM') as creation_month,
|
||||
to_char(c.create_date, 'YYYY-MM-DD') as creation_day,
|
||||
# to_char(c.create_date, 'YYYY') as creation_year,
|
||||
# to_char(c.create_date, 'MM') as creation_month,
|
||||
# to_char(c.create_date, 'YYYY-MM-DD') as creation_day,
|
||||
|
||||
to_char(c.date_open, 'YYYY-MM-DD') as opening_date,
|
||||
to_char(c.date_closed, 'YYYY-mm-dd') as date_closed,
|
||||
# to_char(c.date_open, 'YYYY-MM-DD') as opening_date,
|
||||
# to_char(c.date_closed, 'YYYY-mm-dd') as date_closed,
|
||||
|
||||
c.state,
|
||||
c.user_id,
|
||||
c.probability,
|
||||
c.stage_id,
|
||||
c.type,
|
||||
c.company_id,
|
||||
c.priority,
|
||||
c.section_id,
|
||||
c.channel_id,
|
||||
c.type_id,
|
||||
c.categ_id,
|
||||
c.partner_id,
|
||||
c.country_id,
|
||||
c.planned_revenue,
|
||||
c.planned_revenue*(c.probability/100) as probable_revenue,
|
||||
1 as nbr,
|
||||
(SELECT count(id) FROM mail_message WHERE model='crm.lead' AND res_id=c.id AND email_from is not null) AS email,
|
||||
date_trunc('day',c.create_date) as create_date,
|
||||
extract('epoch' from (c.date_closed-c.create_date))/(3600*24) as delay_close,
|
||||
abs(extract('epoch' from (c.date_deadline - c.date_closed))/(3600*24)) as delay_expected,
|
||||
extract('epoch' from (c.date_open-c.create_date))/(3600*24) as delay_open
|
||||
FROM
|
||||
crm_lead c
|
||||
)""")
|
||||
# c.state,
|
||||
# c.user_id,
|
||||
# c.probability,
|
||||
# c.stage_id,
|
||||
# c.type,
|
||||
# c.company_id,
|
||||
# c.priority,
|
||||
# c.section_id,
|
||||
# c.channel_id,
|
||||
# c.type_id,
|
||||
# c.categ_id,
|
||||
# c.partner_id,
|
||||
# c.country_id,
|
||||
# c.planned_revenue,
|
||||
# c.planned_revenue*(c.probability/100) as probable_revenue,
|
||||
# 1 as nbr,
|
||||
# (SELECT count(id) FROM mail_message WHERE model='crm.lead' AND res_id=c.id AND email_from is not null) AS email,
|
||||
# date_trunc('day',c.create_date) as create_date,
|
||||
# extract('epoch' from (c.date_closed-c.create_date))/(3600*24) as delay_close,
|
||||
# abs(extract('epoch' from (c.date_deadline - c.date_closed))/(3600*24)) as delay_expected,
|
||||
# extract('epoch' from (c.date_open-c.create_date))/(3600*24) as delay_open
|
||||
# FROM
|
||||
# crm_lead c
|
||||
# )""")
|
||||
|
||||
crm_lead_report()
|
||||
|
||||
|
|
Loading…
Reference in New Issue