【问题标题】:Pre-select parent item in many2one popup在 many2one 弹出窗口中预选父项
【发布时间】:2015-05-04 10:32:36
【问题描述】:

让我们从一个基本的 One2many 关系开始,一个类 Parent 和一个类 Child

型号:

class Parent(models.Model):
    _name = 'module.parent'
    child_ids = fields.One2many('module.child', 'parent_id')

class Child(models.Model):
    _name = 'module.child'
    parent_id = fields.Many2one('module.parent')

观看次数:

    <record model="ir.ui.view" id="parent_form_view">
        <field name="name">parent.form</field>
        <field name="model">module.parent</field>
        <field name="arch" type="xml">
            <form string="Parent Form">
                <sheet>
                   <field name="child_ids" />
                </sheet>
            </form>
        </field>
    </record>

    <record model="ir.ui.view" id="child_form_view">
        <field name="name">child.form</field>
        <field name="model">module.child</field>
        <field name="arch" type="xml">
            <form string="Child Form">
                <sheet>
                   <field name="parent_id" />
                </sheet>
            </form>
        </field>
    </record>

当我打开一个 Parent 表单并尝试从 one2many 弹出窗口创建一个新的 Child 时,parent_id 字段未选择当前打开的 从窗口视图! 我必须在parent_id 选择字段中检索它才能重新选择它。

有没有办法进行这种自动选择?

【问题讨论】:

    标签: python openerp odoo many-to-one openerp-8


    【解决方案1】:

    尝试关注,

    class Parent(models.Model):
        _name = 'module.parent'
        child_ids = fields.One2many('module.child', 'parent_id')
    
    class Child(models.Model):
        _name = 'module.child'
        parent_id = fields.Many2one('module.parent')
    

    您在父类和子类中定义了相同的模型名称。

    【讨论】:

    • 这只是一个打字错误,在原帖中编辑。
    猜你喜欢
    • 2012-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-18
    • 2013-04-24
    • 1970-01-01
    相关资源
    最近更新 更多