Skip to Content
Menu
This question has been flagged
1 Atsakyti
1466 Rodiniai

Hi!

I would like to know how can I create a data for the seeder please ?

- for one2many

- for many2many


Currently I have a data:


category.xml
<record id="category_1" model="product.category">
<
fieldname="name">Category 1field>


product.xml
<record id="product_1" model="product.product">
<
fieldname="name">Product 1field>


I would like to attach a category on product

And on the many2many relation, how can I create a seeder with insert id ?

Thank you so much for your help!

Portretas
Atmesti
Best Answer

Hi,

To create a data file for many2many and one2many, first you need to create data in the one2many or many2many model. Then link that data file to the main model.

<record id="employee_category_2" model="hr.employee.category">
          <field name="name">Sales</field>
</record>


<record id="employee_fp" model="hr.employee">
          <field name="name">Pieter Parker</field>
          <field name="user_id" ref="base.user_root"/>
          <field name="department_id" ref="dep_management"/>
          <field name="job_id" ref="hr.job_ceo"/>
<field name="category_ids" eval="[(6, 0, [ref('employee_category_2')])]"/>
          <field name="work_location">Building 1, Second Floor</field>
<field name="work_phone">+3281813700</field>
<field name="work_email">pieter@openerp.com</field>
<field name="image" type="base64" file="hr/static/img/employee_fp-image.jpg"/>
</record>


You can refer more from this link:

https://github.com/odoo/odoo/blob/9.0/addons/hr/hr_demo.xml" target="_blank" data-saferedirecturl="https://github.com/odoo/odoo/blob/9.0/addons/hr/hr_demo.xml

" rel="ugc">https://www.google.com/url?q=https://github.com/odoo/odoo/blob/9.0/addons/hr/hr_demo.xml&source=gmail&ust=1691503901030000&usg=AOvVaw0qj7PFExwbprYOcbgO6-rE">https://github.com/odoo/odoo/blob/9.0/addons/hr/hr_demo.xml

Hope it helps

Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
1
rugp. 22
2272
0
geg. 17
6862
1
kov. 15
3482
2
kov. 15
3882
0
gruod. 24
470