1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import fields, osv
24 class base_contact_installer(osv.osv_memory):
25 _name = 'base.contact.installer'
26 _inherit = 'res.config.installer'
29 'name': fields.char('Name', size=64),
30 'migrate': fields.boolean('Migrate', help="If you select this, all addresses will be migrated."),
33 def execute(self, cr, uid, ids, context=None):
35 This function is used to create contact and address from existing partner address
37 obj = self.pool.get("base.contact.installer").browse(cr, uid, uid, context=context)
39 # Enable PL/pgSQL if not enabled yet in the database
40 cr.execute("SELECT 1 FROM pg_language WHERE lanname = 'plpgsql'")
42 cr.execute("CREATE LANGUAGE plpgsql;")
44 cr.execute("""DROP TRIGGER IF EXISTS contactjob on res_partner_contact;
45 CREATE OR REPLACE FUNCTION add_to_job() RETURNS TRIGGER AS $contactjob$
50 IF(TG_OP='INSERT') THEN
51 INSERT INTO res_partner_job(contact_id, address_id, function, state) VALUES(NEW.id, NEW.website::integer,NEW.first_name, 'current');
52 UPDATE res_partner_contact set first_name=Null, website=Null, active=True where id=NEW.id;
56 $contactjob$ LANGUAGE plpgsql;
57 CREATE TRIGGER contactjob AFTER INSERT ON res_partner_contact FOR EACH ROW EXECUTE PROCEDURE add_to_job();""")
59 cr.execute("INSERT into res_partner_contact (name, title, email, first_name, website) (SELECT coalesce(name, 'Noname'), title, email, function , to_char(id, '99999999') from res_partner_address)")
61 cr.execute("DROP TRIGGER IF EXISTS contactjob on res_partner_contact")
63 cr.execute("DROP FUNCTION IF EXISTS add_to_job()")
65 base_contact_installer()
67 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: