Search code examples
odoo

Removing records on module upgrade on OpenERP / ODOO


I have an application module that have loaded employees for database initialization with custom data in a previous module release:

<?xml version="1.0"?>
<openerp>
    <data>
        ....
        <!-- John Smith -->
        <record id="emp_john_smith" model="hr.employee">
            <field name="name">John Smith</field>
            <field name="company_id" ref="base.main_company"/>
            <field name="department_id" ref="dp_production"/>
            <field name="job_id" ref="jb_production_officer"/>
            <field name="work_email">[email protected]</field>
            <field name="begin_date">2012-01-01</field>
            <field name="gender">male</field>
            <field name="work_location">Madrid</field>
            <field name="lang">es_ES</field>            
        </record>
    ....
    <record id="ctr_john_smith_hr" model="hr.contract">
        <field name="name">John Smith Production Contract</field>
        <field name="employee_id" ref="emp_john_smith"/>
        <field name="job_id" ref="jb_production_officer"/>
        <field name="email">[email protected]</field>
        <field name="date_start">2012-01-01</field>
        <field name="wage">0</field>
        <field name="percent_working_hours">15</field>
        <field name="working_hours" ref="spain_calendar"/>
    </record>
    </data>
</openerp>

But these records must be removed on the next release of that module. Which is the record element i should use on the XML data file of the next release to erase those records?


Solution

  • You can use the delete tag in xml. Dont remove the xml data records you have created in the xml file. In the new version just add the delete tag at the end of the file.

    <delete id="module_name.xml_record_id" model="hr.employee"/>
    

    or you can use the function tag as Yucer said