diff --git a/addons/base_contact/__init__.py b/addons/base_contact/__init__.py index 7cd056c1c20..84054cd59e7 100644 --- a/addons/base_contact/__init__.py +++ b/addons/base_contact/__init__.py @@ -20,5 +20,7 @@ ############################################################################## import base_contact +import base_contact_installer + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/base_contact/__openerp__.py b/addons/base_contact/__openerp__.py index a0fc97aa5a1..8c58d44ff4c 100644 --- a/addons/base_contact/__openerp__.py +++ b/addons/base_contact/__openerp__.py @@ -45,6 +45,7 @@ 'update_xml': [ 'security/ir.model.access.csv', 'base_contact_view.xml', + 'base_contact_installer_view.xml', 'process/base_contact_process.xml' ], 'demo_xml': ['base_contact_demo.xml'], diff --git a/addons/base_contact/base_contact_installer.py b/addons/base_contact/base_contact_installer.py new file mode 100644 index 00000000000..3cb32017111 --- /dev/null +++ b/addons/base_contact/base_contact_installer.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# 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. +# +# 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 +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from lxml import etree +from osv import fields, osv + +class base_contact_installer(osv.osv_memory): + _name = 'base.contact.installer' + _inherit = 'res.config.installer' + + _columns = { + 'name': fields.char('Name', size=64), + 'migrate': fields.boolean('Migrate', help="If you select this, all addresses will be migrated."), + } + + def execute(self, cr, uid, ids, context=None): + """ + This function is used to create contact and address from existing partner address + """ + cr.execute("""DROP TRIGGER IF EXISTS contactjob on res_partner_contact; + DROP LANGUAGE IF EXISTS plpgsql CASCADE; + CREATE LANGUAGE plpgsql ; + CREATE OR REPLACE FUNCTION add_to_job() RETURNS TRIGGER AS $contactjob$ + DECLARE + new_name varchar; + new_phonenum varchar; + BEGIN + IF(TG_OP='INSERT') THEN + INSERT INTO res_partner_job(contact_id, address_id, function, state) VALUES(NEW.id, NEW.website::integer,NEW.first_name, 'current'); + UPDATE res_partner_contact set first_name=Null, website=Null, active=True where id=NEW.id; + END IF; + RETURN NEW; + END; + $contactjob$ LANGUAGE plpgsql; + CREATE TRIGGER contactjob AFTER INSERT ON res_partner_contact FOR EACH ROW EXECUTE PROCEDURE add_to_job();""") + cr.commit() + + 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)") + cr.commit() + + cr.execute("DROP TRIGGER IF EXISTS contactjob on res_partner_contact") + cr.execute("DROP LANGUAGE IF EXISTS plpgsql CASCADE;") + cr.execute("DROP FUNCTION IF EXISTS add_to_job()") + cr.commit() + +base_contact_installer() + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/base_contact/base_contact_installer_view.xml b/addons/base_contact/base_contact_installer_view.xml new file mode 100644 index 00000000000..3d93faa5728 --- /dev/null +++ b/addons/base_contact/base_contact_installer_view.xml @@ -0,0 +1,56 @@ + + + + base.contact.installer.view + base.contact.installer + form + + + +
+ Address's Migration to Contacts +
+ + + Select the Option for Addresses Migration + + + You can migrate Partner's current addresses to the contact. + + + 13 + + + + Migrate + + + + + +
+
+
+ + + Address Migration + ir.actions.act_window + base.contact.installer + + form + form + new + + + + + 3 + + +
+