2009-10-13 05:58:37 +00:00
|
|
|
|
# -*- coding: utf-8 -*-
|
2008-08-24 14:45:43 +00:00
|
|
|
|
##############################################################################
|
2010-03-26 13:27:16 +00:00
|
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2008-08-24 14:45:43 +00:00
|
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
# License, or (at your option) any later version.
|
2008-08-24 14:45:43 +00:00
|
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 11:15:34 +00:00
|
|
|
|
# GNU Affero General Public License for more details.
|
2008-08-24 14:45:43 +00:00
|
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2010-03-26 13:27:16 +00:00
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-08-24 14:45:43 +00:00
|
|
|
|
#
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
|
|
from osv import fields, osv
|
|
|
|
|
|
|
|
|
|
class res_partner_contact(osv.osv):
|
2010-03-26 13:27:16 +00:00
|
|
|
|
""" Partner Contact """
|
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_name = "res.partner.contact"
|
2010-05-19 18:32:32 +00:00
|
|
|
|
_description = "Contact"
|
2008-08-24 14:45:43 +00:00
|
|
|
|
|
|
|
|
|
def _title_get(self,cr, user, context={}):
|
2010-03-26 13:27:16 +00:00
|
|
|
|
"""
|
|
|
|
|
@param self: The object pointer
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param user: the current user,
|
|
|
|
|
@param context: A standard dictionary for contextual values
|
|
|
|
|
"""
|
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
obj = self.pool.get('res.partner.title')
|
|
|
|
|
ids = obj.search(cr, user, [])
|
|
|
|
|
res = obj.read(cr, user, ids, ['shortcut', 'name','domain'], context)
|
|
|
|
|
res = [(r['shortcut'], r['name']) for r in res if r['domain']=='contact']
|
|
|
|
|
return res
|
|
|
|
|
|
2009-12-04 10:45:24 +00:00
|
|
|
|
def _main_job(self, cr, uid, ids, fields, arg, context=None):
|
2010-03-26 13:27:16 +00:00
|
|
|
|
"""
|
|
|
|
|
@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), ...]. """
|
|
|
|
|
|
|
|
|
|
|
2009-12-04 10:45:24 +00:00
|
|
|
|
res = dict.fromkeys(ids, False)
|
|
|
|
|
for contact in self.browse(cr, uid, ids, context):
|
|
|
|
|
if contact.job_ids:
|
|
|
|
|
res[contact.id] = contact.job_ids[0].name_get()[0]
|
|
|
|
|
return res
|
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_columns = {
|
|
|
|
|
'name': fields.char('Last Name', size=30,required=True),
|
|
|
|
|
'first_name': fields.char('First Name', size=30),
|
2010-03-26 13:27:16 +00:00
|
|
|
|
'mobile': fields.char('Mobile',size=30),
|
2008-08-24 14:45:43 +00:00
|
|
|
|
'title': fields.selection(_title_get, 'Title'),
|
2010-03-26 13:27:16 +00:00
|
|
|
|
'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'),
|
|
|
|
|
'country_id': fields.many2one('res.country','Nationality'),
|
|
|
|
|
'birthdate': fields.date('Birth Date'),
|
|
|
|
|
'active': fields.boolean('Active', help="If the active field is set to true,\
|
|
|
|
|
it will allow you to hide the partner contact without removing it."),
|
|
|
|
|
'partner_id': fields.related('job_ids','address_id','partner_id',type='many2one',\
|
|
|
|
|
relation='res.partner', string='Main Employer'),
|
|
|
|
|
'function_id': fields.related('job_ids','function_id',type='many2one', \
|
|
|
|
|
relation='res.partner.function', string='Main Function'),
|
|
|
|
|
'job_id': fields.function(_main_job, method=True, type='many2one',\
|
|
|
|
|
relation='res.partner.job', string='Main Job'),
|
2009-02-20 00:06:54 +00:00
|
|
|
|
'email': fields.char('E-Mail', size=240),
|
2010-03-26 13:27:16 +00:00
|
|
|
|
'comment': fields.text('Notes', translate=True),
|
|
|
|
|
'photo': fields.binary('Image'),
|
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
_defaults = {
|
|
|
|
|
'active' : lambda *a: True,
|
|
|
|
|
}
|
2010-03-26 13:27:16 +00:00
|
|
|
|
|
2009-09-24 10:46:21 +00:00
|
|
|
|
_order = "name,first_name"
|
2010-03-26 13:27:16 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
def name_get(self, cr, user, ids, context={}):
|
2010-03-26 13:27:16 +00:00
|
|
|
|
|
|
|
|
|
""" will return name and first_name.......
|
|
|
|
|
@param self: The object pointer
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param user: the current user’s ID for security checks,
|
|
|
|
|
@param ids: List of create menu’s IDs
|
|
|
|
|
@return: name and first_name
|
|
|
|
|
@param context: A standard dictionary for contextual values
|
|
|
|
|
"""
|
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
if not len(ids):
|
|
|
|
|
return []
|
|
|
|
|
res = []
|
2008-10-06 14:39:28 +00:00
|
|
|
|
for r in self.read(cr, user, ids, ['name','first_name','title']):
|
|
|
|
|
addr = r['title'] and str(r['title'])+" " or ''
|
2008-12-12 00:02:09 +00:00
|
|
|
|
addr += r.get('name', '')
|
2008-08-24 14:45:43 +00:00
|
|
|
|
if r['name'] and r['first_name']:
|
|
|
|
|
addr += ' '
|
2008-12-12 13:01:57 +00:00
|
|
|
|
addr += (r.get('first_name', '') or '')
|
2008-08-24 14:45:43 +00:00
|
|
|
|
res.append((r['id'], addr))
|
|
|
|
|
return res
|
2010-03-26 13:27:16 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
res_partner_contact()
|
|
|
|
|
|
2010-03-26 13:27:16 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
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={}):
|
2010-03-26 13:27:16 +00:00
|
|
|
|
"""
|
|
|
|
|
@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
|
|
|
|
|
"""
|
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
if not len(ids):
|
|
|
|
|
return []
|
|
|
|
|
res = []
|
2010-03-26 13:27:16 +00:00
|
|
|
|
for r in self.read(cr, user, ids, ['zip', 'city', 'partner_id', 'street']):
|
2009-05-18 09:45:44 +00:00
|
|
|
|
if context.get('contact_display', 'contact')=='partner' and r['partner_id']:
|
2008-08-24 14:45:43 +00:00
|
|
|
|
res.append((r['id'], r['partner_id'][1]))
|
|
|
|
|
else:
|
|
|
|
|
addr = str('')
|
2010-03-26 13:27:16 +00:00
|
|
|
|
addr += "%s %s %s" % (r.get('street', '') or '', r.get('zip', '') \
|
|
|
|
|
or '', r.get('city', '') or '')
|
2008-08-24 14:45:43 +00:00
|
|
|
|
res.append((r['id'], addr.strip() or '/'))
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
_name = 'res.partner.address'
|
2010-03-26 13:27:16 +00:00
|
|
|
|
_inherit = 'res.partner.address'
|
2008-10-06 14:39:28 +00:00
|
|
|
|
_description ='Partner Address'
|
2010-03-26 13:27:16 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_columns = {
|
2010-03-26 13:27:16 +00:00
|
|
|
|
'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'),
|
2008-08-24 14:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
res_partner_address()
|
|
|
|
|
|
|
|
|
|
class res_partner_job(osv.osv):
|
|
|
|
|
|
2008-10-06 14:39:28 +00:00
|
|
|
|
def name_get(self, cr, uid, ids, context={}):
|
2010-03-26 13:27:16 +00:00
|
|
|
|
"""
|
|
|
|
|
@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
|
|
|
|
|
"""
|
|
|
|
|
|
2008-10-06 14:39:28 +00:00
|
|
|
|
if not len(ids):
|
|
|
|
|
return []
|
|
|
|
|
res = []
|
|
|
|
|
for r in self.browse(cr, uid, ids):
|
2009-05-08 14:19:37 +00:00
|
|
|
|
funct = r.function_id and (", " + r.function_id.name) or ""
|
2010-03-26 13:27:16 +00:00
|
|
|
|
res.append((r.id, self.pool.get('res.partner.contact').name_get(cr, uid, \
|
|
|
|
|
[r.contact_id.id])[0][1] + funct))
|
2008-08-24 14:45:43 +00:00
|
|
|
|
return res
|
|
|
|
|
|
2010-02-01 07:58:52 +00:00
|
|
|
|
def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False):
|
2010-03-26 13:27:16 +00:00
|
|
|
|
""" search parnter job
|
|
|
|
|
@param self: The object pointer
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param user: the current user
|
|
|
|
|
@param args: list of tuples of form [(‘name_of_the_field’, ‘operator’, value), ...].
|
|
|
|
|
@param offset: The Number of Results to Pass
|
|
|
|
|
@param limit: The Number of Results to Return
|
|
|
|
|
@param context: A standard dictionary for contextual values
|
|
|
|
|
"""
|
|
|
|
|
|
2010-02-01 07:58:52 +00:00
|
|
|
|
job_ids = []
|
2008-09-17 07:12:42 +00:00
|
|
|
|
for arg in args:
|
2010-02-01 07:58:52 +00:00
|
|
|
|
if arg[0] == 'address_id':
|
2008-09-17 07:12:42 +00:00
|
|
|
|
self._order = 'sequence_partner'
|
2010-02-01 07:58:52 +00:00
|
|
|
|
elif arg[0] == 'contact_id':
|
2008-09-17 07:12:42 +00:00
|
|
|
|
self._order = 'sequence_contact'
|
2010-02-05 08:32:08 +00:00
|
|
|
|
|
2010-02-01 07:58:52 +00:00
|
|
|
|
contact_obj = self.pool.get('res.partner.contact')
|
2010-04-16 05:47:19 +00:00
|
|
|
|
if arg[2] and not count:
|
|
|
|
|
search_arg = ['|', ('first_name', 'ilike', arg[2]), ('name', 'ilike', arg[2])]
|
|
|
|
|
contact_ids = contact_obj.search(cr, user, search_arg, offset=offset, limit=limit, order=order, context=context, count=count)
|
2010-05-11 08:34:48 +00:00
|
|
|
|
if not contact_ids:
|
|
|
|
|
continue
|
2010-04-16 05:47:19 +00:00
|
|
|
|
contacts = contact_obj.browse(cr, user, contact_ids, context=context)
|
|
|
|
|
for contact in contacts:
|
|
|
|
|
job_ids.extend([item.id for item in contact.job_ids])
|
2010-02-01 07:58:52 +00:00
|
|
|
|
|
2010-03-26 13:27:16 +00:00
|
|
|
|
res = super(res_partner_job,self).search(cr, user, args, offset=offset,\
|
|
|
|
|
limit=limit, order=order, context=context, count=count)
|
2010-02-01 07:58:52 +00:00
|
|
|
|
if job_ids:
|
|
|
|
|
res = list(set(res + job_ids))
|
|
|
|
|
|
|
|
|
|
return res
|
2008-09-17 07:12:42 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_name = 'res.partner.job'
|
2008-12-26 19:21:44 +00:00
|
|
|
|
_description ='Contact Partner Function'
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_order = 'sequence_contact'
|
2010-03-26 13:27:16 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_columns = {
|
2010-05-19 09:58:12 +00:00
|
|
|
|
'name': fields.related('address_id', 'partner_id', type='many2one',\
|
2010-03-26 13:27:16 +00:00
|
|
|
|
relation='res.partner', string='Partner', help="You may\
|
|
|
|
|
enter Address first,Partner will be linked automatically if any."),
|
2010-05-19 09:58:12 +00:00
|
|
|
|
'address_id': fields.many2one('res.partner.address', 'Address', domain=[('partner_id', '=', name)], \
|
2010-03-26 13:27:16 +00:00
|
|
|
|
help='Address which is linked to the Partner'),
|
|
|
|
|
'contact_id': fields.many2one('res.partner.contact','Contact', required=True, ondelete='cascade'),
|
|
|
|
|
'function_id': fields.many2one('res.partner.function','Partner Function', \
|
|
|
|
|
help="Function of this contact with this partner"),
|
|
|
|
|
'sequence_contact': fields.integer('Contact Seq.',help='Order of\
|
|
|
|
|
importance of this address in the list of addresses of the linked contact'),
|
|
|
|
|
'sequence_partner': fields.integer('Partner Seq.',help='Order of importance\
|
|
|
|
|
of this job title in the list of job title of the linked partner'),
|
2009-09-24 10:46:21 +00:00
|
|
|
|
'email': fields.char('E-Mail', size=240, help="Job E-Mail"),
|
|
|
|
|
'phone': fields.char('Phone', size=64, help="Job Phone no."),
|
|
|
|
|
'fax': fields.char('Fax', size=64, help="Job FAX no."),
|
2009-02-20 00:06:54 +00:00
|
|
|
|
'extension': fields.char('Extension', size=64, help='Internal/External extension phone number'),
|
2009-03-25 06:53:10 +00:00
|
|
|
|
'other': fields.char('Other', size=64, help='Additional phone field'),
|
2010-03-26 13:27:16 +00:00
|
|
|
|
'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': fields.selection([('past', 'Past'),('current', 'Current')], \
|
|
|
|
|
'State', required=True, help="Status of Address"),
|
2008-08-24 14:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_defaults = {
|
|
|
|
|
'sequence_contact' : lambda *a: 0,
|
2010-03-26 13:27:16 +00:00
|
|
|
|
'state': lambda *a: 'current',
|
2008-08-24 14:45:43 +00:00
|
|
|
|
}
|
2010-05-19 09:58:12 +00:00
|
|
|
|
|
|
|
|
|
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}}
|
2010-03-26 13:27:16 +00:00
|
|
|
|
|
2010-05-19 09:58:12 +00:00
|
|
|
|
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)
|
|
|
|
|
partner_id = address.partner_id.id
|
|
|
|
|
return {'value': {'name': partner_id}}
|
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
res_partner_job()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|
|