本文介绍了在openerp中继承数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用以下编码将退出数据从一种形式继承到另一种形式

I have inherited exiting data from one form to another form using following coding

xml: <field name = "res_model">lis.lab</field> 
python: _inherit="lis.lab"

lis.lab是第一种形式.我输入信息,仅在此处保存.test.lab是另一种形式.在这里,我已经完成了使用上面两行单击在树状视图中显示此处(test.lab)的记录的过程.但是它仅以"test.lab"形式存在.而且它没有以第二种形式(test.lab)显示新字段.

lis.lab is first form. I enter information and save only here.test.lab is another form. Here I have finished to display that record here(test.lab) in tree view using above two line click. But It has only exiting field in "test.lab" form. And it's not showing new field in second form(test.lab).

xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- ===================== This is tree layout =============================-->
<record id="lis_tree" model="ir.ui.view">
        <field name="name">Lab Registration</field>
        <field name="model">lis.lab</field>
        <field name="arch" type="xml">
            <tree string="lab">
                <field name = "name"/>
                <field name = "customer_email"/>
                <field name = "customer_name"/>
                <field name = "customer_city"/>
                <field name = "customer_mobile"/>
            </tree>
        </field>
    </record>

<!-- ========================This is Form layout===============================-->
<record id="lis_form" model="ir.ui.view">
        <field name="name">Lab Registration</field>
        <field name="model">lis.lab</field>
        <field name="arch" type="xml">
            <form string="lab" version="7.0">
                <sheet>
                    <group>
                        <field name = "name"/>
                        <field name = "customer_name" on_change="on_change_customer(customer_name)"/>
                        <field name = "customer_city"/>
                        <field name = "customer_email"/>
                        <field name = "customer_mobile"/>    
                    </group>
               </sheet>
            </form>
       </field>
    </record>

<!-- ========================= Action Layout ============================= -->
    <record id="action_lab" model="ir.actions.act_window">
        <field name="name">Lab Registration</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">lis.lab</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="view_id" ref="lis_tree"/>
    </record>

    <!-- ===================== This is tree layout =============================-->
<record id="test_tree" model="ir.ui.view">
        <field name="name">Test Report</field>
        <field name="model">test.lab</field>
        <field name="arch" type="xml">
            <tree string="test">
                <field name = "name"/>
                <field name = "customer_email"/>
                <field name = "customer_name"/>
                <field name = "customer_city"/>
                <field name = "customer_mobile"/>
            </tree>
        </field>
    </record>

<!-- ========================This is Form layout===============================-->
<record id="test_form" model="ir.ui.view">
        <field name="name">Test Report</field>
        <field name="model">test.lab</field>
        <field name="arch" type="xml">
            <form string="test" version="7.0">
                <sheet>
                    <notebook >
                        <page string="Hamthalaogy Report">
                            <field name = "sam" />
                        </page>
                        <page string="Serology Report">
                            <field name = "sam1" />
                        </page>
                    </notebook>
                </sheet>
            </form>
       </field>
    </record>

<!-- ========================= Action Layout ============================= -->
    <record id="action_test" model="ir.actions.act_window">
        <field name="name">Test Report</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">lis.lab</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="view_id" ref="test_tree"/>
    </record>

    <!-- ===========================Menu Settings=========================== -->
    <menuitem name = "LIS" id = "menu_lis_lab" />
        <menuitem name = "Lab Info" id = "menu_sub" parent = "menu_lis_lab"/>
            <menuitem name = "Lab Registration" id = "lab_register" parent = "menu_sub" action = "action_lab" />
            <menuitem name = "Test Report" id = "lab_test" parent = "menu_sub" action = "action_test" />

</data>
</openerp>

python

from osv import osv
from osv import fields

class cus(osv.osv):
 _name = "lis.lab"
 _description = "This table is for keeping lab data of cord blood"
 _columns = {
    'name': fields.char('Lab Id',size=20,required=True),
    'customer_name': fields.many2one('res.partner', 'Customer Name', domain=[('customer', '=', True)]),
    'customer_city': fields.char('City', size=20),
    'customer_email': fields.char('Email', size=20),
    'customer_mobile': fields.char('Mobile', size=20),
    'sam': fields.char('Sample', size=64),
    'sam1': fields.char('Sample1', size=64)
 }
 def on_change_customer(self, cr, uid, ids, customer_name, context=None):
  values = {}
  if customer_name:
   cust = self.pool.get('res.partner').browse(cr, uid, customer_name, context=context)
   values = {
    'customer_city': cust.city,
    'customer_email': cust.email,
    'customer_mobile': cust.mobile
   }
  return {'value' : values}

class test(osv.osv):
 _name = "test.lab"
 _inherit = "lis.lab"
 _description = "Lab Result"
 _columns = {

 }
 def on_change_labid(self, cr, uid, ids, name, context=None):
  values = {}
  if name:
   custinfo = self.pool.get('lis.lab').browse(cr, uid, name, context=context)
   values = {
   }
  return {'value' : values}

推荐答案

使用类继承来实现您的目标.

您正在通过OpenERP原型使用继承概念.其中_name!= _inherit.因此,在超类表上运行的视图或树将永远不会看到子类的新实例.

You are using inheritance by prototyping concept of OpenERP. Where _name != _inherit. New instances of child class will therefore never been seen by views or trees operating on the superclasses table.

要在子类"视图中显示父类的实例,您需要使用类继承,其中_name = _inherit.子级继承父级的数据(字段)和行为(功能).

To display instances of Super Class in Child Class view, You need to use class inheritance where _name = _inherit. where The child inherits data (fields) and behaviour (functions) of his parent.

这篇关于在openerp中继承数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 17:08