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
|
2011-11-28 17:02:10 +00:00
|
|
|
import addons
|
2008-08-24 14:45:43 +00:00
|
|
|
|
|
|
|
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"
|
2010-09-29 09:52:55 +00:00
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
_columns = {
|
2010-08-05 10:15:50 +00:00
|
|
|
'name': fields.char('Last Name', size=64, required=True),
|
|
|
|
'first_name': fields.char('First Name', size=64),
|
|
|
|
'mobile': fields.char('Mobile', size=64),
|
2010-07-05 13:18:51 +00:00
|
|
|
'title': fields.many2one('res.partner.title','Title'),
|
2010-06-16 11:51:39 +00:00
|
|
|
'website': fields.char('Website', size=120),
|
|
|
|
'lang_id': fields.many2one('res.lang', 'Language'),
|
2011-12-08 18:43:28 +00:00
|
|
|
'job_ids': fields.one2many('res.partner.address', 'contact_id', 'Functions and Addresses'),
|
2010-03-26 13:27:16 +00:00
|
|
|
'country_id': fields.many2one('res.country','Nationality'),
|
|
|
|
'birthdate': fields.date('Birth Date'),
|
2010-11-15 13:15:55 +00:00
|
|
|
'active': fields.boolean('Active', help="If the active field is set to False,\
|
2010-03-26 13:27:16 +00:00
|
|
|
it will allow you to hide the partner contact without removing it."),
|
2011-12-08 18:43:28 +00:00
|
|
|
'partner_id': fields.related('job_ids', 'location_id', 'partner_id', type='many2one',\
|
2010-03-26 13:27:16 +00:00
|
|
|
relation='res.partner', string='Main Employer'),
|
2010-05-24 06:11:15 +00:00
|
|
|
'function': fields.related('job_ids', 'function', type='char', \
|
|
|
|
string='Main Function'),
|
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),
|
2011-11-28 17:02:10 +00:00
|
|
|
'photo': fields.binary('Photo'),
|
2010-03-26 13:27:16 +00:00
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
}
|
2011-11-28 17:02:10 +00:00
|
|
|
|
|
|
|
def _get_photo(self, cr, uid, context=None):
|
|
|
|
photo_path = addons.get_module_resource('base_contact', 'images', 'photo.png')
|
|
|
|
return open(photo_path, 'rb').read().encode('base64')
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
_defaults = {
|
2011-11-28 17:02:10 +00:00
|
|
|
'photo' : _get_photo,
|
2008-08-24 14:45:43 +00:00
|
|
|
'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
|
|
|
|
2010-09-29 14:17:24 +00:00
|
|
|
def name_search(self, cr, uid, name='', args=None, operator='ilike', context=None, limit=None):
|
|
|
|
if not args:
|
|
|
|
args = []
|
|
|
|
if context is None:
|
|
|
|
context = {}
|
|
|
|
if name:
|
|
|
|
ids = self.search(cr, uid, ['|',('name', operator, name),('first_name', operator, name)] + args, limit=limit, context=context)
|
|
|
|
else:
|
|
|
|
ids = self.search(cr, uid, args, limit=limit, context=context)
|
|
|
|
return self.name_get(cr, uid, ids, context=context)
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
res_partner_contact()
|
|
|
|
|
2011-12-08 18:43:28 +00:00
|
|
|
class res_partner(osv.osv):
|
|
|
|
_inherit = 'res.partner'
|
2010-03-26 13:27:16 +00:00
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
_columns = {
|
2011-12-08 18:43:28 +00:00
|
|
|
'address': fields.one2many('res.partner.location', 'partner_id', 'Address')
|
2008-08-24 14:45:43 +00:00
|
|
|
}
|
2011-12-08 18:43:28 +00:00
|
|
|
|
|
|
|
res_partner()
|
2008-08-24 14:45:43 +00:00
|
|
|
|
2011-11-25 10:33:20 +00:00
|
|
|
class res_partner_location(osv.osv):
|
|
|
|
_name = 'res.partner.location'
|
|
|
|
_inherit = 'res.partner.address'
|
2011-12-08 18:43:28 +00:00
|
|
|
_columns = {
|
|
|
|
'job_ids': fields.one2many('res.partner.address', 'location_id', 'Contacts'),
|
|
|
|
}
|
2011-12-09 16:55:31 +00:00
|
|
|
|
|
|
|
def _auto_init(self, cr, context=None):
|
|
|
|
def table_exists(view_name):
|
|
|
|
cr.execute('SELECT count(relname) FROM pg_class WHERE relname = %s', (view_name,))
|
|
|
|
value = cr.fetchone()[0]
|
|
|
|
return bool(value == 1)
|
|
|
|
|
|
|
|
exists = table_exists(self._table)
|
|
|
|
super(res_partner_location, self)._auto_init(cr, context)
|
|
|
|
|
|
|
|
if not exists:
|
|
|
|
sequence_name = self.pool.get('res.partner.address')._sequence
|
|
|
|
cr.execute("SELECT last_value FROM " + sequence_name)
|
|
|
|
last_sequence = cr.fetchone()[0]
|
|
|
|
|
|
|
|
cr.execute("INSERT INTO res_partner_location SELECT * FROM res_partner_address")
|
|
|
|
cr.execute("ALTER SEQUENCE " + self._sequence + " RESTART WITH " + str(last_sequence))
|
|
|
|
|
|
|
|
|
2011-11-25 10:33:20 +00:00
|
|
|
res_partner_location()
|
|
|
|
|
|
|
|
class res_partner_address(osv.osv):
|
|
|
|
_name = 'res.partner.address'
|
2011-12-08 18:43:28 +00:00
|
|
|
_inherits = { 'res.partner.location' : 'location_id' }
|
2011-11-25 10:33:20 +00:00
|
|
|
|
|
|
|
_columns = {
|
2011-12-08 18:43:28 +00:00
|
|
|
'location_id' : fields.many2one('res.partner.location', 'Location'),
|
2011-11-25 10:33:20 +00:00
|
|
|
'contact_id' : fields.many2one('res.partner.contact', 'Contact'),
|
2011-12-08 18:43:28 +00:00
|
|
|
|
2011-11-28 17:02:10 +00:00
|
|
|
'contact_firstname' : fields.related('contact_id', 'first_name', type='char', size=64, string='FirstName'),
|
2011-12-08 18:43:28 +00:00
|
|
|
'name' : fields.related('contact_id', 'name', type='char', size='64', string="LastName"),
|
2011-11-25 10:33:20 +00:00
|
|
|
'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': fields.selection([('past', 'Past'),('current', 'Current')], \
|
|
|
|
'State', required=True, help="Status of Address"),
|
|
|
|
}
|
|
|
|
|
|
|
|
_description ='Contact Partner Function'
|
|
|
|
|
|
|
|
_defaults = {
|
|
|
|
'state': 'current',
|
|
|
|
}
|
|
|
|
|
2011-12-09 16:55:31 +00:00
|
|
|
def _auto_init(self, cr, context=None):
|
|
|
|
def column_exists(column):
|
|
|
|
cr.execute("select count(attname) from pg_attribute where attrelid = \
|
|
|
|
(select oid from pg_class where relname = %s) \
|
|
|
|
and attname = %s", (self._table, column,))
|
|
|
|
value = cr.fetchone()[0]
|
|
|
|
return bool(value == 1)
|
|
|
|
|
|
|
|
exists = column_exists('location_id')
|
|
|
|
super(res_partner_address, self)._auto_init(cr, context)
|
|
|
|
|
|
|
|
if not exists:
|
|
|
|
cr.execute("UPDATE res_partner_address SET location_id = id")
|
2010-09-29 09:52:55 +00:00
|
|
|
|
2011-11-25 10:33:20 +00:00
|
|
|
res_partner_address()
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|