odoo學習-2

10132714發表於2024-07-02

1. 新加自定義模組

odoo同級目錄下新建my_addons資料夾
加入自己的模組(注意:views中也要建立一個xml檔案)

2. model程式碼-寫在models下面的py檔案中

from odoo import api, fields, models


class EpidemicRecord(models.Model):
    _name = 'epidemic.record'  # 資料庫表明

    name = fields.Char(string='姓名')
    date = fields.Date(string='感染日期')
    state = fields.Char(string='省')
    city = fields.Char(string='城市')
    county = fields.Char(string='縣')
    street = fields.Char(string='具體地址')
    ill_type = fields.Char(string='感染方式')
    with_or_abroad = fields.Selection([('within', '境內'), ('abroad', '境外')], string='境內/境外')

  

3. views程式碼-解除安裝views下面的xml檔案中

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <record id="epidemic_record_tree_view" model="ir.ui.view">
        <field name="name">疫情記錄</field>
        <field name="model">epidemic.record</field>
        <field name="arch" type="xml">
            <tree>
                <field name="name"/>
                <field name="date"/>
                <field name="state"/>
                <field name="city"/>
                <field name="county"/>
                <field name="street"/>
                <field name="ill_type"/>
                <field name="with_or_abroad"/>
            </tree>
        </field>
    </record>

    <record id="epidemic_record_act_window" model="ir.actions.act_window">
        <field name="name">疫情記錄</field>
        <field name="res_model">epidemic.record</field>
        <field name="view_mode">tree, form</field>
    </record>

    <menuitem name="疫情記錄" id="epidemic_record_menu_root" groups="base.group_user" sequence="10"/>
    <menuitem name="疫情記錄" id="sec_epidemic_record_menu" parent="epidemic_record_menu_root"
              action="epidemic_record_act_window" sequence="10"/>
</odoo>

  

相關文章