跳至内容
菜单
此问题已终结
1 回复
1464 查看

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!

形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
1
8月 22
2268
0
5月 17
6861
1
3月 15
3481
2
3月 15
3881
0
12月 24
469