如何将字段的默认值从视图发送到其他视图

时间:2014-08-21 14:52:15

标签: openerp-7

我需要在openerp7中创建one2one关系。我读了很多关于这个想法的文章,我可以输入以下代码

问题是:openerp7没有从父视图(计算)向子(容器)发送值

这是我的代码

testproject.py

from osv import fields,osv

class container(osv.osv):
    _name='container'
    _columns={
        'calculation_id': fields.many2one('calculation','Calculation'),
        'name': fields.char('Name', size=32),
        }
container()

class calculation(osv.osv):
    _name='calculation'
    _columns={
        'container_id': fields.many2one('container','Container'),
        'namefull': fields.char('Name Full', size=32),
        }
calculation()

xml code

<?xml version="1.0"?>
<openerp>
<data>

    <record model="ir.ui.view" id="view_container_form">
        <field name="name">container.form</field>
        <field name="model">container</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Container">
                <field name="name" select="1"/>
                <field name="calculation_id" context="{'default_container_id': active_id}"  />
            </form>
        </field>
    </record>

    <record model="ir.actions.act_window" id="action_container">
        <field name="name">Container</field>
        <field name="res_model">container</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
    </record>

    <menuitem name="Container/Container" id="menu_container"/>-->

    <menuitem name="Container" id="menu_container_item" parent="menu_container" action="action_container"/>

    <record model="ir.ui.view" id="view_calculation_form">
        <field name="name">calculation.form</field>
        <field name="model">calculation</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Calculation">
                <field name="namefull" />
                <field name="container_id" />
            </form>
        </field>
    </record>

    <record model="ir.actions.act_window" id="action_calculation">
        <field name="name">Calculation</field>
        <field name="res_model">calculation</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
    </record>

    <menuitem name="Calculation" id="menu_calculation_item" parent="menu_container" action="action_calculation"/>

</data>
</openerp>

1 个答案:

答案 0 :(得分:0)

你是对的,OpenERP不会为你移动数据 - 你需要修改你的Python代码才能做到。

哦,你应该用你的model命名你的牌桌 - 我会使用假名牌my_model

class calculation(osv.Model):
    _name = 'my_model.calculation'
    _columns = {
        'container_id' fields.many2one('my_model.container', 'Container'),
        'namefull': fields.char('Name Full', size=32),
        }

    def create(self, cr, uid, values, context=None):
        new_id = super(calculation, self).create(cr, uid, values, context=context)
        self.pool.get('my_model.container').create(cr, uid, {'calculation_id':new_id, 'name':values['namefull'])
        return new_id

如果write()更新,则会向namefull添加一些similer。