Inheriting data in openerp

2019-08-18 23:42发布

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 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}

1条回答
迷人小祖宗
2楼-- · 2019-08-18 23:56

Use Class inheritance to achieve your goal.

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.

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.

查看更多
登录 后发表回答