diff --git a/addons/base_contact/__init__.py b/addons/base_contact/__init__.py index 7fa97e2b7ab..aa3d3b43064 100644 --- a/addons/base_contact/__init__.py +++ b/addons/base_contact/__init__.py @@ -21,5 +21,3 @@ import base_contact -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/addons/base_contact/__openerp__.py b/addons/base_contact/__openerp__.py index 77dabe261f3..14f90106fef 100644 --- a/addons/base_contact/__openerp__.py +++ b/addons/base_contact/__openerp__.py @@ -19,15 +19,14 @@ # ############################################################################## - { 'name': 'Contacts Management', 'version': '1.0', 'category': 'Customer Relationship Management', 'complexity': "expert", 'description': """ -This module allows you to manage your contacts entirely. -======================================================== +This module allows you to manage your contacts +============================================== It lets you define: * contacts unrelated to a partner, diff --git a/addons/base_contact/base_contact.py b/addons/base_contact/base_contact.py index 7808b18bdc3..2e729a78eb5 100644 --- a/addons/base_contact/base_contact.py +++ b/addons/base_contact/base_contact.py @@ -28,11 +28,18 @@ class res_partner_contact(osv.osv): _name = "res.partner.contact" _description = "Contact" + def _name_get_full(self, cr, uid, ids, prop, unknow_none, context=None): + result = {} + for rec in self.browse(cr, uid, ids, context=context): + result[rec.id] = rec.last_name+' '+(rec.first_name or '') + return result + _columns = { - 'name': fields.char('Last Name', size=64, required=True), + 'name': fields.function(_name_get_full, string='Name', size=64, type="char", store=True), + 'last_name': fields.char('Last Name', size=64, required=True), 'first_name': fields.char('First Name', size=64), 'mobile': fields.char('Mobile', size=64), - 'title': fields.many2one('res.partner.title','Title'), + 'title': fields.many2one('res.partner.title','Title', domain=[('domain','=','contact')]), 'website': fields.char('Website', size=120), 'lang_id': fields.many2one('res.lang', 'Language'), 'job_ids': fields.one2many('res.partner.address', 'contact_id', 'Functions and Addresses'), @@ -40,14 +47,13 @@ class res_partner_contact(osv.osv): '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', 'location_id', 'partner_id', type='many2one',\ + 'partner_id': fields.related('job_ids', 'partner_id', type='many2one',\ relation='res.partner', string='Main Employer'), 'function': fields.related('job_ids', 'function', type='char', \ string='Main Function'), 'email': fields.char('E-Mail', size=240), 'comment': fields.text('Notes', translate=True), 'photo': fields.binary('Photo'), - } def _get_photo(self, cr, uid, context=None): @@ -74,24 +80,53 @@ class res_partner_contact(osv.osv): def name_get(self, cr, uid, ids, context=None): return [ - (obj.id, " ".join(filter(None, [obj.first_name, obj.name])),) + (obj.id, obj.name) for obj in self.browse(cr, uid, ids, context=context) ] -res_partner_contact() + 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) -class res_partner(osv.osv): - _inherit = 'res.partner' - _columns = { - 'address': fields.one2many('res.partner.location', 'partner_id', 'Address') - } -res_partner() + exists = table_exists(self._table) + super(res_partner_contact, self)._auto_init(cr, context) + + if not exists: + cr.execute(""" + INSERT INTO + res_partner_contact + (id,name,last_name,title,active) + SELECT + id,COALESCE(name, '/'),COALESCE(name, '/'),title,true + FROM + res_partner_address""") + cr.execute("alter table res_partner_address add contact_id int references res_partner_contact") + cr.execute("update res_partner_address set contact_id=id") + cr.execute("select setval('res_partner_contact_id_seq', (select max(id)+1 from res_partner_contact))") + + +res_partner_contact() class res_partner_location(osv.osv): _name = 'res.partner.location' - _inherit = 'res.partner.address' + _rec_name = 'street' _columns = { + 'street': fields.char('Street', size=128), + 'street2': fields.char('Street2', size=128), + 'zip': fields.char('Zip', change_default=True, size=24), + 'city': fields.char('City', size=128), + 'state_id': fields.many2one("res.country.state", 'Fed. State', domain="[('country_id','=',country_id)]"), + 'country_id': fields.many2one('res.country', 'Country'), + 'partner_id': fields.many2one('res.partner', 'Partner Name', ondelete='set null', select=True, help="Keep empty for a private address, not related to partner."), + 'company_id': fields.many2one('res.company', 'Company',select=1), 'job_ids': fields.one2many('res.partner.address', 'location_id', 'Contacts'), + 'partner_id': fields.related('job_ids', 'partner_id', type='many2one',\ + relation='res.partner', string='Main Partner'), + } + _defaults = { + 'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'res.partner.address', context=c), } def _auto_init(self, cr, context=None): def table_exists(view_name): @@ -103,29 +138,34 @@ class res_partner_location(osv.osv): 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 + 10)) + cr.execute(""" + INSERT INTO + res_partner_location + (id,street,street2,zip,city, + state_id,country_id,company_id) + SELECT + id,street,street2,zip,city, + state_id,country_id,company_id + FROM + res_partner_address""") + cr.execute("alter table res_partner_address add location_id int references res_partner_location") + cr.execute("update res_partner_address set location_id=id") + cr.execute("select setval('res_partner_location_id_seq', (select max(id)+1 from res_partner_address))") def name_get(self, cr, uid, ids, context=None): - return [ - ((obj.id, "%s, %s" % (obj.city, obj.country_id and obj.country_id.name or ''))) - for obj in self.browse(cr, uid, ids, context=context) - ] + result = {} + for obj in self.browse(cr, uid, ids, context=context): + res = [] + if obj.partner_id: res.append(obj.partner_id.name_get()[0][1]) + if obj.city: res.append(obj.city) + if obj.country_id: res.append(obj.country_id.name_get()[0][1]) + result[obj.id] = ', '.join(res) + return result res_partner_location() class res_partner_address(osv.osv): - _name = 'res.partner.address' - _inherits = { 'res.partner.location' : 'location_id' } - - def _get_use_existing_address(self, cr, uid, ids, fieldnames, args, context=None): - return dict(map(lambda x: (x, False), ids)) - - def _set_use_existing_address(self, cr, uid, ids, name, value, arg, context=None): - return True + _inherit = 'res.partner.address' def _default_location_id(self, cr, uid, context=None): context = context or {} @@ -134,86 +174,55 @@ class res_partner_address(osv.osv): ids = self.pool.get('res.partner.location').search(cr, uid, [('partner_id','=',context['default_partner_id'])], context=context) return ids and ids[0] or False - def _default_existing_get(self, cr, uid, context=None): - return bool(self._default_location_id(cr, uid, context)) + def onchange_location_id(self,cr, uid, ids, location_id=False, context={}): + if not location_id: + return {} + location = self.pool.get('res.partner.location').browse(cr, uid, location_id, context=context) + return {'value':{ + 'street': location.street, + 'street2': location.street2, + 'zip': location.zip, + 'city': location.city, + 'country_id': location.country_id and location.country_id.id or False, + 'state_id': location.state_id and location.state_id.id or False, + }} _columns = { - 'location_id' : fields.many2one('res.partner.location', 'Location'), - 'use_existing_address' : fields.function(_get_use_existing_address, - fnct_inv=_set_use_existing_address, - type='boolean', - string='Link to Existing Address'), - + 'location_id' : fields.many2one('res.partner.location', 'Location', required=True), 'contact_id' : fields.many2one('res.partner.contact', 'Contact'), - # come modules are doing SQL reports on those fields (crm) + # fields from location + 'street': fields.related('location_id', 'street', string='Street', type="char", store=True, size=128), + 'street2': fields.related('location_id', 'street2', string='Street2', type="char", store=True, size=128), + 'zip': fields.related('location_id', 'zip', string='Zip', type="char", store=True, change_default=True, size=24), + 'city': fields.related('location_id', 'city', string='City', type="char", store=True, size=128), + 'state_id': fields.related('location_id', 'state_id', relation="res.country.state", string='Fed. State', type="many2one", store=True, domain="[('country_id','=',country_id)]"), 'country_id': fields.related('location_id', 'country_id', type='many2one', string='Country', store=True, relation='res.country'), - 'company_id': fields.related('location_id', 'company_id', type='many2one', string='Company', store=True, relation='res.company'), - # Do not use the one of the location, each job position has it's phone 'phone': fields.char('Phone', size=64), 'fax': fields.char('Fax', size=64), 'email': fields.char('E-Mail', size=240), - 'function': fields.char('Partner Function', size=64, help="Function of this contact with this partner"), - #'partner_id' : fields.related('location_id', 'partner_id', type="many2one", relation='res.partner', string='Partner'), - '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", store=True), + # fields from contact + 'mobile' : fields.related('contact_id', 'mobile', type='char', size=64, string='Mobile'), + 'name' : fields.related('contact_id', 'name', type='char', size=64, string="Contact Name", store=True), + 'title' : fields.related('contact_id', 'title', type='many2one', relation='res.partner.title', string="Title", store=True), } def name_get(self, cr, uid, ids, context=None): - return [ - ((obj.id, "%s, %s" % (obj.contact_id.name_get()[0][1], obj.location_id.name_get()[0][1],))) - for obj in self.browse(cr, uid, ids, context=context) - ] - + result = {} + for rec in self.browse(cr,uid, ids, context=context): + res = [] + for obj in [rec.partner_id, rec.contact_id, rec.location_id]: + if obj: + res.append(obj.name_get()[0][1]) + result[rec.id] = ', '.join(res) + return result _defaults = { - 'use_existing_address': _default_existing_get, 'location_id': _default_location_id } - 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: - contact_proxy = self.pool.get('res.partner.contact') - uid = 1 - cr.execute("SELECT id, name, mobile, country_id, partner_id, phone, email, street, street2, city, company_id, state_id, zip, location_id \ - FROM res_partner_address") - for item in cr.fetchall(): - values = { - 'name' : item[1] or '/', - 'mobile' : item[2], - 'country_id' : item[3], - 'phone' : item[5], - 'email' : item[6], - 'company_id' : item[10], - } - - contact_id = contact_proxy.create(cr, uid, values, context=context) - values = { - 'street' : item[7], - 'street2' : item[8], - 'city' : item[9], - 'country_id' : item[3], - 'company_id' : item[10], - 'state_id' : item[11], - 'zip' : item[12], - } - location_id = self.pool.get('res.partner.location').create(cr, uid, values, context=context) - cr.execute("UPDATE res_partner_address SET location_id = %s, contact_id = %s, partner_id = %s WHERE id = %s", - (location_id, contact_id, item[4], item[0],)) - def default_get(self, cr, uid, fields=[], context=None): context = context or {} if 'default_type' in context: diff --git a/addons/base_contact/base_contact_demo.xml b/addons/base_contact/base_contact_demo.xml index 4ab31a657ec..888ef6b54b7 100644 --- a/addons/base_contact/base_contact_demo.xml +++ b/addons/base_contact/base_contact_demo.xml @@ -3,141 +3,118 @@ - + - - + Benoit + Mortier - - - + Laurent + Jacot - - - + Thomas + Passot - - - - + Etienne + Lacarte - - + Tang - - + Wong - - + Jean-Guy + Lavente - - - + Sylvie + Lelitre - - - + Arthur + Grosbonnet - - - + Karine + Lesbrouffe - - - + Zen - - - + http://fptiny.blogspot.com/ + Fabien + Pinckaers - - - + Marc + Debois - - - + Phuong + Luu - - - + Najlaa + Khayat - - - + Quentin + Paolino - - - + Fabian + W. - - - + Yvan + Van - - - + Henry + Lambotte - - - + Olivier + Laurent - - - + Christophe + Dupont - - - + Stéphane + Andre - - - + Philippe + Antoine - @@ -152,13 +129,13 @@ Salesman - + contact@tecsas.fr CTO - + info@mycompany.com @@ -207,74 +184,74 @@ Salesman - + re@mycompany.com CTO - + st@mycompany.com CTO - + ch@mycompany.com CTO - + ol@mycompany.com CTO - + fl@mycompany.com Salesman - + av@mycompany.com CTO - + fb@mycompany.com CTO - + qd@mycompany.com CTO - + ne@mycompany.com CTO - + ph@mycompany.com CEO - + fp@mycompany.com -1 Salesman - + cd@mycompany.com @@ -284,14 +261,14 @@ PA - + 1 PA 5 - + 2 CEO diff --git a/addons/base_contact/base_contact_view.xml b/addons/base_contact/base_contact_view.xml index 4a1308ae98c..e4a5fb728c8 100644 --- a/addons/base_contact/base_contact_view.xml +++ b/addons/base_contact/base_contact_view.xml @@ -30,7 +30,7 @@
- + @@ -50,22 +50,17 @@ - - - - + + - - - - - - - - - + + + + + + @@ -95,8 +90,8 @@ search - - + @@ -139,119 +134,43 @@ form - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - -
-
+ + + + + +
- - - - - res.partner.form - form - res.partner - - - - - - - - - - - res.partner.form - form - res.partner - - - - - - - - res.partner.form - form - res.partner - - - - - - - - - - - - + + res.partner.location.form + res.partner.location + form + +
+ + + + + + + + +
+ + res.partner.location.tree res.partner.location tree - - - - - - @@ -262,134 +181,15 @@ form - - - - - - - - - - - - - - - - - - {'invisible' : [('use_existing_address', '=', 1)], 'readonly' : [('use_existing_address', '=', 1)]} - - - {'invisible' : [('use_existing_address', '=', 1)], 'readonly' : [('use_existing_address', '=', 1)]} - - - {'invisible' : [('use_existing_address', '=', 1)], 'readonly' : [('use_existing_address', '=', 1)]} - - - {'invisible' : [('use_existing_address', '=', 1)], 'readonly' : [('use_existing_address', '=', 1)]} - - - {'invisible' : [('use_existing_address', '=', 1)], 'readonly' : [('use_existing_address', '=', 1)]} - - - {'invisible' : [('use_existing_address', '=', 1)], 'readonly' : [('use_existing_address', '=', 1)]} - - - {'invisible' : [('use_existing_address', '=', 1)], 'readonly' : [('use_existing_address', '=', 1)]} - - -
- - - res.partner.address.select - res.partner.address - search - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/addons/base_contact/test/base_contact00.yml b/addons/base_contact/test/base_contact00.yml index ba226fd5afd..c2ff49199f7 100644 --- a/addons/base_contact/test/base_contact00.yml +++ b/addons/base_contact/test/base_contact00.yml @@ -9,6 +9,7 @@ !record {model: res.partner.contact, id: res_partner_contact_williams0}: country_id: base.be first_name: Laura + last_name: Henrion job_ids: - email: lwilliams@mydomain.com function: PA @@ -26,9 +27,8 @@ street: 23, street ways type: default zip: '2324324' - job_ids: - - function: CEO - contact_id: res_partner_contact_williams0 + function: CEO + contact_id: res_partner_contact_williams0 name: Lauras Company ref: LC -