2
votes

I need import employees(hr.employee object) from xml and to tie them with users(res.users object) and contacts(res.partner object). Relation with user working is good(screen below after import).

enter image description here

But I have problem with contacts. When system import user she authomatically create new contact which applies to user. How I can to tie this contact with employee if I don't know ID?

enter image description here

I tried add contact record to xml file and set relations. But in this case system creates 2 contacts. And one of them is not related to user.

Here my xml for import from my module.

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data noupdate="1">
        <record id="user_test" model="res.users">
            <field name="name">My Name</field>
            <field name="login">my_name</field>
            <field name="password">1111</field>
        </record>
        <!-- I tried create contact like this...
             but then will be created 2 contacts
             instead 1 + one of them is not related with user -->

        <!--<record id="contact_test" model="res.partner">-->
            <!--<field name="name">My Name</field>-->
            <!--<field name="user_id" ref="user_test"/>-->
        <!--</record>-->
        <record id="employee_test" model="hr.employee">
            <field name="name">My Name</field>
            <field name="work_email">[email protected]</field>
            <field name="user_id" ref="user_test"/>
        </record>
    </data>
</openerp>

So, my question is: How I can to set contact(which was created authomatically from user) to employee?

2
Have you tried creating first the partner in the xml and then the user? just add <field name="partner_id" ref ="contact_test"/>. Be sure that the user is under partner.dccdany
Nothing changed. But in this case was created 1 contact, not 2.Danila Ganchar
And how is the relation between the user created and the contact?. I mean, the user needs to have 1 contact associated, is it a new one?dccdany
I think by user_id. Because I can't remove contact from GUI. I get error : The operation cannot be completed, probably due to the following: - deletion: you may be trying to delete a record while other records still reference it - creation/update: a mandatory field is not correctly set. [Object with link: Users - res.users]Danila Ganchar
It is possible add some values to fields after determination? I mean, here one record: <record id="contact_my_name" model="res.partner"> <field name="name">My Name</field> </record>. It is possible add some values to this record after tag </record>?Danila Ganchar

2 Answers

1
votes

Try this:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data noupdate="1">

        <record id="contact_test" model="res.partner">
            <field name="name">My Name</field>
        </record>

        <record id="user_test" model="res.users">
            <field name="name">My Name</field>
            <field name="login">my_name</field>
            <field name="password">1111</field>
            <field name="partner_id ref="contact_test"/>
        </record>

        <record id="employee_test" model="hr.employee">
            <field name="name">My Name</field>
            <field name="work_email">[email protected]</field>
            <field name="user_id" ref="user_test"/>
            <field name="partner_id" ref="contact_test"/>
        </record>
    </data>
</openerp>
0
votes

Here solution:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data noupdate="1">
        <!-- at first create contact -->
        <record id="contact_test" model="res.partner">
            <field name="name">My Name</field>
        </record>
        <record id="user_test" model="res.users">
            <field name="name">My Name</field>
            <field name="login">my_name</field>
            <field name="password">1111</field>
            <!-- relation between user and contact -->
            <field name="partner_id" ref="contact_test"/>
        </record>
        <record id="employee_test" model="hr.employee">
            <field name="name">My Name</field>
            <field name="work_email">[email protected]</field>
            <field name="user_id" ref="user_test"/>
            <!-- relation employee and contact -->
            <field name="address_home_id" ref="contact_test"/>
        </record>
    </data>
</openerp>

In this case will be created 1 contact, 1 user and 1 employee. Employee will have relation with contact.