【问题标题】:Odoo how to filter many2one field values in one2many fieldOdoo如何过滤one2many字段中的many2one字段值
【发布时间】:2017-09-19 07:49:46
【问题描述】:

我有 many2one 字段 name_id。通常,当我在此字段下面的 my_model.xml 代码中使用它时,我可以从 my.model.line 中写入的所有值中进行选择。 在这种情况下,我想过滤值并仅查看当前 my.model 中写入的这些值的列表。

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')

为了更清楚地理解 - 示例:

我有 my.model(字段名称 = 'first')和 my.model(字段名称 = 'second')的表单视图。

在 my.model (name = 'first') 在 my_model_line 名称字段中添加数据:'item1'、'item2'

在 my.model (name = 'second') 在 my_model_line 名称字段中添加数据:'1item', '2item'

现在:

在 my.model (name = 'first') supply_conditions_status name_id 字段我看到选择:'1item','2item,item1','item2'

需要:

在 my.model (name = 'first') supply_conditions_status name_id 仅从“item1”、“item2”中选择的可能性

我怎样才能做到这一点?

【问题讨论】:

  • 我正在考虑 my.model.line 模型上的 name_get 方法。问题是我无法获取当前视图 my.model 类 ID。

标签: python-2.7 openerp odoo-9 many-to-one odoo-view


【解决方案1】:

您只需将域赋予您的 many2one 字段即可实现此目的。 试试这个:

name_id = fields.Many2one('my.model.line', string='Product', domain=lambda self: [('my_model_id', '=', self.model_id)])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-15
    • 1970-01-01
    相关资源
    最近更新 更多