1.首先造出一个many2many字段,关联到选项字典表的细单中,并设置筛选条件
如下所示:
rule_m2m = fields.Many2many('sys.column.ddl.dtl', string='客户性质', domain="[('ddlid', '=', 24)]")
2.创建按钮然后绑定方法
创建按钮:
<button name="type_of_custom" string="设置客户性质" type="object" class="oe_highlight"/>
绑定方法:
def type_of_custom(self):
return {
'name': '设置客户性质',
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'view_id': self.env.ref('purchage_manage.view_form_type_of_custom').id,
'target': 'new',
'res_model': 'rx.supply.rebate.rule',
'res_id': self.id,
}
3.新创建个form表单,里面仅仅含有一个字段(就是这个many2many字段)
<!--type_of_custom-->
<record id="view_form_type_of_custom" model="ir.ui.view">
<field name="name">tree.type.of.custom</field>
<field name="model">rx.supply.rebate.rule</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="rule_m2m" widget="many2many_tags" options="{'no_create': 1, 'no_open': 1}"/>
</group>
<footer>
<button name="affirm" string="确定" type="object" class="btn-primary"/>
<button string="取消" class="oe_link" special="cancel"/>
</footer>
</sheet>
</form>
</field>
</record>
4.affirm方法:
def affirm(self):
print(self.rule_m2m)
customertype = []
for record in self.rule_m2m:
print(record.value)
customertype.append(record.value)
self.customertype = customertype
到此就完成了.