odoo从选项字典列表中批量选取数据并存储到某一个字段中

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

到此就完成了.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值