odoo many2one字段按域过滤

时间:2017-09-20 13:00:42

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

我想按域过滤name_id字段。正在尝试:

name_id = fields.Many2one('my.model.line',string ='Product',domain = [('purchase_request_id','=',model_id)])

然后我收到了一个错误:

  File "/opt/odoo/openerp/fields.py", line 343, in __getattr__
    return self._attrs[name]
  File "/opt/odoo/openerp/fields.py", line 343, in __getattr__
    return self._attrs[name]
  File "/opt/odoo/openerp/fields.py", line 343, in __getattr__
    return self._attrs[name]
  File "/opt/odoo/openerp/fields.py", line 343, in __getattr__
    return self._attrs[name]
  File "/opt/odoo/openerp/fields.py", line 343, in __getattr__
    return self._attrs[name]
RuntimeError: maximum recursion depth exceeded

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

更新

我的意思是: domain = [('my_model_id','=',model_id)])

1 个答案:

答案 0 :(得分:0)

您正在应用具有purchase_request_id的域作为字段,但模型&#39; my.model.line&#39;中没有字段名称purchase_request_id。试试这段代码:

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

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

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

希望这能解决您的问题。祝你有愉快的一天。