Odoo 8(Openerp):从列表视图使用向导设置值 [英] Odoo 8 (Openerp): Setting values using Wizard from list view

查看:79
本文介绍了Odoo 8(Openerp):从列表视图使用向导设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在列表视图中使用Odoo向导遇到了一些问题,该问题将从所选(选中)列表项中获取一个值来更新另一个记录.例如,我在res_partner中添加了一个名为related_pa​​rtner_id的列.基本上,它用于对主客户(合作伙伴)进行分类.添加新客户时,我设置了一个下拉菜单,可以分配主帐户.数据库将res_partner中的related_pa​​rtner_id更新为子帐户的ID.

I'm having some issues with an Odoo Wizard in a list view that would take a value from the selected (checked) list items to update another record. For instance, I added a column to res_partner called related_partner_id. Basically, it's used to classify master accounts (partners). When adding a new customer, I have setup a dropdown that I could assign the master account. The database updates the related_partner_id to the child account's id from res_partner.

这是我正在使用的视图.

Here is the view I'm using.

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <!--Wizard view to assign new master account-->
        <record model="ir.ui.view" id="view_master_wizard_form">
            <field name="name">master.wizard.form</field>
            <field name="model">master.wizard</field>
            <field name="arch" type="xml">
                <form string="Assign New Parent">
                    <separator colspan="4" string="Update Parent"/>
                    <newline/>
                    <field name="related_partner_id"/>
                    <field name="parent_id" invisible="1"/>
                    <group col="4" colspan="4">
                        <button icon="gtk-cancel" special="cancel" string="Cancel"/>
                        <button icon="gtk-ok" name="change_master" string="Update" type="object"/>
                    </group>
                </form>
        </field>
    </record>
    <!--Add option to More dropdown in customer list viewt-->
    <act_window id="launch_res_partner" name="Assign New Master"
                src_model="res.partner"
                res_model="master.wizard"
                view_mode="form"
                view_type="form"
                target="new"
                key2="client_action_multi"/>
    <!--Action to change selected customers to the new master account-->
    <record id="action_change_master" model="ir.actions.act_window">
        <field name="name">Assign New Master Account</field>
        <field name="type">ir.actions.act_window</field>
        <field name="src_model">res.partner</field>
        <field name="res_model">master.wizard</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="target">new</field>
    </record>
</data>

我遵循/基于Odoo向导指南此处.我可以看到它在数据库中的master_wizard表中写入了条目(尽管无论检查多少,都只有一个),但是它不会更新res_partner表.

I followed/based it off the Odoo Wizard guide here. I can see it write entries the master_wizard table in the database (though only one no matter how many I check), but it doesn't update the res_partner table.

推荐答案

此处是可与上述XML一起使用的模型类.只需循环遍历id,并将其值从self值设置为向导,再将其设置为res.partner表.这就是所有新的API.它可能需要稍微修饰一下,但目前还可以.我还必须将parent_id设置为需要更改的值.

Here is the model class that works with the above XML. Just need to loop through the ids and set the value from the self value to the wizard to the res.partner table. This is all the new API. It may need to be touched up a bit, but works ok for now. I had to set the parent_id as that needed to change as well.

from openerp import models, fields, api


class master_wizard(models.TransientModel):
    _name = 'master.wizard'

    related_partner_id = fields.Many2one('res.partner', 'Master Account')
    parent_id = fields.Many2one('res.partner')
    related_partner_ids = fields.One2many('res.partner', 'related_partner_id')

    @api.multi
    def change_master(self):
        related_partner_ids = self.env['res.partner'].browse(self._context.get('active_ids'))
        for partner in related_partner_ids:
            partner.related_partner_id = self.related_partner_id
            partner.parent_id = self.related_partner_id
        return {}

这篇关于Odoo 8(Openerp):从列表视图使用向导设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆