我尝试根据另一个具有 char 类型的“itemsnames”列中已经存在的名称过滤具有 many2one 类型的“item”列,我无法在 xml 文件中写入域,这是我的 xml 文件:
<record id="sale_order_line_form_inherited" model="ir.ui.view">
<field name="name">sale_order.line.form.inherited</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//tree//field[@name='name']" position="after">
<field name="categorie"/>
<!--<field name="item" domain="[('item.name','=', 'name.name')]"/>-->
<!--<field name="item" domain="[('item.name','in',items)]"/>-->
<field name="item" domain="[('item.name','in',itemsnames)]"/>
<field name="itemsids"/>
<field name="itemsnames"/>
</xpath>
</field>
</record>
这是python文件:
class class2(models.Model):
_name = 'module.item'
name = fields.Char(string='item')
class class3(models.Model):
_name = 'module.categorieitem'
name = fields.Many2one('module.categorie', string='Categorie')
item = fields.Many2one('module.item', string='Item')
class class4(models.Model):
_inherit = 'sale.order.line'
categorie = fields.Many2one('module.categorie')
# list1=[1,2]
# item = fields.Many2one('module.item', domain=[('id', '=', list1)])
item = fields.Many2one('module.item')
itemsids = fields.Char()
itemsnames = fields.Char()
@api.onchange('categorie')
def _onchange_categorie(self):
print('»»» call onchange_categorie')
res = {}
items_ids = []
items_names = []
records = self.env['module.categorieitem'].search([('name','=',self.categorie .id)])
for record in records:
print(record.item.name)
items_ids.append(record.item.id)
items_names.append(record.item.name)
self.itemsids = items_ids
self.itemsnames = items_names
print('itemsnames: ',self.itemsnames)
res['domain'] = {'item':[('id','in',items_ids)]}
return res
这是查看的屏幕截图