我有2个类,第一个包含一个函数,并在其中创建了一个列表。odoo 8其他类的域变量
class the_first_class(models.Model)
_inherit = 'mrp.bom'
def first_function(self):
list1 = []
的第二类,含有一个字段,一个想设在的“the_first_class”“first_function”创建的列表上指定域。如下:
class second_class(models.Model)
_inherit = 'mrp.bom.line'
field1 = fields.Many2one('product.product', domain=[('id','in',list1)])
有没有办法可以像这样调用“list1”?或者可能指定基于功能的域?然后调用的功能等内部变量 “列表1”:
self.env['mrp.bom'].list1
的完整代码:
class bom_excl_list(models.Model):
_inherit = 'mrp.bom'
excl_list = fields.Many2many(comodel_name='product.template')
def methodA(self):
self.test = [17,18]
@api.onchange('bom_line_ids', 'excl_list')
def get_excl_list(self):
print self.excl_list
list1 = []
for i in self.excl_list:
list1.append(i.id)
list2 = []
for j in self.bom_line_ids.product_id:
list2.append(j.id)
class bom_filtered_products(models.Model):
_inherit = 'mrp.bom.line'
def methodB(self):
A = bom_excl_list()
A.methodA()
print "List", A.test
return [('id','=',A.test)]
filtered_products = fields.Many2one('product.product', domain=methodB)
views.xml:
<record model="ir.ui.view" id="view_bom_form">
<field name="name">mrp.bom.form</field>
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_form_view"/>
<field name="arch" type="xml">
<xpath expr="//page[@string='Components']/field[@name='bom_line_ids']/tree/field[@name='product_id']" position="after">
<field name="filtered_products"/>
</xpath>
<xpath expr="//page[@string='Properties']/group" position="after">
<group>
<!-- <field name="excl_list" widget="many2many_checkboxes"/> -->
<field name="excl_list"/>
</group>
</xpath>
</field>
</record>
嗨,当我执行此代码我收到以下错误: 错误信息:“NoneType”对象有没有属性“了methodA””解析/root/git/odoo/modules/project1/views.xml:634,在 附近 .... –
Jesse
把你的完整代码放在什么地方你用xml文件实现... –
我的代码与上面列出的代码相同,只有第一个类(Class_A)从'mrp.bom'和第二个类(Class_B)从'mrp'中进行了检测。 bom.line' 我使用views.xml文件来显示我在第一个类中声明的其他字段。但是这个工作之前,我添加的唯一的东西是新方法(methodA)和列表 – Jesse