demo data here means that records which will insert automatically will we install the module , and in order to do that we have to go to our module then add new folder by name"data" _ as standard _ then inside data add new xml file in which we will add our demo data record by record , so let me give an example
let us say we have object with name student.py which is contain data about the student "name , age , phone , email"
from openerp import models, fields, api, _
class Student(models.Model):
_name = 'student'
"""
contain all student data
"""
name = fields.Char('Name', required=True)
age = fields.Integer('Age', required=True)
phone = fields.Integer('Phone', required=True)
email = fields.Char('Email', required=True)
then we will create the demo data file by name student_demo.xml as
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- Student Demo Data -->
<record id="student_1" model="student.py">
<field name="name">A</field>
<field name="age">15</field>
<field name="phone">123456</field>
<field name="email">A@mail.com</field>
</record>
<odoo>
<data noupdate="1">
<!-- Student Demo Data -->
<record id="student_1" model="student.py">
<field name="name">A</field>
<field name="age">15</field>
<field name="phone">123456</field>
<field name="email">A@mail.com</field>
</record>
<record id="student_1" model="student.py">
<field name="name">B</field>
<field name="age">15</field>
<field name="phone">123457</field>
<field name="email">B@mail.com</field>
</record>
<field name="name">B</field>
<field name="age">15</field>
<field name="phone">123457</field>
<field name="email">B@mail.com</field>
</record>
<record id="student_1" model="student.py">
<field name="name">C</field>
<field name="age">15</field>
<field name="phone">123458</field>
<field name="email">C@mail.com</field>
</record>
<field name="name">C</field>
<field name="age">15</field>
<field name="phone">123458</field>
<field name="email">C@mail.com</field>
</record>
</data>
</odoo>
</odoo>
now we create the student "A,B,C" and the will be insert automatically when we install our module
No comments:
Post a Comment