Odoo过滤many2one值取决于活动模型/关系

时间:2017-09-20 09:56:28

标签: python-2.7 openerp odoo-9 odoo-10

我在many2one视图中有name_id字段my_model.xml

我想过滤并有可能只从name_id字段中选择与活动表单视图模型有关系的值。

示例:

我有'my.model'班级记录:

id = 1
title = 'Aloha'

id = 2
title = 'Bye'

'my.model.line'班级记录:

id = 1
name = 'first'
my_model_id = 1

id = 2
name = 'second'
my_model_id = 1

id = 3
name = 'item'
my_model_id = 2

因此,当我打开表单视图,并点击来自name_id many2one field I want to have selection only from values: 'first', 'second' if active 'my.model' id = 1. If 'my.model' id = 2 name_id many2one字段选择的添加项时,只需从'项'值。

my_model.xml

 <record model="ir.ui.view" id="view_my_model_form">
     <field name="name">my.model.form</field>
     <field name="model">my.model</field>
     <field name="arch" type="xml">
        <form string="My Model">
          <header>
               <field name="my_model_line">
                     <tree>
                         field name="name"/>
                      </tree>
               </field>
      <notebook>
           <page>
              <field name="supply_conditions_status">
                  <tree string="My model Lines">
                        <field name="name_id"/>
                  </tree>

型号:

class SupplyConditions(models.Model):
    _name = 'supply.conditions'
    name_id = fields.Many2one('my.model.line', string='Product')
    model_id = fields.Many2one('my.model')

class MyModelLine(models.Model):
    _name = 'my.model.line'
    name = fields.Char('Name')
    my_model_id = fields.Many2one('my.model')

class MyModel(models.Model):
    _name = 'my.model'
    title = fields.Char('Title')
    my_model_line = fields.One2many('my.model.line', 'my_model_id')
    supply_conditions_status = fields.One2many('supply.conditions', 'model_id')

我不知道该怎么做。无法在xml视图上使用域名,因为无法访问有效的“my.model”#39; ID。试过name_id使用_default_value但没什么..可能与关系但也不知道如何。需要任何提示..

0 个答案:

没有答案