Odoo 10:从“发票”模块获取类似发票_line_ids的视图

时间:2018-09-20 11:20:51

标签: python xml module customization odoo

我正在扩展“员工”模块,以列出员工从公司获得的所有设备。以下是我的models.py:

# -*- coding: utf-8 -*-

from odoo import models, fields, api

class device_types(models.Model):
    _name = "device.types"
    name = fields.Char()

class device_names(models.Model):
    _name = "device.names"
    name = fields.Char()
    #devices_names = fields.Many2one('hr.employee')


class devices(models.Model):
    _name = "devices"

    #devices_types = fields.Many2one('device.types')
    devices_id = fields.Many2one('hr.employee')
    devices_types = fields.Char()
    devices_names = fields.Char()



    #employee_id = fields.Many2one('hr.employee')


class employee_devices(models.Model):
     _inherit = 'hr.employee'
     #devices_lines_ids = fields.One2many('devices','devices_id',string='Device Lines',readonly=True, states={'draft': [('readonly', False)]}, copy=True)
     devices_lines_ids = fields.One2many('devices','devices_id',string='Device Lines')
     #devices_names = fields.Many2one('devices')
     #devices_types = fields.Many2one('devices')
     devices_types = fields.One2many('devices','devices_types')
     devices_names = fields.One2many('devices.names')

和我的view.xml:

<odoo>
  <data>
    <!-- explicit list view definition -->

    <record id="invoice_form" model="ir.ui.view">
    <field name="model">hr.employee</field>
    <field name="inherit_id" ref="hr.view_employee_form" />
    <field name="priority" eval="1"/>
    <field name="arch" type="xml"> 
        <xpath expr="//notebook//page[@name='hr_settings']" position="after">
         <page name="Devices" string="Devices" groups="hr.group_hr_user">
                                <group>
                                    <group string="Devices" name="devices_group">
                                        <field name="devices_lines_ids" nolabel="1" widget="one2many_list" mode="tree" >
                                         <tree string="Devices" editable="bottom">
                                           <field name="devices_types" />
                                              <field name="devices_names"/> 
                                         </tree> 
                                        </field>
                                    </group>
                                </group>
        </page>
       </xpath>
    </field>
</record>


  </data>
</odoo>

,我能够实现: enter image description here

但是我想在“设备类型”和“设备名称”列中有一个下拉菜单,能够创建新的类型和名称。正如您在models.py的注释中看到的那样,我尝试了不同的组合。如何在我的视图中找到该下拉菜单?

简而言之,我想要这种类型的视图,我可以在其中编辑树形视图中的每一列,并且某些列具有下拉菜单:enter image description here

1 个答案:

答案 0 :(得分:1)

已修复。我更新的modules.py:

# -*- coding: utf-8 -*-

from odoo import models, fields, api

class device_types(models.Model):
    _name = "device.types"
    name = fields.Char()

class device_names(models.Model):
    _name = "device.names"
    name = fields.Char()


class devices(models.Model):
    _name = "devices"
    employee_name = fields.Many2one('hr.employee')
    devices_names = fields.Many2one('device.names')
    devices_types = fields.Many2one('device.types')



class employee_devices(models.Model):
     _inherit = 'hr.employee'
     devices_lines_ids = fields.One2many('devices','employee_name',string='Device Lines',states={'draft': [('readonly', False)]}, copy=True)

和我的views.xml:

    <odoo>
    <data>
    <!-- explicit list view definition -->

    <record id="invoice_form" model="ir.ui.view">
      <field name="model">hr.employee</field>
      <field name="inherit_id" ref="hr.view_employee_form" />
      <field name="priority" eval="1"/>
      <field name="arch" type="xml">
        <xpath expr="//notebook//page[@name='hr_settings']" position="after">
          <page name="Devices" string="Devices" groups="hr.group_hr_user">
            <group>
                <field name="devices_lines_ids" nolabel="1" widget="one2many_list" mode="tree">
                  <tree string="Devices" editable="bottom">
                    <field name="devices_types" />
                    <field name="devices_names"/>
                  </tree>
                </field>
            </group>
          </page>
        </xpath>
      </field>
    </record>
  </data>
</odoo>