У меня есть 2 класса, первый из которых содержит функцию с созданным в ней списком.
class the_first_class(models.Model)
_inherit = 'mrp.bom'
def first_function(self):
list1 = []
Второй класс, содержащий поле, в котором требуется указать домен на основе списка, созданного в «first_function» из «the_first_class». Как показано ниже:
class second_class(models.Model)
_inherit = 'mrp.bom.line'
field1 = fields.Many2one('product.product', domain=[('id','in',list1)])
Есть ли способ, которым я могу назвать «список1» таким образом? Или, может быть, указать домен на основе функции? А затем вызовите переменную «list1» внутри функции, например:
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)
просмотры.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>