Reputation: 769
I have 2 classes, the first one containing a function with a list created in it.
class the_first_class(models.Model)
_inherit = 'mrp.bom'
def first_function(self):
list1 = []
A second class, containing a field where a want to specify a domain based on the list created in "first_function" of "the_first_class". Like following:
class second_class(models.Model)
_inherit = 'mrp.bom.line'
field1 = fields.Many2one('product.product', domain=[('id','in',list1)])
Is there a way I can call the "list1" like this? Or maybe specify the domain based on a function? And then call the variable "list1" inside the function like:
self.env['mrp.bom'].list1
The full code:
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>
Upvotes: 0
Views: 1339
Reputation: 1551
Your full code is look like this after some changes...
class bom_excl_list(models.Model):
_inherit = 'mrp.bom'
excl_list = fields.Many2many(comodel_name='product.template')
def methodA(self):
print "***methodA is Calling***"
test = [17,18]
return test
@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):
bom = self.env['mrp.bom']
print "You get your list here------------>>>>>", bom.methodA()
#A = bom_excl_list()
#A.methodA()
#print "List", A.test
#return [('id','=',A.test)]
return [('id','=',bom.methodA())]
filtered_products = fields.Many2one('product.product', domain=methodB)
Upvotes: 0
Reputation: 2324
As per python approach you can do it by following sample code
class Class_A():
def methodA(self):
self.myList = []
class Class_B():
def methodB(self):
A = Class_A()
A.methodA()
print "Wow! You got your list here ->", A.myList
You can also declare a list in init() method if you don't want to call method of Class_A. As per my knowledge it also works for Odoo8.
Upvotes: 1