_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),
'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'),
_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
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"),
'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:
@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,
-
- 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.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
- )""")
+ #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.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,
+
+ # 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()