当前位置 : 主页 > 手机开发 > ROM >

odoo——日历的一对多与多对一

来源:互联网 收集:自由互联 发布时间:2021-06-10
# model文件 # -*- coding: utf-8 -*- from odoo import api, fields, models class TodoTestYear(models.Model): _name = ‘ todo.year ‘ _description = ‘ To-do Test Year ‘ _order = ‘ start_date ‘ # 年度名称 year_name = fields.Char
# model文件
# -*- coding: utf-8 -*-
from odoo import api, fields, models


class TodoTestYear(models.Model):
    _name = todo.year
    _description = To-do Test Year
    _order = start_date
    # 年度名称
    year_name = fields.Char(string=Name, required=True, translate=True)
    # 年度编码
    year_code = fields.Char(string=Code, required=True)
    # 开始时间
    start_date = fields.Date(string=Start_Date, required=True) # 小于结束时间
    # 结束时间
    end_date = fields.Date(string=End_Date, required=True) # 大于开始时间
    quarter_ids = fields.One2many(todo.quarter, inverse_name=year_id, string=Quarter)
    month_ids = fields.One2many(todo.month,inverse_name=year_id, string=Month)


class TodoTestQuarter(models.Model):
    _name = todo.quarter
    _description = To-do Test Quarter
    # 季度名称
    quarter_name = fields.Char(string=Quarter_Name, required=True)
    # 季度编码
    quarter_code = fields.Char(string=Quarter_Code, required=True)
    # 开始时间
    start_date = fields.Date(string=Start_Date, readonly=True) # 小于结束时间,逐季变大
    # 结束时间
    end_date = fields.Date(string=End_Date, readonly=True) # 大于开始时间, 逐季变大
    year_id = fields.Many2one(comodel_name=todo.year, string=Year)


class TodoTestMonth(models.Model):
    _name = todo.month
    _description = To-do Test Month
    # 月份名称
    month_name = fields.Char(string=Month_Name, required=True)
    # 月份编码
    month_code = fields.Char(string=Month_Code, required=True)
    # 开始时间
    start_date = fields.Date(string=Start_Date, readonly=True) # 小于结束时间,逐月变大
    # 结束时间
    end_date = fields.Date(string=End_Date, readonly=True) # 大于结束时间,逐月变大
    # 所属季度
    quarter_id = fields.Many2one(comodel_name=todo.quarter, readonly=True, string=Quarter) # 取值同1年度内的季度行表中的季度,格式为季度的 Code,注意行结构不提供链接
    year_id = fields.Many2one(comodel_name=todo.year, string=Year)
# xml文件
<?xml version="1.0"?>
<odoo>

      <act_window id="todo_test_action"
                  name="To-do Test"
                  res_model="todo.year"

                  />
   <!---->
      <menuitem id="todo_test_menu_action"
                name="Todos"
                action="todo_test_action"/>

      <!--form视图-->
      <record id="todo_test_view_form" model="ir.ui.view">
         <field name="name">To-do Test year Form</field>
         <field name="model">todo.year</field>
         <field name="arch" type="xml">
            <form string="To-do Test">
               <header>
                  <button name="create_month" type="object" string="Create Month" class="create_month"/>
               </header>
               <sheet>
                  <group name="group_top">
                     <group name="group_left">
                        <field name="year_name"/>
                        <field name="year_code"/>
                     </group>
                     <group name="group_right">
                        <field name="start_date"/>
                        <field name="end_date"/>
                     </group>
                  </group>
                  <notebook>
                     <page string="Quarter">
                        <field name="quarter_ids">
                           <tree>
                              <field name="quarter_name"/>
                              <field name="quarter_code"/>
                              <field name="start_date"/>
                              <field name="end_date"/>
                           </tree>
                        </field>
                     </page>
                     <page string="Month">
                        <field name="month_ids">
                           <tree>
                              <field name="month_name"/>
                              <field name="month_code"/>
                              <field name="start_date"/>
                              <field name="end_date"/>
                              <field name="quarter_id"/>
                           </tree>
                        </field>
                     </page>
                  </notebook>
               </sheet>
            </form>
         </field>
      </record>

      <!--tree视图-->
      <record id="todo_test_view_tree" model="ir.ui.view">
         <field name="name">To-do Test year Tree</field>
         <field name="model">todo.year</field>
         <field name="arch" type="xml">
            <tree>
               <field name="year_name"/>
               <field name="year_code"/>
               <field name="start_date"/>
               <field name="end_date"/>
            </tree>
         </field>
      </record>

      <record id="todo_test_view_search" model="ir.ui.view">
            <field name="name">To-do Test year Search</field>
            <field name="model">todo.year</field>
            <field name="arch" type="xml">
                <search>
                    <field name="year_name" string="Year" filter_domain="[‘|‘,(‘year_name‘,‘ilike‘,self),(‘year_code‘,‘ilike‘,self)]"/>
                </search>
            </field>
        </record>

</odoo>

分享图片

分享图片

上一篇:echarts常用说明
下一篇:Pairs of Numbers
网友评论