[ADD] base_contact:

* [ADD] add configuration wizard  to migrate  addresses into contact

bzr revid: hmo@tinyerp.com-20100624064650-pujl9lwoy9caen0i
This commit is contained in:
Mod2 Team (OpenERP) 2010-06-24 12:16:50 +05:30 committed by Harry (OpenERP)
parent 3058bf6bb2
commit b7a1ff4ef9
4 changed files with 125 additions and 0 deletions

View File

@ -20,5 +20,7 @@
##############################################################################
import base_contact
import base_contact_installer
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -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'],

View File

@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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:

View File

@ -0,0 +1,56 @@
<openerp>
<data>
<record id="view_base_contact_installer" model="ir.ui.view">
<field name="name">base.contact.installer.view</field>
<field name="model">base.contact.installer</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.res_config_installer"/>
<field name="arch" type="xml">
<data>
<form position="attributes">
<attribute name="string">Address's Migration to Contacts</attribute>
</form>
<separator string="title" position="attributes">
<attribute name="string">Select the Option for Addresses Migration</attribute>
</separator>
<xpath expr="//label[@string='description']"
position="attributes">
<attribute name="string">You can migrate Partner's current addresses to the contact.</attribute>
</xpath>
<xpath expr='//separator[@string="vsep"]' position='attributes'>
<attribute name='rowspan'>13</attribute>
<attribute name='string'></attribute>
</xpath>
<xpath expr="//button[@string='Install Modules']" position="attributes">
<attribute name="string">Migrate</attribute>
</xpath>
<group colspan="8">
<group colspan="2" col="2">
<label string="Due to changes in Address and Partner's relation, some of the details from address are needed to migrated into contact information." colspan="4"/>
<label string="Otherwise these details will not be visible from address/contact." colspan="4"/>
<label string="Do you want to migrate your Address data in Contact Data?" colspan="4" />
<field name="migrate" string="Yes/No" />
</group>
</group>
</data>
</field>
</record>
<record id="action_base_contact_installer" model="ir.actions.act_window">
<field name="name">Address Migration</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">base.contact.installer</field>
<field name="view_id" ref="view_base_contact_installer"/>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<record id="base_contact_installer_todo" model="ir.actions.todo">
<field name="action_id" ref="action_base_contact_installer"/>
<field name="sequence">3</field>
</record>
</data>
</openerp>