zoukankan      html  css  js  c++  java
  • odoo——日历的一对多与多对一

    # 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>

  • 相关阅读:
    codeforces 1438D,思路非常非常巧妙的构造题
    【Azure DevOps系列】开始第一个Azure DevOps应用
    .NET Core SameSite cookie问题
    解决Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
    feign.FeignException$NotFound: status 404 reading OrdersClient#isBuyCourse(String,String)
    feign.FeignException$NotFound: status 404 reading EduClient#getCourseInfoOrder
    谷粒学院查询全部课程不显示问题
    解决java.sql.SQLException: Zero date value prohibited
    使用Visual Studio Code代码编辑器给vue安装插件,结果导致node_modules里面的安装好的依赖丢失
    Redis报错: Caused by: io.lettuce.core.RedisConnectionException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, ...
  • 原文地址:https://www.cnblogs.com/pywjh/p/11265978.html
Copyright © 2011-2022 走看看